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
cUnderFunction.h
Go to the documentation of this file.
1 /**
2  * @class cUnderFunction
3  * file name: cUnderFunction.h
4  * @author Betti Oesterholz
5  * @date 22.04.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a basic Fib-underfunction.
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 file contains the basisclass of all Fib-underfunctions. It's not
28  * possible to create instances from this class.
29  * Underfunctions are used in Fib-elements, especialy functions, to
30  * represent mathematical functions such like addition or the maximum
31  * function.
32  *
33  */
34 /*
35 History:
36 22.04.2010 Oesterholz created
37 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
38 */
39 
40 #ifndef ___C_UNDER_FUNCTION_H__
41 #define ___C_UNDER_FUNCTION_H__
42 
43 
44 #include "version.h"
45 #include "fibDatatyps.h"
46 #include "cReadBits.h"
47 
48 #include "cTypeUnderFunction.h"
49 #include "cDomainSingle.h"
50 #include "cFibVariable.h"
51 
52 #include "tinyxml.h"
53 
54 #include <sstream>
55 #include <ostream>
56 #include <istream>
57 #include <set>
58 #include <list>
59 
60 using std::set;
61 using std::list;
62 
63 namespace fib{
64 
65 
66 class cFibElement;//cyclic dependencie
67 
68 
70 
71  friend class cFunction;
72  friend class cFunctionIf;
73  friend class cFunctionOneValue;
74  friend class cFunctionTwoValue;
75  friend class cConditionComparison;
76 
77 public:
78 
79  /**
80  * the definitions for the underfunctions
81  */
82  static const unsignedIntFib FUNCTION_VALUE = 0; // cUnderFunction
83  static const unsignedIntFib FUNCTION_VARIABLE = 1; // cFunctionVariable
84  static const unsignedIntFib FUNCTION_LOG = 10; // cFunctionLog
85  static const unsignedIntFib FUNCTION_SIN = 11; // cFunctionSin
86  static const unsignedIntFib FUNCTION_ABS = 12; // cFunctionAbs
87  static const unsignedIntFib FUNCTION_ARCSIN = 13; // cFunctionArcsin
88  static const unsignedIntFib FUNCTION_ROUND = 14; // cFunctionRound
89  static const unsignedIntFib FUNCTION_ADD = 20; // cFunctionAdd
90  static const unsignedIntFib FUNCTION_SUB = 21; // cFunctionSub
91  static const unsignedIntFib FUNCTION_MULT = 22; // cFunctionMult
92  static const unsignedIntFib FUNCTION_DIV = 23; // cFunctionDiv
93  static const unsignedIntFib FUNCTION_EXP = 24; // cFunctionExp
94  static const unsignedIntFib FUNCTION_MIN = 25; // cFunctionMin
95  static const unsignedIntFib FUNCTION_MAX = 26; // cFunctionMax
96  static const unsignedIntFib FUNCTION_IF = 30; // cFunctionIf
97  static const unsignedIntFib FUNCTION_MOD = 31; // cFunctionMod
98 
99 protected:
100 
101  /**
102  * the Fib-element which defines/ uses the underfunction
103  */
105 
106  /**
107  * the Fib-element which defines/ uses the underfunction
108  */
110 
111 
112  /**
113  * The constructor of the underfunction.
114  *
115  * @param pInSuperiorUnderFunction the underfunction which contains
116  * @param pInDefiningFibElement the Fib-element which defines/ uses
117  * the new underfunction
118  */
119  cUnderFunction( cUnderFunction * pInSuperiorUnderFunction = NULL,
120  cFibElement * pInDefiningFibElement = NULL );
121 
122  /**
123  * The copy constructor of the underfunction.
124  *
125  * @param underfunction the underfunction which to copy
126  * @param pSuperiorUnderFunction the underfunction which contains
127  * @param pInDefiningFibElement the Fib-element which defines/ uses
128  */
129  cUnderFunction( const cUnderFunction & underfunction,
130  cUnderFunction * pInSuperiorUnderFunction = NULL,
131  cFibElement *pInDefiningFibElement = NULL );
132 
133 public:
134 
135  /**
136  * The destructor of the underfunction.
137  */
138  virtual ~cUnderFunction();
139 
140  /**
141  * This method returns if this underfunction is valid, else false.
142  * All values in the underfunction and it's underfunctions must be
143  * inside the underfunction domain. All variables must be defined over
144  * this underfunction.
145  * No underfunction should contain itself or should be contained in one
146  * of its underfunctions (no cycles allowed).
147  *
148  * @return true if this underfunction is valid, else false
149  */
150  virtual bool isValid() const = 0;
151 
152 
153  /**
154  * This method checks if the given variable is used in this underfunction.
155  *
156  * @see cFibVariable
157  * @param variable the variable to check if it is used
158  * @return true if the variable is used, else false
159  */
160  virtual bool isUsedVariable( const cFibVariable * variable ) const = 0;
161 
162  /**
163  * This method returns all variables used in this underfunction.
164  *
165  * @see cFibVariable
166  * @return all variables used in this underfunction
167  */
168  virtual set<cFibVariable*> getUsedVariables() = 0;
169 
170  /**
171  * This method replace the variable variableOld with the variable
172  * variableNew in the underfunction.
173  *
174  * @see cFibVariable
175  * @see isVariable()
176  * @see isUsedVariable()
177  * @param variableOld the variable to replace
178  * @param variableNew the variable with which the variable variableOld
179  * is to replace
180  * @return true if the variable variableOld is replaced with variableNew,
181  * else false
182  */
183  virtual bool replaceVariable( cFibVariable *variableOld,
184  cFibVariable *variableNew ) = 0;
185 
186  /**
187  * Returns the value of the underfunction or 0 if non such exists.
188  *
189  * @return the value of the underfunction or 0 if non
190  * such exists
191  */
192  virtual doubleFib getValue() const = 0;
193 
194  /**
195  * @return the number of underfunctions, a underfunction of this type has
196  */
197  virtual unsignedIntFib getNumberOfUnderFunctions() const = 0;
198 
199  /**
200  * Returns the type of the underfunction.
201  * You have to delete the returned object after usage.
202  *
203  * @return the type of the underfunction
204  */
205  virtual cTypeElement * getElementType() const;
206 
207 
208  /**
209  * Returns a reference to the domain of the underfunction or
210  * the nullpointer NULL if no domain is defined for the underfunction.
211  * If the nullpointer NULL is returned the standarddomain is valid for the
212  * underfunction.
213  *
214  * @return a reference to the underfunctiondomain of the underfunction
215  */
216  virtual cDomainSingle * getDomain() const;
217 
218  /**
219  * Returns a reference to the value domain of the underfunction or
220  * the nullpointer NULL if no value domain is defined for the underfunction.
221  * If the nullpointer NULL is returned the standarddomain is valid for the
222  * underfunction.
223  *
224  * @return a reference to the definitionarea of the underfunction
225  */
226  virtual cDomainSingle * getValueDomain() const;
227 
228  /**
229  * Returns a reference to the standard domain of the underfunction.
230  * You have to delete the returned object after usage.
231  *
232  * @return a reference to the standard domain of the underfunction
233  */
234  virtual cDomainSingle * getStandardDomain() const;
235 
236  /**
237  * Returns a reference to the domain for variables of the underfunction.
238  * You have to delete the returned object after usage.
239  *
240  * @return a reference to the domain for variables of the underfunction
241  */
242  virtual cDomainSingle * getVariableDomain() const;
243 
244  /**
245  * @return the Fib-element which defines/ uses this underfunction or
246  * a Nullpointer NULL if non such Fib-element exists
247  */
249 
250  /**
251  * @return the superior underfunction to this or NULL, if non such
252  * exists (the superior underfunction is the underfunction, which
253  * contains this underfunction)
254  */
256 
257  /**
258  * Sets the Fib-element which defines/ uses this underfunction.
259  * If the given pointer is the nullpointer (standardvalue), no
260  * Fib-element defines this underfunction.
261  *
262  * @param definingFibElement a pointer to the Fib-element which
263  * defines/ uses this underfunction
264  * @param bCheckDomains get the domains of the defining element and
265  * check the underfunctionelements with it
266  */
267  virtual void setDefiningFibElement( cFibElement *fibElement=NULL,
268  bool bCheckDomains=true );
269 
270  /**
271  * This method evaluades a value for the time needed to evalue the
272  * underfunction.
273  * This value should not exceed lMaxTime, if the value for the time
274  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
275  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
276  * stoped, this is the standard case.
277  *
278  * @see cFibElement::evalueObject()
279  * @param lMaxTime the maximum time for the evaluation, the returned
280  * exceed this value; the value 0 stands for infinity, so the
281  * evaluation won't be stoped
282  * @return a value for the time needed to evalue this underfunction
283  */
284  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const = 0;
285 
286  /**
287  * This method evaluades the size of the Fib-object in bits in the
288  * compressed file form.
289  * The optionalpart field of point -elements will be ignored.
290  *
291  * @see store()
292  * @return the size of the Fib-object in bits in the compressed form
293  */
294  virtual unsignedLongFib getCompressedSize() const = 0;
295 
296  /**
297  * This method restores a underfunction in the XML -format from an
298  * TinyXml element.
299  *
300  * @param pXmlNode a pointer to the TinyXml node wher the underfunction is stored in
301  * @param outStatus an integervalue with the errorvalue
302  * possible errorvalues are:
303  * - 0 loading successful
304  * - -1 loading error, invalid pXmlElement
305  * - -2 loading error, invalid data in pXmlElement
306  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
307  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
308  * object is wrong
309  * @param liDefinedVariables a list with the defined variables for the
310  * to restore Fib-element, every variable should have it's number
311  * (the number under which it is stored) as it's value
312  * @param pInSuperiorFunction the underfunction which contains the
313  * to restore underfunction
314  * @param pInDefiningFibElement the Fib-element which defines/ uses
315  * the to restore underfunction
316  * @return the pointers to the restored underfunction, if non could be restored
317  * the returned pointer is NULL
318  */
319  static cUnderFunction * restoreXml( const TiXmlElement * pXmlElement,
320  intFib & outStatus, list<cFibVariable*> & liDefinedVariables,
321  cUnderFunction * pInSuperiorFunction = NULL,
322  cFibElement *pInDefiningFibElement = NULL );
323 
324  /**
325  * This method stores this underfunction in the XML -format into the
326  * given stream.
327  * Variables should have ther number as ther value.
328  *
329  * @param stream the stream where this underfunctionshould be
330  * stored to
331  * @return true if this underfunction is stored, else false
332  */
333  virtual bool storeXml( ostream &stream ) const = 0;
334 
335  /**
336  * This method restores a underfunction from a bitstream, wher it is
337  * stored in the compressed Fib-format.
338  *
339  * @see store
340  * @param iBitStream the stream where the underfunction is stored in,
341  * because the stream is an cReadBits, any number of bits can be
342  * readed from it
343  * @param outStatus an integervalue with the errorvalue
344  * possible errorvalues are:
345  * - 0 loading successful
346  * - -1 loading error, invalid pXmlElement
347  * - -2 loading error, invalid data in pXmlElement
348  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
349  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
350  * object is wrong
351  * @param liDefinedVariables a list with the defined variables for the
352  * to restore Fib-element, every variable should have it's number
353  * (the number under which it is stored) as it's value
354  * @param pInValueDomain the domain for value underfunction
355  * @param pInDomainVariable the domain for variables
356  * @param pInSuperiorFunction the underfunction which contains the
357  * to restore underfunction
358  * @param pInDefiningFibElement the Fib-element which defines/ uses
359  * the to restore underfunction
360  * @return a pointer to the restored underfunction or NULL
361  */
362  static cUnderFunction * restore( cReadBits & iBitStream, intFib & outStatus,
363  list<cFibVariable*> & liDefinedVariables,
364  const cDomainSingle * pInValueDomain, const cDomainSingle * pInDomainVariable,
365  cUnderFunction * pInSuperiorFunction = NULL,
366  cFibElement *pInDefiningFibElement = NULL );
367 
368  /**
369  * This method stores this Fib-object in the compressed Fib-format
370  * into the given stream.
371  * It is needed becouse the stream can yust store byts but the size of
372  * Fib-elements can be any number of bits. Because of that ther have to
373  * be a possibility to exchange the missing bits betwean the Fib-elements.
374  *
375  * @see store
376  * @param stream the stream where this Fib-object should be stored to
377  * @param cRestBits the not yet writen bits which should be stored
378  * @param uiRestBitPosition the number of bits in the cRestBits which
379  * should be writen respectively containing valid information
380  * @return true if this Fib-object is stored, else false
381  */
382  virtual bool store( ostream & stream, char & cRestBits,
383  unsigned char & uiRestBitPosition ) const = 0;
384 
385  /**
386  * @return the type for the underfunction
387  */
388  virtual unsignedIntFib getType() const = 0;
389 
390  /**
391  * @return the name for the underfunction
392  */
393  virtual string getUnderFunctionName() const = 0;
394 
395 #ifdef FEATURE_EQUAL_FIB_OBJECT
396 
397  /**
398  * This method checks if the given underfunction is equal to this underfunction.
399  *
400  * @param underfunction the underfunction to compare with this underfunction
401  * @param bCheckExternalObjects if true the external objects of
402  * cExtObject will be compared
403  * @return true if the given underfunction is equal to this underfunction, else false
404  */
405  virtual bool equal( const cUnderFunction &underfunction,
406  const bool bCheckExternalObjects=true ) const;
407 
408 #else //FEATURE_EQUAL_FIB_OBJECT
409 
410  /**
411  * This method checks if the given underfunction is equal to this underfunction.
412  *
413  * @param underfunction the underfunction to compare with this underfunction
414  * @return true if the given underfunction is equal to this underfunction, else false
415  */
416  virtual bool equal( const cUnderFunction &underfunction ) const = 0;
417 
418 #endif //FEATURE_EQUAL_FIB_OBJECT
419 
420  /**
421  * This method checks if the given underfunction is equal to this underfunction.
422  *
423  * @param underfunction the underfunction to compare with this underfunction
424  * @return true if the given underfunction is equal to this underfunction, else false
425  */
426  virtual bool operator==( const cUnderFunction &underfunction ) const;
427 
428  /**
429  * This method checks if the given underfunction is not equal to this underfunction.
430  *
431  * @param underfunction the underfunction to compare with this underfunction
432  * @return true if the given underfunction is not equal to this underfunction, else false
433  */
434  bool operator!=( const cUnderFunction &underfunction ) const;
435 
436  /**
437  * This method duplicates this whole underfunction.
438  * Underfunctions of this underfunction are also cloned.
439  *
440  * @param pSuperiorUnderFunction the underfunction which contains the
441  * cloned underfunction
442  * @param pInDefiningFibElement the Fib-element which defines/ uses the
443  * cloned underfunction
444  * @return the cloned/ duplicated underfunction
445  */
446  virtual cUnderFunction * clone(
447  cUnderFunction * pInSuperiorUnderFunction = NULL,
448  cFibElement *pInDefiningFibElement = NULL) const = 0;
449 
450 protected:
451 
452 #ifdef FEATURE_EQUAL_FIB_OBJECT
453  /**
454  * This method checks if the given underfunction is equal to this underfunction.
455  * Variables can be others, but must be defined and used in equivalent
456  * Fib-elements.
457  *
458  * @param underfunction the underfunction to compare with this underfunction
459  * @param mapEqualRootObjects the root objects of this object that wher
460  * already checked as equal
461  * map entries:
462  * key: the root-element of this Fib object that was checked
463  * value: the to the key correspondending root-element of the
464  * fibObject that was checked and which is equal to the key
465  * root-element
466  * (it is empty if bCheckExternalObjects == false)
467  * @param mapEqualDefinedVariables the Fib elements that defines
468  * variables and are equal;
469  * map entries:
470  * key: the Fib element of this Fib object that was checked
471  * value: the to the key correspondending Fib element of the
472  * fibObject that was checked and which sets its defined
473  * variables to the same values as the key Fib element
474  * @param bCheckExternalObjects if true the external objects of
475  * cExtObject will be compared
476  * @return true if this Fib-object is equal to the given Fib-object,
477  * else false
478  */
479  virtual bool equalInternal( const cUnderFunction & underfunction,
480  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
481  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
482  const bool bCheckExternalObjects ) const = 0;
483 
484 #endif //FEATURE_EQUAL_FIB_OBJECT
485 
486 
487 };//end class cUnderFunction
488 
489 
490 }//end namespace fib
491 
492 #endif