The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cFunctionOneValue.h
Go to the documentation of this file.
1 /**
2  * @class cFunctionOneValue
3  * file name: cFunctionOneValue.h
4  * @author Betti Oesterholz
5  * @date 08.05.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents the basisclass for all one value underfunctions.
11  * Copyright (C) @c LGPL3 2010 Betti Oesterholz
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License (LGPL) as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  *
26  *
27  * This class represents the basisclass for all one value underfunction.
28  * From this class all classes are derived, which represent function,
29  * which work on one input values.
30  *
31  */
32 /*
33 History:
34 08.05.2010 Oesterholz created
35 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
36 */
37 
38 #ifndef ___C_FUNCTION_ONE_VALUE_H__
39 #define ___C_FUNCTION_ONE_VALUE_H__
40 
41 
42 #include "version.h"
43 #include "fibDatatyps.h"
44 #include "cReadBits.h"
45 
46 #include "cUnderFunction.h"
47 
48 
49 using std::set;
50 
51 namespace fib{
52 
53 
55 
56 protected:
57 
58  /**
59  * The first underfunction for the function.
60  */
62 
63 public:
64 
65 
66  /**
67  * The constructor of the underfunction.
68  *
69  * @param pUnderfunction a pointer to the underfunction for the function
70  * (a clone of the underfunction will be taken as the underfunction of
71  * this function; this is a pointer, so that this constructor didn't
72  * gets confused with the copy constructor) @see pUnderfunction
73  * @param pInSuperiorFunction the underfunction which contains the
74  * new underfunction
75  * @param pInDefiningFibElement the fib -element which defines/ uses
76  * the new underfunction
77  */
79  cUnderFunction * pInSuperiorFunction = NULL,
80  cFibElement * pInDefiningFibElement = NULL );
81 
82  /**
83  * The copy constructor of the underfunction.
84  * This constructor will also copy the underfunctions of the given
85  * function.
86  *
87  * @param underfunction the underfunction which to copy
88  * @param pInSuperiorFunction the underfunction which contains the
89  * new underfunction
90  * @param pInDefiningFibElement the fib -element which defines/ uses
91  * the new underfunction
92  */
93  cFunctionOneValue( const cFunctionOneValue & underfunction,
94  cUnderFunction * pInSuperiorFunction = NULL,
95  cFibElement *pInDefiningFibElement = NULL );
96 
97  /**
98  * The constructor for restoring a value underfunction from an TinyXml element.
99  *
100  * @param pXmlNode a pointer to the TinyXml node the underfunction is stored in
101  * @param outStatus An reference to an integervalue where the errorvalue
102  * can be stored to.
103  * possible errorvalues are:
104  * - 0 loading successful
105  * - -1 loading error, invalid pXmlElement
106  * - -2 loading error, invalid data in pXmlElement
107  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
108  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
109  * object is wrong
110  * @param liDefinedVariables a list with the defined variables for the
111  * to restore fib -element, every variable should have it's number
112  * (the number under which it is stored) as it's value
113  * @param pInSuperiorFunction the underfunction which contains the
114  * new underfunction
115  * @param pInDefiningFibElement the fib -element which defines/ uses
116  * the new underfunction
117  */
118  cFunctionOneValue( const TiXmlElement * pXmlElement, intFib & outStatus,
119  list<cFibVariable*> & liDefinedVariables,
120  cUnderFunction * pInSuperiorFunction = NULL,
121  cFibElement * pInDefiningFibElement = NULL );
122 
123  /**
124  * This constructor restores a value underfunction from the stream
125  * where it is stored in the compressed fib -format.
126  * Beware: The bits for the functiontype should be allready readed, this
127  * constructor reads yust the one underfunctions.
128  *
129  * @param iBitStream the stream where this underfunction is stored to in,
130  * because this stream is an cReadBits, any number of bits can be
131  * readed from it
132  * @param outStatus An reference to an integervalue where the errorvalue
133  * can be stored to. If the pointer is NULL no errorvalue will be
134  * given back.
135  * possible errorvalues are:
136  * - 0 loading successful
137  * - -1 loading error, invalid stream
138  * - -2 loading error, invalid data in stream
139  * - 1 loading warning, invalid data in stream, error could be corrected
140  * - 2 loading warning, invalid data in stream, maybe the loaded
141  * object is wrong
142  * @param liDefinedVariables a list with the defined variables for the
143  * to restore fib -element, every variable should have it's number
144  * (the number under which it is stored) as it's value
145  * @param pInDomainValue the domain for value underfunction
146  * @param pInDomainVariable the domain for variables
147  * @param pInSuperiorFunction the underfunction which contains the
148  * new underfunction
149  * @param pInDefiningFibElement the fib -element which defines/ uses
150  * the new underfunction
151  */
152  cFunctionOneValue( cReadBits & iBitStream, intFib & outStatus,
153  list<cFibVariable*> & liDefinedVariables,
154  const cDomainSingle * pInDomainValue, const cDomainSingle * pInDomainVariable,
155  cUnderFunction * pInSuperiorFunction = NULL,
156  cFibElement * pInDefiningFibElement = NULL );
157 
158 
159  /**
160  * The destructor of the underfunction.
161  */
162  virtual ~cFunctionOneValue();
163 
164  /**
165  * @return This method returns a pointer to the underfunction of
166  * this function. @see pUnderfunction
167  */
169 
170  /**
171  * This methods sets the underfunction of this function.
172  *
173  * @see pUnderfunction
174  * @param underFunction the underfunction, which should be set as the
175  * underfunction of this function; the underfunction will be
176  * copied and the copy will be inserted
177  * @param bDeleteOld if true the old underfunction will be deleted from
178  * memory, else the old underfunction should be deleted elswher
179  */
180  void setUnderFunction( const cUnderFunction & underFunction,
181  bool bDeleteOld=true );
182 
183  /**
184  * This method returns if this underfunction is valid, else false.
185  * All values in the underfunction and it's underfunctions must be
186  * inside the underfunction domain. All variables must be defined over
187  * this underfunction.
188  * No underfunction should contain itselfor should be contained in one
189  * of its underfunctions (no cycles allowed).
190  *
191  * @return true if this underfunction is valid, else false
192  */
193  virtual bool isValid() const;
194 
195  /**
196  * This method checks if the given variable is used in this underfunction.
197  *
198  * @see cFibVariable
199  * @param variable the variable to check if it is used
200  * @return true if the variable is used, else false
201  */
202  virtual bool isUsedVariable( const cFibVariable * variable ) const;
203 
204  /**
205  * This method returns all variables used in this underfunction.
206  *
207  * @see cFibVariable
208  * @return all variables used in this underfunction
209  */
210  virtual set<cFibVariable*> getUsedVariables();
211 
212  /**
213  * This method replace the variable variableOld with the variable
214  * variableNew in the underfunction.
215  *
216  * @see cFibVariable
217  * @see isVariable()
218  * @see isUsedVariable()
219  * @param variableOld the variable to replace
220  * @param variableNew the variable with which the variable variableOld
221  * is to replace
222  * @return true if the variable variableOld is replaced with variableNew,
223  * else false
224  */
225  virtual bool replaceVariable( cFibVariable *variableOld,
226  cFibVariable *variableNew );
227 
228  /**
229  * @return the number of underfunctions, a underfunction of this type has
230  */
232 
233  /**
234  * Sets the Fib -element which defines/ uses this underfunction.
235  * If the given pointer is the nullpointer (standardvalue), no
236  * Fib -element defines this underfunction.
237  *
238  * @param definingFibElement a pointer to the Fib -element which
239  * defines/ uses this underfunction
240  * @param bCheckDomains getthe domains of the defining element and
241  * check the underfunctionelements with it
242  */
243  virtual void setDefiningFibElement( cFibElement *fibElement=NULL,
244  bool bCheckDomains=true );
245 
246  /**
247  * This method evaluades a value for the time needed to evalue the
248  * underfunction.
249  * This value should not exceed lMaxTime, if the value for the time
250  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
251  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
252  * stoped, this is the standard case.
253  *
254  * @see cFibElement::evalueObject()
255  * @param lMaxTime the maximum time for the evaluation, the returned
256  * exceed this value; the value 0 stands for infinity, so the
257  * evaluation won't be stoped
258  * @return a value for the time needed to evalue this underfunction
259  */
260  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
261 
262  /**
263  * This method evaluades the size of the Fib -object in bits in the
264  * compressed file form.
265  * The optionalpart field of point -elements will be ignored.
266  *
267  * @see store()
268  * @return the size of the Fib -object in bits in the compressed form
269  */
270  virtual unsignedLongFib getCompressedSize() const;
271 
272  /**
273  * This method stores this underfunction in the XML -format into the
274  * given stream.
275  * Variables should have ther number as ther value.
276  *
277  * @param stream the stream where this underfunctionshould be
278  * stored to
279  * @return true if this underfunction is stored, else false
280  */
281  virtual bool storeXml( ostream &stream ) const;
282 
283 #ifndef FEATURE_EQUAL_FIB_OBJECT
284 
285  /**
286  * This Method checks if the given underfunction is equal to this underfunction.
287  *
288  * @param underfunction the underfunction to compare with this underfunction
289  * @return true if the given underfunction is equal to this underfunction, else false
290  */
291  virtual bool equal( const cUnderFunction & underfunction ) const;
292 
293 #endif //FEATURE_EQUAL_FIB_OBJECT
294 
295 protected:
296 
297 #ifdef FEATURE_EQUAL_FIB_OBJECT
298  /**
299  * This method checks if the given underfunction is equal to this underfunction.
300  * Variables can be others, but must be defined and used in equivalent
301  * Fib-elements.
302  *
303  * @param underfunction the underfunction to compare with this underfunction
304  * @param mapEqualRootObjects the root objects of this object that wher
305  * already checked as equal
306  * map entries:
307  * key: the root-element of this Fib object that was checked
308  * value: the to the key correspondending root-element of the
309  * fibObject that was checked and which is equal to the key
310  * root-element
311  * (it is empty if bCheckExternalObjects == false)
312  * @param mapEqualDefinedVariables the Fib elements that defines
313  * variables and are equal;
314  * map entries:
315  * key: the Fib element of this Fib object that was checked
316  * value: the to the key correspondending Fib element of the
317  * fibObject that was checked and which sets its defined
318  * variables to the same values as the key Fib element
319  * @param bCheckExternalObjects if true the external objects of
320  * cExtObject will be compared
321  * @return true if this Fib-object is equal to the given Fib-object,
322  * else false
323  */
324  virtual bool equalInternal( const cUnderFunction & underfunction,
325  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
326  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
327  const bool bCheckExternalObjects ) const;
328 
329 #endif //FEATURE_EQUAL_FIB_OBJECT
330 
331 
332 };//end class cFunctionOneValue
333 
334 
335 }//end namespace fib
336 
337 #endif