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
cFunction.h
Go to the documentation of this file.
1 /**
2  * @class cFunction
3  * file name: cFunction.h
4  * @author Betti Oesterholz
5  * @date 23.04.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents the Fib-functionelement.
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 functionelement of the Fib-multimedialanguage.
28  * An functionelement contains a underfunction which realizes the function.
29  * It defines a variable which is set to the value of the underfunction.
30  *
31  */
32 /*
33 History:
34 23.04.2010 Oesterholz created
35 06.05.2011 Oesterholz isValidFibElement() checks the underfunction
36 07.08.2011 Oesterholz isDefinedVariable() and getDefinedVariables() with
37  pCallingFibElement
38 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
39 */
40 
41 #ifndef ___C_FUNCTION_H__
42 #define ___C_FUNCTION_H__
43 
44 
45 #include "version.h"
46 
47 #include "fibDatatyps.h"
48 
49 #include "cFibLimb.h"
50 #include "cRoot.h"
51 #include "cUnderFunction.h"
52 #include "cFibVariable.h"
53 
54 namespace fib{
55 
56 
57 class cFunction: public cFibLimb{
58 
59 friend class cFibElement;
60 
61 private:
62 
63  /**
64  * The underfunction of the function element.
65  */
67 
68  /**
69  *The variable which this functionelement defines.
70  */
72 
73 public:
74 
75 #ifdef FEATURE_SIMPLE_CONSTRUCTOR
76 
77  /**
78  * parameterconstructor
79  *
80  * @param inUnderFunction the underfunction this function should have
81  * @param pInUnderobject the fib-element, which is the underobject of
82  * this fib-element (it also stands next in the order of fib-elements)
83  * @param pInSuperiorElement the fib-element in which this
84  * function element is an underobject
85  */
86  cFunction( const cUnderFunction & inUnderFunction,
87  cFibElement * pInUnderobject = NULL,
88  cFibElement * pInSuperiorElement = NULL );
89 
90 #else //FEATURE_SIMPLE_CONSTRUCTOR
91 
92  /**
93  * parameterconstructor
94  *
95  * @param inUnderFunction the underfunction this function should have
96  * @param pInSuperiorElement the fib-element in which this
97  * function -element is an underobject
98  * @param pInPreviousFibElement the fib-element which stands in the order
99  * of fib-elements befor this fib-element
100  * @param pInUnderobject the fib-element which is the underobject of
101  * this fib-element (it also stands next in the order of fib-elements)
102  */
103  cFunction( const cUnderFunction & inUnderFunction,
104  cFibElement * pInSuperiorElement = NULL,
105  cFibElement * pInPreviousFibElement = NULL,
106  cFibElement * pInUnderobject = NULL );
107 
108 #endif //FEATURE_SIMPLE_CONSTRUCTOR
109 
110  /**
111  * copyconstructor
112  * This copyconstructor constructs a copy of the given function element.
113  * It dosn't copy other fib-elements than the given, even if ther are
114  * in the function element.
115  *
116  * @param functionElement the function element to copy
117  */
118  cFunction( const cFunction & functionElement );
119 
120 protected:
121 
122  /**
123  * The constructor for restoring a functionobject from an TinyXml element.
124  *
125  * @param pXmlNode a pointer to the TinyXml node wher the Fib-object is stored in
126  * @param outStatus An reference to an integervalue where the errorvalue
127  * can be stored to.
128  * possible errorvalues are:
129  * - 0 loading successful
130  * - -1 loading error, invalid pXmlElement
131  * - -2 loading error, invalid data in pXmlElement
132  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
133  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
134  * object is wrong
135  * @param liDefinedVariables a list with the defined variables for the
136  * to restore fib-element, every variable should have it's number
137  * (the number under which it is stored) as it's value
138  */
139  cFunction( const TiXmlElement * pXmlElement, intFib &outStatus,
140  list<cFibVariable*> & liDefinedVariables );
141 
142  /**
143  * This constructor restores a functionobject from the stream where it is
144  * stored in the compressed Fib-format.
145  * This method is for internal use only.
146  *
147  * @param iBitStream the stream wher the functionobject is stored to in,
148  * because this stream is an cReadBits, any number of bits can be
149  * readed from it
150  * @param outStatus An reference to an integervalue where the errorvalue
151  * can be stored to. If the pointer is NULL no errorvalue will be
152  * given back.
153  * possible errorvalues are:
154  * - 0 loading successful
155  * - -1 loading error, invalid stream
156  * - -2 loading error, invalid data in stream
157  * - 1 loading warning, invalid data in stream, error could be corrected
158  * - 2 loading warning, invalid data in stream, maybe the loaded
159  * object is wrong
160  * @param liDefinedVariables a list with the defined variables for the
161  * to restore fib-element, every variable should have it's number
162  * (the number under which it is stored) as it's value
163  * @param validDomains the domains valid for restoring the fib-elements
164  * @param pNextRoot the next higher root-element for the to restore
165  * fib-elements, or the last restored root-element
166  */
167  cFunction( cReadBits & iBitStream, intFib & outStatus,
168  list<cFibVariable*> & liDefinedVariables, const cDomains & validDomains,
169  cRoot * pNextRoot );
170 
171 
172 public:
173 
174  /**
175  * desstructor
176  */
177  ~cFunction();
178 
179  /**
180  * This method checks, if this Fib-element is an valid Fib-element.
181  *
182  * @return true if this Fib-element is an valid Fib-element, else false
183  */
184  virtual bool isValidFibElement() const;
185 
186  /**
187  * @see getTypeName
188  * @return a character for the typ of the fib-element
189  * Types are:
190  * - u: element of unknown typ
191  * - p: point
192  * - l: list-element
193  * - y: property
194  * - c: comment
195  * - a: area
196  * - f: function
197  * - i: if-condition
198  * - o: extern object element
199  * - s: extern subobject element
200  * - v: set-element
201  * - m: matrix element
202  * - r: root-element
203  */
204  virtual char getType() const;
205 
206  /**
207  * This method evaluades the Fib-object.
208  *
209  * @param evaluePosition a reference to the object with the
210  * evaluePosition() method to evalue /store the positions and ther
211  * properties; everytime a point (to evalue) is reached in the
212  * evaluation, this method is called with the position and the
213  * properties of the point; @see iEvaluePosition
214  * @param objectPoint the object point in the order of true partobjects
215  * to evalue
216  * @param liVecProperties a list with the property vectors which should
217  * be global for the evalued object
218  * @return if the evalueation was successfull true, else false
219  */
220  virtual bool evalueObject( iEvaluePosition & evaluePosition,
221  const unsignedIntFib objectPoint,
222  list<cVectorProperty> & liVecProperties ) const;
223 
224  /**
225  * This method evaluades the Fib-object.
226  * Evertime a fib-elements, with a type of the given type chars in
227  * liCFibElementTyps, is reached while evaluation, it is given
228  * back with the properties which it has.
229  * Ever pointelement is given back. The type chars for pointelements
230  * don't need to be in the list liCFibElementTyps.
231  *
232  * @param evalueFibElement a reference to the object with the
233  * evalueElement() method to evalue /store the fib-elements and ther
234  * properties; everytime a fib-element (with one of the type given
235  * in liCFibElementTyps) is reached in the evaluation, the method
236  * evalueElement() of this objects is called with the fib-element
237  * and the properties of the fib-element; @see iEvalueFibElement
238  * @param objectPoint the object point in the order of true partobjects
239  * to evalue
240  * @param liVecProperties a list with the property vectors which should
241  * be global for the evalued object
242  * @param liCFibElementTyps a list with the type chars (@see getType)
243  * of the fib-elements to return
244  * @return if the evalueation was successfull true, else false
245  */
246  virtual bool evalueObject( iEvalueFibElement & evalueFibElement,
247  const unsignedIntFib objectPoint,
248  list<cVectorProperty> & liVecProperties,
249  const list<char> & liCFibElementTyps );
250 
251  /**
252  * This method evaluades a value for the time needed to evalue the
253  * object.
254  * This value should not exceed lMaxTime, if the value for the time
255  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
256  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
257  * stoped, this is the standard case.
258  *
259  * @see evalueObject()
260  * @param lMaxTime the maximum time for the evaluation, the returned
261  * exceed this value; the value 0 stands for infinity, so the
262  * evaluation won't be stoped
263  * @return a value for the time needed to evalue the object
264  */
265  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
266 
267  /**
268  * This method evaluades the size of the Fib-object in bits in the
269  * compressed file form.
270  * The optionalpart field of function -elements will be ignored.
271  *
272  * @see store()
273  * @return the size of the Fib-object in bits in the compressed form
274  */
275  virtual unsignedLongFib getCompressedSize() const;
276 
277  /**
278  * This method checks if the given variable is used in the given
279  * direction from this fib-element.
280  *
281  * @see cFibVariable
282  * @see isDefinedVariable()
283  * @param variable the variable to check if it is used
284  * @param direction the direction from this fib-element, in which the
285  * variable should be used; standardvalue is ED_POSITION so yust
286  * this fib-element will be checked
287  * @return true if the variable is used, else false
288  */
289  virtual bool isUsedVariable( const cFibVariable *variable ,
290  edDirection direction=ED_POSITION ) const;
291 
292  /**
293  * This method returns all variables used in the given direction from
294  * this fib-element.
295  *
296  * @see cFibVariable
297  * @see isUsedVariable()
298  * @see isDefinedVariable()
299  * @param direction the direction from this fib-element, in which the
300  * variable should be used; standardvalue is ED_POSITION so yust
301  * this fib-element will be checked
302  * @return the set with all variables used in the given direction from
303  * this fib-element
304  */
305  virtual set<cFibVariable*> getUsedVariables( edDirection direction=ED_POSITION );
306 
307  /**
308  * This method replace the variable variableOld with the variable
309  * variableNew in the object.
310  *
311  * @see cFibVariable
312  * @see isUsedVariable()
313  * @see isDefinedVariable()
314  * @param variableOld the variable to replace
315  * @param variableNew the variable with which the variable variableOld
316  * is to replace
317  * @return true if the variable variableOld is replaced with variableNew,
318  * else false
319  */
320  virtual bool replaceVariable( cFibVariable *variableOld,
321  cFibVariable *variableNew );
322 
323 
324  /**
325  * This method copies the fib-element on the specified position.
326  * Variables which are not defined in the fib-element but used
327  * don't change ther reference.
328  *
329  * @see getType()
330  * @param cType the type of the fib-element to copy
331  * @param elementPoint the number of the fib-element, in the order of
332  * Fib-elements of the given type cType, to copy
333  * @param bAbsolute if the lNumber is an absolute value for the wool
334  * Fib-object
335  * @return the copy of the fib-element
336  */
337  virtual cFibElement *copyElement( const char cType='u', const unsignedIntFib
338  elementPoint=0, bool bAbsolute=false ) const;
339 
340 #ifndef FEATURE_EQUAL_FIB_OBJECT
341 
342  /**
343  * This method checks if the given Fib-object is equal to this Fib
344  * -object.
345  * Variables can be others, but must be defined and used in equivalent
346  * fib-elements.
347  *
348  * @param fibObject the Fib-object to which this Fib-object should be
349  * equal
350  * @return true if this Fib-object is equal to the given Fib-object,
351  * else false
352  */
353  virtual bool equal( const cFibElement & fibObject ) const;
354 
355  /**
356  * This method checks if the given fib-element is equal to this fib
357  * -element.
358  * The underobjects arn't compared, not even ther count is compared.
359  * Used variables can be others.
360  *
361  * @param fibElement the fib-element to which this fib-element should be
362  * equal
363  * @return true if this fib-element is equal to the given Fib-object,
364  * else false
365  */
366  virtual bool equalElement( const cFibElement & fibElement ) const;
367 
368 #endif //FEATURE_EQUAL_FIB_OBJECT
369 
370  /**
371  * This method stores this Fib-object in the XML -format into the
372  * given stream.
373  *
374  * @param stream the stream where this Fib-object should be stored to
375  * @return true if this Fib-object is stored, else false
376  */
377  virtual bool storeXml( ostream &stream ) const;
378 
379 
380 
381 /*
382  * functionelement methods
383  */
384 
385  /**
386  * @return the underfunction this functionelement realizes
387  */
389 
390  /**
391  * This method sets the given underfunction as the underfunction of
392  * this function.
393  * (The given underfunction is copied befor it is set.)
394  *
395  * @param underFunction a reference to the to set underfunction
396  * @return true if the underFunction was set, else false
397  */
398  bool setUnderFunction( const cUnderFunction & underFunction );
399 
400  /**
401  * @return a pointer to the variable this functionelement defines
402  */
404 
405 
406 protected:
407 
408  /**
409  * This method stores this Fib-object in the compressed Fib-format
410  * into the given stream.
411  * It is needed becouse the stream can yust store byts but the size of
412  * fib-elements can be any number of bits. Because of that ther have to
413  * be a possibility to exchange the missing bits betwean the fib-elements.
414  * Beware: You need to call storeBit() of the root-elements with the
415  * domain for the function or the function will not be readebel.
416  *
417  * @see store
418  * @param stream the stream where this Fib-object should be stored to
419  * @param cRestBits the not yet writen bits which should be stored
420  * @param uiRestBitPosition the number of bits in the cRestBits which
421  * should be writen respectively containing valid information
422  * @return true if this Fib-object is stored, else false
423  */
424  virtual bool storeBit( ostream & stream, char & cRestBits,
425  unsigned char & uiRestBitPosition ) const;
426 
427  /**
428  * This method sets the each variable, which is defined over an leaf,
429  * to an uniqe integer number greater than the given number
430  * uiLastVariableNumber. While storing this number can be stored to
431  * identify the variable.
432  *
433  * @param uiLastVariableNumber the number which was last use, this
434  * means also is the greatest used, in this limb.
435  * @return the number which was last use, this
436  * means also is the greatest used, in this limb
437  * from the method
438  */
440  unsignedIntFib uiLastVariableNumber = 0 );
441 
442  /**
443  * This method copies the connected object with the given number in the
444  * order of connected objects.
445  * For this every fib-element, beginning from this fib-element, that
446  * is part of the connected object will be copied.
447  * Variables which are not defined in the connected object but used
448  * don't change ther reference.
449  * It is an helpmethod for the copy method. It dosn't update the
450  * structural information of the created Fib-object.
451  *
452  * @param iObjectPoint the number of the connected object to copy;
453  * the standartvalue is 0 for coping the complet actual object
454  * @return the copy of the connected object or NULL if non such exists
455  */
456  virtual cFibElement *copyInternal( const unsignedIntFib iObjectPoint=0 ) const;
457 
458  /**
459  * This method checks if the given variable is defined in the given
460  * direction from this Fib-element.
461  * This is for intern use to get the correct data from
462  * isDefinedVariable() without pCallingFibElement.
463  *
464  * @see cFibVariable
465  * @see isUsedVariable()
466  * @param pVariable the variable to check if it is defined
467  * @param direction the direction from this Fib-element, in which the
468  * variable should be defined; standardvalue is ED_POSITION so yust
469  * this Fib-element will be checked
470  * @param pCallingFibElement the Fib-Element which called this method
471  * @return true if the variable is used, else false
472  */
473  virtual bool isDefinedVariableInternal( const cFibVariable * pVariable,
474  edDirection direction = ED_POSITION,
475  const cFibElement * pCallingFibElement = NULL ) const;
476 
477  /**
478  * This method returns all variables defined in the given direction from
479  * this Fib-element.
480  * This is for intern use to get the correct data from
481  * getDefinedVariables() without pCallingFibElement..
482  *
483  * @see cFibVariable
484  * @see getUsedVariables()
485  * @see isDefinedVariable()
486  * @param direction the direction from this Fib-element, in which the
487  * variable should be used; standardvalue is ED_POSITION so yust
488  * this Fib-element will be checked
489  * @param pCallingFibElement the Fib-Element which called this method
490  * @return the set with all variables used in the given direction from
491  * this Fib-element
492  */
493  virtual list< cFibVariable* > getDefinedVariablesInternal(
494  edDirection direction = ED_HIGHER,
495  const cFibElement * pCallingFibElement = NULL );
496 
497 #ifdef FEATURE_EQUAL_FIB_OBJECT
498 
499  /**
500  * This method checks if the given Fib-object is equal to this fib
501  * -object.
502  * Variables can be others, but must be defined and used in equivalent
503  * Fib-elements.
504  *
505  * @param fibObject the Fib-object to which this Fib-object should be
506  * equal
507  * @param mapEqualRootObjects the root objects of this object that wher
508  * already checked as equal
509  * map entries:
510  * key: the root-element of this Fib object that was checked
511  * value: the to the key correspondending root-element of the
512  * fibObject that was checked and which is equal to the key
513  * root-element
514  * (it is empty if bCheckExternalObjects == false)
515  * @param mapEqualDefinedVariables the Fib elements that defines
516  * variables and are equal;
517  * map entries:
518  * key: the Fib element of this Fib object that was checked
519  * value: the to the key correspondending Fib element of the
520  * fibObject that was checked and which sets its defined
521  * variables to the same values as the key Fib element
522  * @param bCheckExternalObjects if true the external objects of
523  * cExtObject will be compared
524  * @return true if this Fib-object is equal to the given Fib-object,
525  * else false
526  */
527  virtual bool equalInternal( const cFibElement & fibObject,
528  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
529  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
530  const bool bCheckExternalObjects ) const;
531 
532  /**
533  * This method checks if the given Fib-element is equal to this fib
534  * -element.
535  * The subobjects arn't compared, not even ther count is compared.
536  * Used variables can be others.
537  *
538  * @param fibElement the Fib-element to which this Fib-element should be
539  * equal
540  * @param mapEqualRootObjects the root objects of this object that wher
541  * already checked as equal
542  * map entries:
543  * key: the root-element of this Fib object that was checked
544  * value: the to the key correspondending root-element of the
545  * fibObject that was checked and which is equal to the key
546  * root-element
547  * (it is empty if bCheckExternalObjects == false)
548  * @param mapEqualDefinedVariables the Fib elements that defines
549  * variables and are equal;
550  * map entries:
551  * key: the Fib element of this Fib object that was checked
552  * value: the to the key correspondending Fib element of the
553  * fibObject that was checked and which sets its defined
554  * variables to the same values as the key Fib element
555  * @param bCheckExternalObjects if true the external objects of
556  * cExtObject will be compared
557  * @return true if this Fib-element is equal to the given Fib-object,
558  * else false
559  */
560  virtual bool equalElementInternal( const cFibElement & fibElement,
561  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
562  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
563  const bool bCheckExternalObjects ) const;
564 
565 
566  /**
567  * This method checks if the given Fib-element sets the variable to
568  * the same values as this Fib-element.
569  *
570  * @param variableOwn a pointer to a defined variable in this Fib-element,
571  * it is compared to the equivalent variable fibElement in the given
572  * Fib-element fibElement
573  * @param fibElement the Fib-element to which this Fib-element should be
574  * compared
575  * @param variable a pointer to a defined variable in the other
576  * Fib-element fibElement
577  * @param mapEqualRootObjects the root objects of this object that wher
578  * already checked as equal
579  * map entries:
580  * key: the root-element of this Fib object that was checked
581  * value: the to the key correspondending root-element of the
582  * fibObject that was checked and which is equal to the key
583  * root-element
584  * (it is empty if bCheckExternalObjects == false)
585  * @param mapEqualDefinedVariables the Fib elements that defines
586  * variables and are equal;
587  * map entries:
588  * key: the Fib element of this Fib object that was checked
589  * value: the to the key correspondending Fib element of the
590  * fibObject that was checked and which sets its defined
591  * variables to the same values as the key Fib element
592  * @param bCheckExternalObjects if true the external objects of
593  * cExtObject will be compared
594  * @return true if this Fib-element sets the variable to the same
595  * values as this Fib-element
596  */
597  virtual bool equalValuesSetInternal( const cFibVariable * variableOwn,
598  const cFibElement & fibElement,
599  const cFibVariable * variable,
600  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
601  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
602  const bool bCheckExternalObjects ) const;
603 
604 #endif //FEATURE_EQUAL_FIB_OBJECT
605 
606 };
607 }//namespace fib
608 
609 #endif //___C_FUNCTION_H__
610 
611 
612 
613 
614 
615