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