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
cFibVector.h
Go to the documentation of this file.
1 /**
2  * @class cFibVector
3  * file name: cFibVector.h
4  * @author Betti Oesterholz
5  * @date 02.05.2009
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a basic Fib-vector.
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 file contains the basisclass of all Fib-vectors. It's not
28  * possible to create instances from this class.
29  * Thes vectors are used in Fib-elements. A vector contains a fixed
30  * number of elements. Every element is an value or an Fib-Variable.
31  *
32  */
33 /*
34 History:
35 17.04.2009 Oesterholz created
36 05.07.2010 Oesterholz lowerVector() moved her from cEvaluePositionList
37  and operator<() added
38 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
39 03.12.2011 Oesterholz changes for cDomainVectorOpenEnd (store + restore
40  of more elements than in the domain)
41 11.12.2011 Oesterholz getCompressedSize() and store() method with
42  parameters for domains added
43 02.01.2011 Oesterholz cFibMatrix added
44 */
45 
46 #ifndef ___C_FIB_VECTOR_H__
47 #define ___C_FIB_VECTOR_H__
48 
49 
50 #include "version.h"
51 #include "fibDatatyps.h"
52 #include "cReadBits.h"
53 
54 #include "cFibVariable.h"
55 #include "cTypeElement.h"
56 #include "cDomainSingle.h"
57 
58 #include "tinyxml.h"
59 
60 #include <vector>
61 #include <list>
62 #include <map>
63 #include <sstream>
64 #include <ostream>
65 #include <istream>
66 
67 
68 using std::vector;
69 
70 namespace fib{
71 
72 
73 class cFibElement;//cyclic dependencie
74 class cDomainVectorBasis;//cyclic dependencie
75 
76 
77 class cFibVector: public iVariableUser{
78 
79 friend class cDomainVector;
80 friend class cDomainVectorOpenEnd;
81 friend class cArea;
82 friend class cProperty;
83 friend class cPoint;
84 friend class cExtObject;
85 friend class cExtSubobject;
86 friend class cFibSet;
87 friend class cFibMatrix;
88 
89 protected:
90 
91  /**
92  * the type fore the type of the vectorelements
93  */
97  };
98  /**
99  * the vector with the type of the vectorelements
100  */
101  vector<eVectorType> liVectorType;
102 
103  /**
104  * the vector with the values of the vectorelements
105  */
106  vector<doubleFib> liVectorValues;
107 
108  /**
109  * the vector with the variables of the vectorelements
110  */
111  vector<cFibVariable*> liVectorVariable;
112 
113  /**
114  * the Fib-element which defines/ uses the vector
115  */
117 
118 
119 protected:
120 
121 
122  /**
123  * The constructor of the vector.
124  *
125  * @param iNumberOfVectorElements number of elements in the vector
126  * @param definingFibElement the Fib-element which defines/ uses
127  * the new vector
128  */
129  cFibVector( unsignedIntFib iNumberOfVectorElements = 1,
130  cFibElement * definingFibElement = NULL );
131 
132  /**
133  * The copy constructor of the vector.
134  *
135  * @param vector the vector from which to copy the data
136  * @param definingFibElement the Fib-element which defines/ uses
137  * the new vector
138  */
139  cFibVector( const cFibVector & vector,
140  cFibElement *definingFibElement = NULL );
141 
142  /**
143  * The constructor for restoring a vector from an TinyXml element.
144  *
145  * @param pXmlNode a pointer to the TinyXml node the vector is stored in
146  * @param outStatus An reference to an integervalue where the errorvalue
147  * can be stored to.
148  * possible errorvalues are:
149  * - 0 loading successful
150  * - -1 loading error, invalid pXmlElement
151  * - -2 loading error, invalid data in pXmlElement
152  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
153  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
154  * object is wrong
155  * @param liDefinedVariables a list with the defined variables for the
156  * to restore vector, every variable should have it's number
157  * (the number under which it is stored) as it's value
158  */
159  cFibVector( const TiXmlElement * pXmlElement, intFib &outStatus,
160  list<cFibVariable*> & liDefinedVariables );
161 
162  /**
163  * This constructor restores a poisitionsvector from the stream where it is
164  * stored in the compressed Fib-format.
165  *
166  * @param iBitStream the stream where this vector is stored to in,
167  * because this stream is an cReadBits, any number of bits can be
168  * readed from it
169  * @param outStatus An reference to an integervalue where the errorvalue
170  * can be stored to. If the pointer is NULL no errorvalue will be
171  * given back.
172  * possible errorvalues are:
173  * - 0 loading successful
174  * - -1 loading error, invalid stream
175  * - -2 loading error, invalid data in stream
176  * - 1 loading warning, invalid data in stream, error could be corrected
177  * - 2 loading warning, invalid data in stream, maybe the loaded
178  * object is wrong
179  * @param liDefinedVariables a list with the defined variables for the
180  * to restore vector, every variable should have it's number
181  * (the number under which it is stored) as it's value
182  * @param pInVectorDomain the domain for this vector
183  * @param pInDomainVariable the domain for variables
184  * @param uiInNumberOfElements the number of elements to restore,
185  * if not given or 0, it will be evalued by the number of elements of
186  * the given domain pInVectorDomain
187  */
188  cFibVector( cReadBits & iBitStream, intFib & outStatus,
189  list<cFibVariable*> & liDefinedVariables,
190  const cDomain * pInVectorDomain, const cDomain * pInDomainVariable,
191  const unsignedIntFib uiInNumberOfElements = 0 );
192 
193  /**
194  * This method creates an instance of this vector type.
195  *
196  * @param iNumberOfVectorElements number of elements in the vector
197  * @param definingFibElement the Fib-element which defines/ uses
198  * the vector
199  */
200  virtual cFibVector * createInstance(
201  unsignedIntFib iNumberOfVectorElements=1,
202  cFibElement *definingFibElement=NULL ) const = 0;
203 
204 public:
205 
206  /**
207  * The destructor of the vector.
208  */
209  virtual ~cFibVector();
210 
211  /**
212  * Returns the number of elements the vector contains.
213  *
214  * @return the number of elements the vector contains
215  */
217 
218 
219  /**
220  * Returns if the iNumberElement'te vectorelement is an variable.
221  *
222  * @param iNumberElement the number of the element, for which is to
223  * check if it is an variable
224  * @return true if the iNumberElement'te vectorelement is an variable,
225  * else false
226  */
227  virtual bool isVariable( unsignedIntFib iNumberElement ) const;
228 
229  /**
230  * This method checks if the given variable is used in this vector.
231  *
232  * @see cFibVariable
233  * @param variable the variable to check if it is used
234  * @return true if the variable is used, else false
235  */
236  virtual bool isUsedVariable( const cFibVariable *variable ) const;
237 
238  /**
239  * This method returns all variables used in this vector.
240  *
241  * @see cFibVariable
242  * @return all variables used in this vector
243  */
244  virtual set<cFibVariable*> getUsedVariables();
245 
246  /**
247  * This method replace the variable variableOld with the variable
248  * variableNew in the vector.
249  *
250  * @see cFibVariable
251  * @see isVariable()
252  * @see isUsedVariable()
253  * @param variableOld the variable to replace
254  * @param variableNew the variable with which the variable variableOld
255  * is to replace
256  * @return true if the variable variableOld is replaced with variableNew,
257  * else false
258  */
259  virtual bool replaceVariable( cFibVariable *variableOld,
260  cFibVariable *variableNew );
261 
262  /**
263  * Returns the value of the iNumberElement'te vectorelement or
264  * Nullvalue if non such exists.
265  *
266  * @param iNumberElement the number of the element, which value is to
267  * return
268  * @return the value of the iNumberElement'te vectorelement or 0 if non
269  * such exists
270  */
271  virtual doubleFib getValue( unsignedIntFib iNumberElement ) const;
272 
273 
274  /**
275  * Sets the value of the iNumberElement'te vectorelement.
276  *
277  * @param iNumberElement the number of the element, which value is to
278  * set
279  * @param dValue the value to set
280  * @return true if the iNumberElement'te vectorelement is set to the
281  * given value dValue, else false
282  */
283  virtual bool setValue( unsignedIntFib iNumberElement, doubleFib dValue );
284 
285 
286  /**
287  * Returns the variable of the iNumberElement'te vectorelement or the
288  * Nullpointer NULL, if the iNumberElement'te vectorelement isn't an
289  * variable.
290  *
291  * @param iNumberElement the number of the element, which variable is
292  * to return
293  * @return the variable of the iNumberElement'te vectorelement or the
294  * Nullpointer NULL, if the iNumberElement'te vectorelement isn't an
295  * variable.
296  */
297  virtual cFibVariable * getVariable( unsignedIntFib iNumberElement );
298 
299 
300  /**
301  * Sets the variable of the iNumberElement'te vectorelement.
302  *
303  * @param iNumberElement the number of the element, where the variable is
304  * to set
305  * @param pVariable the variable to set
306  * @return true if the iNumberElement'te vectorelement is set to the
307  * given variable pVariable, else false
308  */
309  virtual bool setVariable( unsignedIntFib iNumberElement, cFibVariable *pVariable );
310 
311 
312  /**
313  * Returns the type of the vector.
314  * You have to delete the returned object after usage.
315  *
316  * @return the type of the vector
317  */
318  virtual cTypeElement * getElementType() const = 0;
319 
320 
321  /**
322  * Returns a reference to the domain of the vector or
323  * the nullpointer NULL if no domain is defined for the vector.
324  * If the nullpointer NULL is returned the standarddomain is valid for the
325  * vector.
326  *
327  * @return a reference to the vectordomain of the vector
328  */
329  virtual cDomainVectorBasis * getDomain() const;
330 
331  /**
332  * Returns a reference to the value domain of the vector or
333  * the nullpointer NULL if no value domain is defined for the vector.
334  * If the nullpointer NULL is returned the standarddomain is valid for the
335  * vector.
336  *
337  * @return a reference to the definitionarea of the vector
338  */
339  virtual cDomainVectorBasis * getValueDomain() const;
340 
341 
342  /**
343  * Returns a reference to the domain the iNumberElement'te
344  * vectorelement or the nullpointer NULL if non exists.
345  *
346  * @param iNumberElement the number of the element, which
347  * definitionarea is to return
348  * @return a reference to the definitionarea of the iNumberElement'te
349  * vectorelement
350  */
351  virtual cDomain * getDomain( unsignedIntFib iNumberElement ) const;
352 
353  /**
354  * Returns a reference to the standard domain of the vector.
355  * You have to delete the returned object after usage.
356  *
357  * @return a reference to the standard domain of the vector
358  */
359  virtual cDomainVectorBasis * getStandardDomain() const;
360 
361  /**
362  * Returns a reference to the domain for variables of the vector.
363  * You have to delete the returned object after usage.
364  *
365  * @return a reference to the domain for variables of the vector
366  */
367  virtual cDomainSingle * getVariableDomain() const;
368 
369  /**
370  * @return the Fib-element which defines/ uses this vector or
371  * a Nullpointer NULL if non such Fib-element exists
372  */
374 
375 
376  /**
377  * Sets the Fib-element which defines/ uses this vector.
378  * If the given pointer is the nullpointer (standardvalue), no
379  * Fib-element defines this vector.
380  *
381  * @param definingFibElement a pointer to the Fib-element which
382  * defines/ uses this vector
383  * @param bCheckDomains getthe domains of the defining element and
384  * check the vectorelements with it
385  */
386  virtual void setDefiningFibElement( cFibElement *fibElement=NULL,
387  bool bCheckDomains=true );
388 
389  /**
390  * This method evaluades the size of the Fib-object in bits in the
391  * compressed file form.
392  *
393  * @see store()
394  * @return the size of the Fib-object in bits in the compressed form
395  */
396  virtual unsignedLongFib getCompressedSize() const;
397 
398  /**
399  * This method evaluades the size of the Fib-object in bits in the
400  * compressed file form.
401  *
402  * @see store()
403  * @param valueVectorDomain the domain for this vector
404  * @param variableDomain the domain for variables
405  * @return the size of the Fib-object in bits in the compressed form
406  */
408  const cDomainVectorBasis & valueVectorDomain,
409  const cDomainSingle & variableDomain ) const;
410 
411  /**
412  * This method stores this Fib-object in the compressed Fib-format
413  * into the given stream.
414  * It is needed becouse the stream can yust store byts but the size of
415  * Fib-elements can be any number of bits. Because of that ther have to
416  * be a possibility to exchange the missing bits betwean the Fib-elements.
417  *
418  * @see store
419  * @param stream the stream where this Fib-object should be stored to
420  * @param cRestBits the not yet writen bits which should be stored
421  * @param uiRestBitPosition the number of bits in the cRestBits which
422  * should be writen respectively containing valid information
423  * @return true if this Fib-object is stored, else false
424  */
425  virtual bool store( ostream & stream, char & cRestBits,
426  unsigned char & uiRestBitPosition ) const;
427 
428  /**
429  * This method stores this Fib-object in the compressed Fib-format
430  * into the given stream.
431  * It is needed becouse the stream can yust store byts but the size of
432  * Fib-elements can be any number of bits. Because of that ther have to
433  * be a possibility to exchange the missing bits betwean the Fib-elements.
434  *
435  * @see store
436  * @param stream the stream where this Fib-object should be stored to
437  * @param cRestBits the not yet writen bits which should be stored
438  * @param uiRestBitPosition the number of bits in the cRestBits which
439  * should be writen respectively containing valid information
440  * @param valueVectorDomain the domain for this vector
441  * @param variableDomain the domain for variables
442  * @return true if this Fib-object is stored, else false
443  */
444  virtual bool store( ostream & stream, char & cRestBits,
445  unsigned char & uiRestBitPosition,
446  const cDomainVectorBasis & valueVectorDomain,
447  const cDomainSingle & variableDomain ) const;
448 
449  /**
450  * This method stores this vector in the XML -format into the
451  * given stream.
452  * Variables should have ther number as ther value.
453  *
454  * @param stream the stream where this vectorshould be
455  * stored to
456  * @return true if this vector is stored, else false
457  */
458  virtual bool storeXml( ostream &stream ) const;
459 
460  /**
461  * @return the name for the type of the vector
462  */
463  virtual string getVectorType() const = 0;
464 
465 #ifdef FEATURE_EQUAL_FIB_OBJECT
466 
467  /**
468  * This Method checks if the given vector is equal to this vector.
469  *
470  * @param vector the vector to compare with this vector
471  * @param bCheckExternalObjects if true the external objects of
472  * cExtObject will be compared
473  * @return true if the given vector is equal to this vector, else false
474  */
475  virtual bool equal( const cFibVector &vector,
476  const bool bCheckExternalObjects=true ) const;
477 
478 #else //FEATURE_EQUAL_FIB_OBJECT
479 
480  /**
481  * This Method checks if the given vector is equal to this vector.
482  *
483  * @param vector the vector to compare with this vector
484  * @return true if the given vector is equal to this vector, else false
485  */
486  virtual bool equal( const cFibVector &vector ) const;
487 
488 #endif //FEATURE_EQUAL_FIB_OBJECT
489 
490  /**
491  * This Method checks if the given vector is equal to this vector.
492  *
493  * @param vector the vector to compare with this vector
494  * @return true if the given vector is equal to this vector, else false
495  */
496  virtual bool operator==( const cFibVector &vector ) const;
497 
498  /**
499  * This Method checks if the given vector is not equal to this vector.
500  *
501  * @param vector the vector to compare with this vector
502  * @return true if the given vector is not equal to this vector, else false
503  */
504  bool operator!=( const cFibVector &vector ) const;
505 
506  /**
507  * This Method makes this vectorelements equal to the correspondending
508  * vectorelements of the given vector.
509  * The type of the vector won't be changed.
510  *
511  * @param vector the vector to copy
512  */
513  virtual cFibVector & operator=( const cFibVector &vector );
514 
515  /**
516  * This function compares on lower this vector with the given Fib-vector.
517  * A vector is lower, if it has less elements than the other vector or
518  * it's i'th element is lower and all j'th elements with i > j are equal.
519  *
520  * @see lowerVector()
521  * @param vector the vector to compare
522  * @return true if this vector is lower than that of vector, else false
523  */
524  virtual bool operator<( const cFibVector & vector ) const;
525 
526  /**
527  * This function compares two Fib-vectors.
528  * A vector is lower, if it has less elements than the other vector or
529  * it's i'th element is lower and all j'th elements with i > j are equal.
530  *
531  * @param vector1 the first vector to compare
532  * @param vector2 the second vector to compare
533  * @return true if the vector1 is lower than that of vector2, else false
534  */
535  static bool lowerVector( const cFibVector & vector1, const cFibVector & vector2 );
536 
537 
538 protected:
539 
540  /**
541  * @return the Fib-element which uses the variables of this element
542  */
543  virtual cFibElement * getVariableUsingFibElement() const;
544 
545  /**
546  * This method deletes all occurenc of the given variable from this
547  * element. So the variable is not used anymore of this element.
548  * Beware: This element has to be unregisterd (call
549  * unregisterUsingElement() ) at the pVariable seperatly. Do this directly
550  * befor or after calling this method.
551  *
552  * @param pVariable the variable which is to delete from this element
553  * @return true if the variable dosn't occure anymore in this element,
554  * else false
555  */
556  virtual bool deleteVariable( cFibVariable * pVariable );
557 
558 #ifdef FEATURE_EQUAL_FIB_OBJECT
559 
560  /**
561  * This Method checks if the given variable is equal to this variable.
562  *
563  * @param vector the vector to compare with this vector
564  * @param mapEqualRootObjects the root objects of this object that wher
565  * already checked as equal
566  * map entries:
567  * key: the root-element of this Fib object that was checked
568  * value: the to the key correspondending root-element of the
569  * fibObject that was checked and which is equal to the key
570  * root-element
571  * (it is empty if bCheckExternalObjects == false)
572  * @param mapEqualDefinedVariables the Fib elements that defines
573  * variables and are equal;
574  * map entries:
575  * key: the Fib element of this Fib object that was checked
576  * value: the to the key correspondending Fib element of the
577  * fibObject that was checked and which sets its defined
578  * variables to the same values as the key Fib element
579  * @param bCheckExternalObjects if true the external objects of
580  * cExtObject will be compared
581  * @return true if the given variable is equal to this variable, else false
582  */
583  virtual bool equalInternal( const cFibVector &vector,
584  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
585  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
586  const bool bCheckExternalObjects ) const;
587 
588 #endif //FEATURE_EQUAL_FIB_OBJECT
589 
590 };//end class cFibVector
591 
592 
593 }//end namespace fib
594 
595 #endif