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
cFibSet.h
Go to the documentation of this file.
1 /**
2  * @class cFibSet
3  * file name: cFibSet.h
4  * @author Betti Oesterholz
5  * @date 10.12.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents the Fib set-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 set-element of the Fib -multimedialanguage.
28  * An set-element contains a list with vectors to which element values the
29  * variables it defines are set.
30  *
31  */
32 /*
33 History:
34 10.12.2011 Oesterholz created
35 */
36 
37 #ifndef ___C_FIB_SET_H__
38 #define ___C_FIB_SET_H__
39 
40 
41 #include "version.h"
42 
43 #include "fibDatatyps.h"
44 
45 #include "cFibLimb.h"
46 #include "cRoot.h"
47 #include "cVectorFibSet.h"
48 #include "cFibVariable.h"
49 
50 namespace fib{
51 
52 
53 class cFibSet: public cFibLimb{
54 
55 friend class cFibElement;
56 
57 private:
58 
59  /**
60  * The variables, which this set-element defines.
61  */
62  vector< cFibVariable * > vecVariablesDefined;
63 
64  /**
65  * The list with the vectors of the set-element.
66  */
67  list< cVectorFibSet > liFibSets;
68 
69  /**
70  * The number of the set-element domain for this set-element.
71  */
73 
74 public:
75 
76  /**
77  * parameterconstructor
78  *
79  * @param iuNumberOfVariables the number of defined variables or
80  * elements in the vectors this set-element should have
81  * (minimum is 1)
82  * @param pInSubobject the Fib element which is the underobject of
83  * this Fib element (it also stands next in the order of Fib elements)
84  * @param pInSuperiorElement the Fib element in which this
85  * set-element is an underobject
86  */
87  cFibSet( const unsignedIntFib iuNumberOfVariables,
88  cFibElement * pInSubobject = NULL,
89  cFibElement * pInSuperiorElement = NULL );
90 
91  /**
92  * copyconstructor
93  * This copyconstructor constructs a copy of the given set-element.
94  * It dosn't copy other Fib elements than the given, even if ther are
95  * in the set-element.
96  *
97  * @param setElement the set-element to copy
98  */
99  cFibSet( const cFibSet &setElement );
100 
101 protected:
102 
103  /**
104  * The constructor for restoring a set-object from an TinyXml element.
105  *
106  * @param pXmlNode a pointer to the TinyXml node wher the Fib object is stored in
107  * @param outStatus An reference to an integervalue where the errorvalue
108  * can be stored to.
109  * possible errorvalues are:
110  * - 0 loading successful
111  * - -1 loading error, invalid pXmlElement
112  * - -2 loading error, invalid data in pXmlElement
113  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
114  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
115  * object is wrong
116  * @param liDefinedVariables a list with the defined variables for the
117  * to restore Fib element, every variable should have it's number
118  * (the number under which it is stored) as it's value
119  */
120  cFibSet( const TiXmlElement * pXmlElement, intFib &outStatus,
121  list<cFibVariable*> & liDefinedVariables );
122 
123  /**
124  * This constructor restores a set-object from the stream where it is
125  * stored in the compressed Fib format.
126  * This method is for internal use only.
127  *
128  * @param iBitStream the stream wher the set-object is stored to in,
129  * because this stream is an cReadBits, any number of bits can be
130  * readed from it
131  * @param outStatus An reference to an integervalue where the errorvalue
132  * can be stored to. If the pointer is NULL no errorvalue will be
133  * given back.
134  * possible errorvalues are:
135  * - 0 loading successful
136  * - -1 loading error, invalid stream
137  * - -2 loading error, invalid data in stream
138  * - 1 loading warning, invalid data in stream, error could be corrected
139  * - 2 loading warning, invalid data in stream, maybe the loaded
140  * object is wrong
141  * @param liDefinedVariables a list with the defined variables for the
142  * to restore Fib element, every variable should have it's number
143  * (the number under which it is stored) as it's value
144  * @param validDomains the domains valid for restoring the Fib elements
145  * @param pNextRoot the next higher root-element for the to restore
146  * Fib elements, or the last restored root-element
147  */
148  cFibSet( cReadBits & iBitStream, intFib & outStatus,
149  list<cFibVariable*> & liDefinedVariables, const cDomains & validDomains,
150  cRoot * pNextRoot );
151 
152 
153 public:
154 
155  /**
156  * destructor
157  */
158  virtual ~cFibSet();
159 
160  /**
161  * @see getTypeName
162  * @return a character for the typ of the Fib element
163  * Types are:
164  * - u: element of unknown typ
165  * - p: point
166  * - l: list-element
167  * - y: property
168  * - c: comment
169  * - a: area
170  * - f: function
171  * - i: if-condition
172  * - o: extern object element
173  * - s: extern subobject element
174  * - v: set-element
175  * - m: matrix element
176  * - r: root-element
177  */
178  virtual char getType() const;
179 
180  /**
181  * This method checks, if this Fib-element is an valid Fib-element.
182  *
183  * @return true if this Fib-element is an valid Fib-element, else false
184  */
185  virtual bool isValidFibElement() const;
186 
187  /**
188  * This method evaluades the Fib object.
189  *
190  * @param evaluePosition a reference to the object with the
191  * evaluePosition() method to evalue /store the positions and ther
192  * properties; everytime a point (to evalue) is reached in the
193  * evaluation, this method is called with the position and the
194  * properties of the point; @see iEvaluePosition
195  * @param objectPoint the object point in the order of true part objects
196  * to evalue
197  * @param liVecProperties a list with the property vectors which should
198  * be global for the evalued object
199  * @return if the evaluation was successfull true, else false
200  */
201  virtual bool evalueObject( iEvaluePosition & evaluePosition,
202  const unsignedIntFib objectPoint,
203  list<cVectorProperty> & liVecProperties ) const;
204 
205  /**
206  * This method evaluades the Fib object.
207  * Evertime a Fib elements, with a type of the given type chars in
208  * liCFibElementTyps, is reached while evaluation, it is given
209  * back with the properties which it has.
210  * Ever point element is given back. The type chars for point elements
211  * don't need to be in the list liCFibElementTyps.
212  *
213  * @param evalueFibElement a reference to the object with the
214  * evalueElement() method to evalue /store the Fib elements and ther
215  * properties; everytime a Fib element (with one of the type given
216  * in liCFibElementTyps) is reached in the evaluation, the method
217  * evalueElement() of this objects is called with the Fib element
218  * and the properties of the Fib element; @see iEvalueFibElement
219  * @param objectPoint the object point in the order of true part objects
220  * to evalue
221  * @param liVecProperties a list with the property vectors which should
222  * be global for the evalued object
223  * @param liCFibElementTyps a list with the type chars (@see getType)
224  * of the Fib elements to return
225  * @return if the evaluation was successfull true, else false
226  */
227  virtual bool evalueObject( iEvalueFibElement & evalueFibElement,
228  const unsignedIntFib objectPoint,
229  list<cVectorProperty> & liVecProperties,
230  const list<char> & liCFibElementTyps );
231 
232  /**
233  * This method evaluades a value for the time needed to evalue the
234  * object.
235  * This value should not exceed lMaxTime, if the value for the time
236  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
237  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
238  * stoped, this is the standard case.
239  *
240  * @see evalueObject()
241  * @param lMaxTime the maximum time for the evaluation, the returned value
242  * will not be greater than this value; the value 0 stands for infinity,
243  * so the evaluation won't be stoped
244  * @return a value for the time needed to evalue the object
245  */
246  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
247 
248  /**
249  * This method evaluades the size of the Fib object in bits in the
250  * compressed file form.
251  *
252  * @see store()
253  * @return the size of the Fib object in bits in the compressed form
254  */
255  virtual unsignedLongFib getCompressedSize() const;
256 
257  /**
258  * This method checks if the given variable is used in the given
259  * direction from this Fib element.
260  *
261  * @see cFibVariable
262  * @see isDefinedVariable()
263  * @param variable the variable to check if it is used
264  * @param direction the direction from this Fib element, in which the
265  * variable should be used; standardvalue is ED_POSITION so yust
266  * this Fib element will be checked
267  * @return true if the variable is used, else false
268  */
269  virtual bool isUsedVariable( const cFibVariable *variable ,
270  edDirection direction=ED_POSITION ) const;
271 
272  /**
273  * This method returns all variables used in the given direction from
274  * this Fib element.
275  *
276  * @see cFibVariable
277  * @see isUsedVariable()
278  * @see isDefinedVariable()
279  * @param direction the direction from this Fib element, in which the
280  * variable should be used; standardvalue is ED_POSITION so yust
281  * this Fib element will be checked
282  * @return the set with all variables used in the given direction from
283  * this Fib element
284  */
285  virtual set<cFibVariable*> getUsedVariables( edDirection direction=ED_POSITION );
286 
287  /**
288  * This method replace the variable pVariableOld with the variable
289  * pVariableNew in the object.
290  *
291  * @see cFibVariable
292  * @see isUsedVariable()
293  * @see isDefinedVariable()
294  * @param pVariableOld the variable to replace
295  * @param pVariableNew the variable with which the variable pVariableOld
296  * is to be replace
297  * @return true if the variable pVariableOld is replaced with pVariableNew,
298  * else false
299  */
300  virtual bool replaceVariable( cFibVariable * pVariableOld,
301  cFibVariable * pVariableNew );
302 
303  /**
304  * This method copies the Fib element on the specified position.
305  * Variables which are not defined in the Fib element but used
306  * don't change ther reference.
307  *
308  * @see getType()
309  * @param cType the type of the Fib element to copy
310  * @param elementPoint the number of the Fib element, in the order of
311  * Fib -elements of the given type cType, to copy
312  * @param bAbsolute if the lNumber is an absolute value for the wool
313  * Fib object
314  * @return the copy of the Fib element
315  */
316  virtual cFibElement *copyElement( const char cType='u', const unsignedIntFib
317  elementPoint=0, bool bAbsolute=false ) const;
318 
319  /**
320  * This method stores this Fib object in the XML -format into the
321  * given stream.
322  *
323  * @param stream the stream where this Fib object should be stored to
324  * @return true if this Fib object is stored, else false
325  */
326  virtual bool storeXml( ostream &stream ) const;
327 
328 
329 /*
330  * set-element methods
331  */
332 
333  /**
334  * @return the number of variables this set-element defines
335  */
337 
338  /**
339  * This method returns a pointer to the uiPosition'th from this
340  * set-element defined variable.
341  *
342  * @param uiPosition the number of the from this set-element defined
343  * variable to return (counting begins with 1)
344  * @return a pointer to the uiPosition'th from this set-element defined
345  * variable, or NULL if non such exists
346  */
347  cFibVariable * getDefinedVariable( const unsignedLongFib uiPosition );
348 
349 
350  /**
351  * @see uiDomainNr
352  * @return the number of the set-element domain for this set-element
353  */
354  unsignedIntFib getDomainNr() const;
355 
356  /**
357  * This method sets the number of the set-element domain for this
358  * set-element.
359  *
360  * @see uiDomainNr
361  * @param uiInDomainNumber the number of the set-element domain for this set-element
362  */
363  void setDomainNr( const unsignedLongFib uiInDomainNumber );
364 
365 
366  /**
367  * @see liFibSets
368  * @return the number of vectors or sets of values this set-element contains
369  */
371 
372  /**
373  * @return a vector with all vectors / sets of values of this set-element
374  * @see liFibSets
375  */
376  const vector< cVectorFibSet > getVectors();
377 
378  /**
379  * This method sets all vectors / sets of values of this set-element to
380  * the given vectors.
381  *
382  * @see liFibSets
383  * @param vecSets a vector with all vectors / sets of values this
384  * set-element should contain
385  * @return true if the vectors wher set, else false and the vectors of
386  * this set-element unchanged
387  */
388  bool setVectors( const vector< cVectorFibSet > & vecSets );
389 
390  /**
391  * This method returns a pointer to the uiPosition'th vector of this
392  * set-element.
393  *
394  * @see liFibSets
395  * @param uiPosition the number of the vector to return (counting begins
396  * with 1)
397  * @return a pointer to the uiPosition'th vector, or NULL if non such exists
398  */
399  cVectorFibSet * getVector( const unsignedLongFib uiPosition );
400 
401  /**
402  * This method sets the uiPosition'th vector of this set-element to the
403  * given vector.
404  *
405  * @see liFibSets
406  * @param vecSet the vector to set
407  * @param uiPosition the position wher the to set vector should stand
408  * in this set-element (counting begins with 1)
409  * @return true if the vector wher set, else false and the vectors of
410  * this set-element unchanged
411  */
412  bool setVector( const cVectorFibSet & vecSet, const unsignedLongFib uiPosition );
413 
414  /**
415  * This method adds the given vector to the existing vectors.
416  *
417  * @see liSubFibSets
418  * @param vecSet a reference to the to add vector
419  * @param uiPosition the position wher the vecSet should be added
420  * (counting begins with 1); if 0 the vecSet or greater than the number
421  * of vectors the vector will be added to the end of the vector list
422  * @return true if the vecSet was added, else false
423  */
424  bool addVector( const cVectorFibSet & vecSet, const unsignedLongFib uiPosition=0 );
425 
426  /**
427  * This method deletes the uiPosition'th vector from the existing vectors.
428  *
429  * @param uiPosition the position, wher the vector should be deleted from
430  * (counting begins with 1)
431  * @return true if the vector was deleted, else false
432  */
433  bool deleteVector( const unsignedLongFib uiPosition );
434 
435 
436 protected:
437 
438  /**
439  * This method stores this Fib object in the compressed Fib-format
440  * into the given stream.
441  * It is needed because the stream can yust store byts but the size of
442  * Fib elements can be any number of bits. Because of that ther have to
443  * be a possibility to exchange the missing bits betwean the Fib elements.
444  *
445  * @see store
446  * @param stream the stream where this Fib object should be stored to
447  * @param cRestBits the not yet writen bits which should be stored
448  * @param uiRestBitPosition the number of bits in the cRestBits which
449  * should be writen respectively containing valid information
450  * @return true if this Fib object is stored, else false
451  */
452  virtual bool storeBit( ostream & stream, char & cRestBits,
453  unsigned char & uiRestBitPosition ) const;
454 
455  /**
456  * This method sets the each variable, which is defined above a leaf,
457  * to an uniqe integer number greater than the given number
458  * uiLastVariableNumber. While storing this number can be stored to
459  * identify the variable.
460  *
461  * @param uiLastVariableNumber the number which was last use, this
462  * means also is the greatest used, in this limb.
463  * @return the number which was last use, this
464  * means also is the greatest used, in this limb
465  * from the method
466  */
468  unsignedIntFib uiLastVariableNumber = 0 );
469 
470  /**
471  * This method copies the connected object with the given number in the
472  * order of connected objects.
473  * For this every Fib element, beginning from this Fib element, that
474  * is part of the connected object will be copied.
475  * Variables which are not defined in the connected object but used
476  * don't change ther reference.
477  * It is an help method for the copy method. It dosn't update the
478  * structural information of the created Fib object.
479  *
480  * @param iObjectPoint the number of the connected object to copy;
481  * the standartvalue is 0 for coping the complet actual object
482  * @return the copy of the connected object or NULL if non such exists
483  */
484  virtual cFibElement *copyInternal( const unsignedIntFib iObjectPoint=0 ) const;
485 
486  /**
487  * This method checks if the given variable is defined in the given
488  * direction from this Fib element.
489  * This is for intern use to get the correct data from
490  * isDefinedVariable() without pCallingFibElement.
491  *
492  * @see cFibVariable
493  * @see isUsedVariable()
494  * @param pVariable the variable to check if it is defined
495  * @param direction the direction from this Fib element, in which the
496  * variable should be defined; standardvalue is ED_POSITION so yust
497  * this Fib element will be checked
498  * @param pCallingFibElement the Fib-Element which called this method
499  * @return true if the variable is used, else false
500  */
501  virtual bool isDefinedVariableInternal( const cFibVariable * pVariable,
502  edDirection direction = ED_POSITION,
503  const cFibElement * pCallingFibElement = NULL ) const;
504 
505  /**
506  * This method returns all variables defined in the given direction from
507  * this Fib element.
508  * This is for intern use to get the correct data from
509  * getDefinedVariables() without pCallingFibElement.
510  *
511  * @see cFibVariable
512  * @see getUsedVariables()
513  * @see isDefinedVariable()
514  * @param direction the direction from this Fib element, in which the
515  * variable should be used; standardvalue is ED_POSITION so yust
516  * this Fib element will be checked
517  * @param pCallingFibElement the Fib-Element which called this method
518  * @return the set with all variables used in the given direction from
519  * this Fib element
520  */
521  virtual list< cFibVariable* > getDefinedVariablesInternal(
522  edDirection direction = ED_HIGHER,
523  const cFibElement * pCallingFibElement = NULL );
524 
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 are not 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 element,
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 pVariableOwn a pointer to a defined variable in this Fib element,
598  * it is compared to the equivalent variable pVariable in the given
599  * Fib element fibElement
600  * @param fibElement the Fib element, to which this Fib element should be
601  * compared
602  * @param pVariable 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 * pVariableOwn,
625  const cFibElement & fibElement,
626  const cFibVariable * pVariable,
627  map< const cRoot *, const cRoot * > & setEqualRootObjects,
628  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
629  const bool bCheckExternalObjects ) const;
630 
631 
632 };
633 }//namespace fib
634 
635 #endif //___C_FIB_SET_H__
636 
637 
638 
639 
640 
641