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