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