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