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
cFunctionTwoValue.h
Go to the documentation of this file.
1 /**
2  * @class cFunctionTwoValue
3  * file name: cFunctionTwoValue.h
4  * @author Betti Oesterholz
5  * @date 30.04.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents the basisclass for all two 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 two value underfunctions.
28  * From this class all classes are derived, which represent functions,
29  * which work on two input values.
30  *
31  */
32 /*
33 History:
34 30.04.2010 Oesterholz created
35 03.07.2010 Oesterholz const get*UnderFunction() added
36 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
37 */
38 
39 #ifndef ___C_FUNCTION_TWO_VALUE_H__
40 #define ___C_FUNCTION_TWO_VALUE_H__
41 
42 
43 #include "version.h"
44 #include "fibDatatyps.h"
45 #include "cReadBits.h"
46 
47 #include "cUnderFunction.h"
48 
49 
50 using std::set;
51 
52 namespace fib{
53 
54 
56 
57 protected:
58 
59  /**
60  * The first underfunction for the function.
61  */
63 
64  /**
65  * The second underfunction for the function.
66  */
68 
69 public:
70 
71 
72  /**
73  * The constructor of the underfunction.
74  *
75  * @param firstUnderfunction the first underfunction for the function
76  * @see pFirstUnderfunction
77  * @param secondUnderfunction the second underfunction for the function
78  * @see pSecondUnderfunction
79  * @param pInSuperiorFunction the underfunction which contains the
80  * new underfunction
81  * @param pInDefiningFibElement the fib -element which defines/ uses
82  * the new underfunction
83  */
84  cFunctionTwoValue( const cUnderFunction & firstUnderfunction,
85  const cUnderFunction & secondUnderfunction,
86  cUnderFunction * pInSuperiorFunction = NULL,
87  cFibElement * pInDefiningFibElement = NULL );
88 
89  /**
90  * The constructor of the underfunction.
91  *
92  * @param pInFirstUnderfunction a pointer to the first underfunction
93  * for the function
94  * Beware: It won't be copied for inserting.
95  * @see pFirstUnderfunction
96  * @param pInSecondUnderfunction a pointer to the second underfunction
97  * for the function
98  * Beware: It won't be copied for inserting.
99  * @see pSecondUnderfunction
100  * @param pInSuperiorFunction the underfunction which contains the
101  * new underfunction
102  * @param pInDefiningFibElement the fib -element which defines/ uses
103  * the new underfunction
104  */
105  cFunctionTwoValue( cUnderFunction * pInFirstUnderfunction,
106  cUnderFunction * pInSecondUnderfunction,
107  cUnderFunction * pInSuperiorFunction = NULL,
108  cFibElement * pInDefiningFibElement = NULL );
109 
110  /**
111  * The copy constructor of the underfunction.
112  * This constructor will also copy the underfunctions of the given
113  * function.
114  *
115  * @param underfunction the underfunction which to copy
116  * @param pInSuperiorFunction the underfunction which contains the
117  * new underfunction
118  * @param pInDefiningFibElement the fib -element which defines/ uses
119  * the new underfunction
120  */
121  cFunctionTwoValue( const cFunctionTwoValue & underfunction,
122  cUnderFunction * pInSuperiorFunction = NULL,
123  cFibElement *pInDefiningFibElement = NULL );
124 
125  /**
126  * The constructor for restoring a value underfunction from an TinyXml element.
127  *
128  * @param pXmlNode a pointer to the TinyXml node the underfunction is stored in
129  * @param outStatus An reference to an integervalue where the errorvalue
130  * can be stored to.
131  * possible errorvalues are:
132  * - 0 loading successful
133  * - -1 loading error, invalid pXmlElement
134  * - -2 loading error, invalid data in pXmlElement
135  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
136  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
137  * object is wrong
138  * @param liDefinedVariables a list with the defined variables for the
139  * to restore fib -element, every variable should have it's number
140  * (the number under which it is stored) as it's value
141  * @param pInSuperiorFunction the underfunction which contains the
142  * new underfunction
143  * @param pInDefiningFibElement the fib -element which defines/ uses
144  * the new underfunction
145  */
146  cFunctionTwoValue( const TiXmlElement * pXmlElement, intFib & outStatus,
147  list<cFibVariable*> & liDefinedVariables,
148  cUnderFunction * pInSuperiorFunction = NULL,
149  cFibElement * pInDefiningFibElement = NULL );
150 
151  /**
152  * This constructor restores a value underfunction from the stream
153  * where it is stored in the compressed fib -format.
154  * Beware: The bits for the functiontype should be allready readed, this
155  * constructor reads yust the two underfunctions.
156  *
157  * @param iBitStream the stream where this underfunction is stored to in,
158  * because this stream is an cReadBits, any number of bits can be
159  * readed from it
160  * @param outStatus An reference to an integervalue where the errorvalue
161  * can be stored to. If the pointer is NULL no errorvalue will be
162  * given back.
163  * possible errorvalues are:
164  * - 0 loading successful
165  * - -1 loading error, invalid stream
166  * - -2 loading error, invalid data in stream
167  * - 1 loading warning, invalid data in stream, error could be corrected
168  * - 2 loading warning, invalid data in stream, maybe the loaded
169  * object is wrong
170  * @param liDefinedVariables a list with the defined variables for the
171  * to restore fib -element, every variable should have it's number
172  * (the number under which it is stored) as it's value
173  * @param pInDomainValue the domain for value underfunction
174  * @param pInDomainVariable the domain for variables
175  * @param pInSuperiorFunction the underfunction which contains the
176  * new underfunction
177  * @param pInDefiningFibElement the fib -element which defines/ uses
178  * the new underfunction
179  */
180  cFunctionTwoValue( cReadBits & iBitStream, intFib & outStatus,
181  list<cFibVariable*> & liDefinedVariables,
182  const cDomainSingle * pInDomainValue, const cDomainSingle * pInDomainVariable,
183  cUnderFunction * pInSuperiorFunction = NULL,
184  cFibElement * pInDefiningFibElement = NULL );
185 
186 
187  /**
188  * The destructor of the underfunction.
189  */
190  virtual ~cFunctionTwoValue();
191 
192  /**
193  * @return This method returns a pointer to the first underfunction of
194  * this function. @see pFirstUnderfunction
195  */
197 
198  /**
199  * @return This method returns a pointer to the first underfunction of
200  * this function. @see pFirstUnderfunction
201  */
202  const cUnderFunction * getFirstUnderFunction() const;
203 
204  /**
205  * This methods sets the first underfunction of this function.
206  *
207  * @see pFirstUnderfunction
208  * @param underFunction the underfunction, which should be set as the
209  * first underfunction of this function; the underfunction will be
210  * copied and the copy will be inserted
211  * @param bDeleteOld if true the old underfunction will be deleted from
212  * memory, else the old underfunction should be deleted elswher
213  */
214  void setFirstUnderFunction( const cUnderFunction & underFunction,
215  bool bDeleteOld=true );
216 
217  /**
218  * @return This method returns a pointer to the second underfunction of
219  * this function. @see pSecondUnderfunction
220  */
222 
223  /**
224  * @return This method returns a pointer to the second underfunction of
225  * this function. @see pSecondUnderfunction
226  */
227  const cUnderFunction * getSecondUnderFunction() const;
228 
229  /**
230  * This methods sets the second underfunction of this function.
231  *
232  * @see pSecondUnderfunction
233  * @param underFunction the underfunction, which should be set as the
234  * second underfunction of this function; the underfunction will be
235  * copied and the copy will be inserted
236  * @param bDeleteOld if true the old underfunction will be deleted from
237  * memory, else the old underfunction should be deleted elswher
238  */
239  void setSecondUnderFunction( const cUnderFunction & underFunction,
240  bool bDeleteOld=true );
241 
242  /**
243  * This method returns if this underfunction is valid, else false.
244  * All values in the underfunction and it's underfunctions must be
245  * inside the underfunction domain. All variables must be defined over
246  * this underfunction.
247  * No underfunction should contain itselfor should be contained in one
248  * of its underfunctions (no cycles allowed).
249  *
250  * @return true if this underfunction is valid, else false
251  */
252  virtual bool isValid() const;
253 
254  /**
255  * This method checks if the given variable is used in this underfunction.
256  *
257  * @see cFibVariable
258  * @param variable the variable to check if it is used
259  * @return true if the variable is used, else false
260  */
261  virtual bool isUsedVariable( const cFibVariable * variable ) const;
262 
263  /**
264  * This method returns all variables used in this underfunction.
265  *
266  * @see cFibVariable
267  * @return all variables used in this underfunction
268  */
269  virtual set<cFibVariable*> getUsedVariables();
270 
271  /**
272  * This method replace the variable variableOld with the variable
273  * variableNew in the underfunction.
274  *
275  * @see cFibVariable
276  * @see isVariable()
277  * @see isUsedVariable()
278  * @param variableOld the variable to replace
279  * @param variableNew the variable with which the variable variableOld
280  * is to replace
281  * @return true if the variable variableOld is replaced with variableNew,
282  * else false
283  */
284  virtual bool replaceVariable( cFibVariable *variableOld,
285  cFibVariable *variableNew );
286 
287  /**
288  * @return the number of underfunctions, a underfunction of this type has
289  */
291 
292  /**
293  * Sets the Fib -element which defines/ uses this underfunction.
294  * If the given pointer is the nullpointer (standardvalue), no
295  * Fib -element defines this underfunction.
296  *
297  * @param definingFibElement a pointer to the Fib -element which
298  * defines/ uses this underfunction
299  * @param bCheckDomains getthe domains of the defining element and
300  * check the underfunctionelements with it
301  */
302  virtual void setDefiningFibElement( cFibElement *fibElement=NULL,
303  bool bCheckDomains=true );
304 
305  /**
306  * This method evaluades a value for the time needed to evalue the
307  * underfunction.
308  * This value should not exceed lMaxTime, if the value for the time
309  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
310  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
311  * stoped, this is the standard case.
312  *
313  * @see cFibElement::evalueObject()
314  * @param lMaxTime the maximum time for the evaluation, the returned
315  * exceed this value; the value 0 stands for infinity, so the
316  * evaluation won't be stoped
317  * @return a value for the time needed to evalue this underfunction
318  */
319  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
320 
321  /**
322  * This method evaluades the size of the Fib -object in bits in the
323  * compressed file form.
324  * The optionalpart field of point -elements will be ignored.
325  *
326  * @see store()
327  * @return the size of the Fib -object in bits in the compressed form
328  */
329  virtual unsignedLongFib getCompressedSize() const;
330 
331  /**
332  * This method stores this underfunction in the XML -format into the
333  * given stream.
334  * Variables should have ther number as ther value.
335  *
336  * @param stream the stream where this underfunctionshould be
337  * stored to
338  * @return true if this underfunction is stored, else false
339  */
340  virtual bool storeXml( ostream &stream ) const;
341 
342 #ifndef FEATURE_EQUAL_FIB_OBJECT
343 
344  /**
345  * This Method checks if the given underfunction is equal to this underfunction.
346  *
347  * @param underfunction the underfunction to compare with this underfunction
348  * @return true if the given underfunction is equal to this underfunction, else false
349  */
350  virtual bool equal( const cUnderFunction & underfunction ) const;
351 #endif //FEATURE_EQUAL_FIB_OBJECT
352 
353 protected:
354 
355 #ifdef FEATURE_EQUAL_FIB_OBJECT
356 
357  /**
358  * This method checks if the given underfunction is equal to this underfunction.
359  * Variables can be others, but must be defined and used in equivalent
360  * Fib-elements.
361  *
362  * @param underfunction the underfunction to compare with this underfunction
363  * @param mapEqualRootObjects the root objects of this object that wher
364  * already checked as equal
365  * map entries:
366  * key: the root-element of this Fib object that was checked
367  * value: the to the key correspondending root-element of the
368  * fibObject that was checked and which is equal to the key
369  * root-element
370  * (it is empty if bCheckExternalObjects == false)
371  * @param mapEqualDefinedVariables the Fib elements that defines
372  * variables and are equal;
373  * map entries:
374  * key: the Fib element of this Fib object that was checked
375  * value: the to the key correspondending Fib element of the
376  * fibObject that was checked and which sets its defined
377  * variables to the same values as the key Fib element
378  * @param bCheckExternalObjects if true the external objects of
379  * cExtObject will be compared
380  * @return true if this Fib-object is equal to the given Fib-object,
381  * else false
382  */
383  virtual bool equalInternal( const cUnderFunction & underfunction,
384  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
385  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
386  const bool bCheckExternalObjects ) const;
387 
388 #endif //FEATURE_EQUAL_FIB_OBJECT
389 
390 };//end class cFunctionTwoValue
391 
392 
393 }//end namespace fib
394 
395 #endif