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