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
cFunctionValue.h
Go to the documentation of this file.
1 /**
2  * @class cFunctionValue
3  * file name: cFunctionValue.h
4  * @author Betti Oesterholz
5  * @date 23.04.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a value underfunction.
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 a value underfunction.
28  * Value underfunction store a fixted /constant value.
29  *
30  */
31 /*
32 History:
33 23.04.2010 Oesterholz created
34 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
35 */
36 
37 #ifndef ___C_FUNCTION_VALUE_H__
38 #define ___C_FUNCTION_VALUE_H__
39 
40 
41 #include "version.h"
42 #include "fibDatatyps.h"
43 #include "cReadBits.h"
44 
45 #include "cUnderFunction.h"
46 
47 
48 using std::set;
49 
50 namespace fib{
51 
52 
54 
55 protected:
56 
57  /**
58  * The value of this underfunction.
59  */
61 
62 public:
63 
64 
65  /**
66  * The constructor of the underfunction.
67  *
68  * @param dInValue the value of this underfunction
69  * @param pInSuperiorFunction the underfunction which contains the
70  * new underfunction
71  * @param pInDefiningFibElement the fib -element which defines/ uses
72  * the new underfunction
73  */
74  cFunctionValue( doubleFib dInValue, cUnderFunction * pInSuperiorFunction = NULL,
75  cFibElement * pInDefiningFibElement = NULL );
76 
77  /**
78  * The copy constructor of the underfunction.
79  *
80  * @param underfunction the underfunction which to copy
81  * @param pInSuperiorFunction the underfunction which contains the
82  * new underfunction
83  * @param pInDefiningFibElement the fib -element which defines/ uses
84  * the new underfunction
85  */
86  cFunctionValue( const cFunctionValue & underfunction,
87  cUnderFunction * pInSuperiorFunction = NULL,
88  cFibElement *pInDefiningFibElement = NULL );
89 
90  /**
91  * The constructor for restoring a value underfunction from an TinyXml element.
92  * Beware: The bits for the functiontype should be allready readed, this
93  * constructor reads yust the two underfunctions.
94  *
95  * @param pXmlNode a pointer to the TinyXml node the underfunction is stored in
96  * @param outStatus An reference to an integervalue where the errorvalue
97  * can be stored to.
98  * possible errorvalues are:
99  * - 0 loading successful
100  * - -1 loading error, invalid pXmlElement
101  * - -2 loading error, invalid data in pXmlElement
102  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
103  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
104  * object is wrong
105  * @param pInSuperiorFunction the underfunction which contains the
106  * new underfunction
107  * @param pInDefiningFibElement the fib -element which defines/ uses
108  * the new underfunction
109  */
110  cFunctionValue( const TiXmlElement * pXmlElement, intFib & outStatus,
111  cUnderFunction * pInSuperiorFunction = NULL,
112  cFibElement * pInDefiningFibElement = NULL );
113 
114  /**
115  * This constructor restores a value underfunction from the stream
116  * where it is stored in the compressed fib -format.
117  *
118  * @param iBitStream the stream where this underfunction is stored to in,
119  * because this stream is an cReadBits, any number of bits can be
120  * readed from it
121  * @param outStatus An reference to an integervalue where the errorvalue
122  * can be stored to. If the pointer is NULL no errorvalue will be
123  * given back.
124  * possible errorvalues are:
125  * - 0 loading successful
126  * - -1 loading error, invalid stream
127  * - -2 loading error, invalid data in stream
128  * - 1 loading warning, invalid data in stream, error could be corrected
129  * - 2 loading warning, invalid data in stream, maybe the loaded
130  * object is wrong
131  * @param pInValueDomain the domain for value underfunctions
132  * @param pInSuperiorFunction the underfunction which contains the
133  * new underfunction
134  * @param pInDefiningFibElement the fib -element which defines/ uses
135  * the new underfunction
136  */
137  cFunctionValue( cReadBits & iBitStream, intFib & outStatus,
138  const cDomainSingle * pInValueDomain,
139  cUnderFunction * pInSuperiorFunction = NULL,
140  cFibElement * pInDefiningFibElement = NULL );
141 
142 
143  /**
144  * The destructor of the underfunction.
145  */
146  virtual ~cFunctionValue();
147 
148  /**
149  * This method returns if this underfunction is valid, else false.
150  * All values in the underfunction and it's underfunctions must be
151  * inside the underfunction domain. All variables must be defined over
152  * this underfunction.
153  * No underfunction should contain itselfor should be contained in one
154  * of its underfunctions (no cycles allowed).
155  *
156  * @return true if this underfunction is valid, else false
157  */
158  virtual bool isValid() const;
159 
160  /**
161  * This method checks if the given variable is used in this underfunction.
162  *
163  * @see cFibVariable
164  * @param variable the variable to check if it is used
165  * @return true if the variable is used, else false
166  */
167  virtual bool isUsedVariable( const cFibVariable * variable ) const;
168 
169  /**
170  * This method returns all variables used in this underfunction.
171  *
172  * @see cFibVariable
173  * @return all variables used in this underfunction
174  */
175  virtual set<cFibVariable*> getUsedVariables();
176 
177  /**
178  * This method replace the variable variableOld with the variable
179  * variableNew in the underfunction.
180  *
181  * @see cFibVariable
182  * @see isVariable()
183  * @see isUsedVariable()
184  * @param variableOld the variable to replace
185  * @param variableNew the variable with which the variable variableOld
186  * is to replace
187  * @return true if the variable variableOld is replaced with variableNew,
188  * else false
189  */
190  virtual bool replaceVariable( cFibVariable *variableOld,
191  cFibVariable *variableNew );
192 
193  /**
194  * Returns the value of the underfunction or 0 if non such exists.
195  *
196  * @return the value of the underfunction or 0 if non
197  * such exists
198  */
199  virtual doubleFib getValue() const;
200 
201  /**
202  * @return the number of underfunctions, a underfunction of this type has
203  */
205 
206  /**
207  * Sets the Fib -element which defines/ uses this underfunction.
208  * If the given pointer is the nullpointer (standardvalue), no
209  * Fib -element defines this underfunction.
210  *
211  * @param definingFibElement a pointer to the Fib -element which
212  * defines/ uses this underfunction
213  * @param bCheckDomains getthe domains of the defining element and
214  * check the underfunctionelements with it
215  */
216  virtual void setDefiningFibElement( cFibElement *fibElement=NULL,
217  bool bCheckDomains=true );
218 
219  /**
220  * This method evaluades a value for the time needed to evalue the
221  * underfunction.
222  * This value should not exceed lMaxTime, if the value for the time
223  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
224  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
225  * stoped, this is the standard case.
226  *
227  * @see cFibElement::evalueObject()
228  * @param lMaxTime the maximum time for the evaluation, the returned
229  * exceed this value; the value 0 stands for infinity, so the
230  * evaluation won't be stoped
231  * @return a value for the time needed to evalue this underfunction
232  */
233  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
234 
235  /**
236  * This method evaluades the size of the Fib -object in bits in the
237  * compressed file form.
238  * The optionalpart field of point -elements will be ignored.
239  *
240  * @see store()
241  * @return the size of the Fib -object in bits in the compressed form
242  */
243  virtual unsignedLongFib getCompressedSize() const;
244 
245  /**
246  * This method stores this Fib -object in the compressed Fib -format
247  * into the given stream.
248  * It is needed becouse the stream can yust store byts but the size of
249  * fib -elements can be any number of bits. Because of that ther have to
250  * be a possibility to exchange the missing bits betwean the fib -elements.
251  *
252  * @see store
253  * @param stream the stream where this Fib -object should be stored to
254  * @param cRestBits the not yet writen bits which should be stored
255  * @param uiRestBitPosition the number of bits in the cRestBits which
256  * should be writen respectively containing valid information
257  * @return true if this Fib -object is stored, else false
258  */
259  virtual bool store( ostream & stream, char & cRestBits,
260  unsigned char & uiRestBitPosition ) const;
261 
262  /**
263  * This method stores this underfunction in the XML -format into the
264  * given stream.
265  * Variables should have ther number as ther value.
266  *
267  * @param stream the stream where this underfunctionshould be
268  * stored to
269  * @return true if this underfunction is stored, else false
270  */
271  virtual bool storeXml( ostream &stream ) const;
272 
273  /**
274  * @return the type for the underfunction
275  */
276  virtual unsignedIntFib getType() const;
277 
278  /**
279  * @return the name for the underfunction
280  */
281  virtual string getUnderFunctionName() const;
282 
283 #ifndef FEATURE_EQUAL_FIB_OBJECT
284  /**
285  * This Method checks if the given underfunction is equal to this underfunction.
286  *
287  * @param underfunction the underfunction to compare with this underfunction
288  * @return true if the given underfunction is equal to this underfunction, else false
289  */
290  virtual bool equal( const cUnderFunction & underfunction ) const;
291 
292 #endif //FEATURE_EQUAL_FIB_OBJECT
293 
294  /**
295  * This method duplicates this whole underfunction.
296  * Underfunctions of this underfunction are also cloned.
297  *
298  * @param pSuperiorUnderFunction the underfunction which contains
299  * @param pInDefiningFibElement the Fib -element which defines/ uses
300  * @return the cloned/ duplicated underfunction
301  */
302  virtual cUnderFunction * clone(
303  cUnderFunction * pInSuperiorUnderFunction = NULL,
304  cFibElement *pInDefiningFibElement = NULL) const;
305 
306 
307 protected:
308 
309 #ifdef FEATURE_EQUAL_FIB_OBJECT
310 
311  /**
312  * This method checks if the given underfunction is equal to this underfunction.
313  * Variables can be others, but must be defined and used in equivalent
314  * Fib-elements.
315  *
316  * @param underfunction the underfunction to compare with this underfunction
317  * @param mapEqualRootObjects the root objects of this object that wher
318  * already checked as equal
319  * map entries:
320  * key: the root-element of this Fib object that was checked
321  * value: the to the key correspondending root-element of the
322  * fibObject that was checked and which is equal to the key
323  * root-element
324  * (it is empty if bCheckExternalObjects == false)
325  * @param mapEqualDefinedVariables the Fib elements that defines
326  * variables and are equal;
327  * map entries:
328  * key: the Fib element of this Fib object that was checked
329  * value: the to the key correspondending Fib element of the
330  * fibObject that was checked and which sets its defined
331  * variables to the same values as the key Fib element
332  * @param bCheckExternalObjects if true the external objects of
333  * cExtObject will be compared
334  * @return true if this Fib-object is equal to the given Fib-object,
335  * else false
336  */
337  virtual bool equalInternal( const cUnderFunction & underfunction,
338  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
339  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
340  const bool bCheckExternalObjects ) const;
341 
342 #endif //FEATURE_EQUAL_FIB_OBJECT
343 
344 };//end class cFunctionValue
345 
346 
347 }//end namespace fib
348 
349 #endif