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