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
cConditionComparison.h
Go to the documentation of this file.
1 /**
2  * @class cConditionComparison
3  * file name: cConditionComparison.h
4  * @author Betti Oesterholz
5  * @date 15.05.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a abstract condition for comparing numbers.
11  * Copyright (C) @c LGPL3 2011 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 abstract condition with two subfunctions, which
28  * values will be compared with this condition.
29  *
30  */
31 /*
32 History:
33 15.05.2011 Oesterholz created
34 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
35 */
36 
37 #ifndef ___C_CONDITION_COMPARISON_H__
38 #define ___C_CONDITION_COMPARISON_H__
39 
40 
41 #include "version.h"
42 #include "fibDatatyps.h"
43 #include "cReadBits.h"
44 
45 #include "cCondition.h"
46 
47 #include "cUnderFunction.h"
48 
49 
50 using std::set;
51 
52 namespace fib{
53 
54 
56 protected:
57  /**
58  * The first function this condition contains.
59  */
61 
62  /**
63  * The second function this condition contains.
64  */
66 
67 public:
68 
69 
70  /**
71  * The constructor of the two value condition.
72  *
73  * @param pInFirstSubFunction a pointer to the first function, this condition
74  * contains; Beware: It (pSubFunction) won't be copied.
75  * @see pFirstSubFunction
76  * @param pInSecondSubFunction a pointer to the second function, this
77  * condition contains; Beware: It (pSubFunction) won't be copied.
78  * @see pSecondSubFunction
79  * @param pInSuperiorCondition the condition which contains the
80  * new condition
81  * @param pInDefiningFibElement the Fib-element which defines/ uses
82  * the new condition
83  */
84  cConditionComparison( cUnderFunction * pInFirstSubFunction,
85  cUnderFunction * pInSecondSubFunction,
86  cCondition * pInSuperiorCondition = NULL,
87  cFibElement * pInDefiningFibElement = NULL );
88 
89  /**
90  * The constructor of the two value condition.
91  *
92  * @param inFirstSubFunction the first function, this condition contains
93  * @see pFirstSubFunction
94  * @param inSecondSubFunction the second function, this condition contains
95  * @see pSecondSubFunction
96  * @param pInSuperiorCondition the condition which contains the
97  * new condition
98  * @param pInDefiningFibElement the Fib-element which defines/ uses
99  * the new condition
100  */
101  cConditionComparison( const cUnderFunction & inFirstSubFunction,
102  const cUnderFunction & inSecondSubFunction,
103  cCondition * pInSuperiorCondition = NULL,
104  cFibElement * pInDefiningFibElement = NULL );
105 
106  /**
107  * The copy constructor of the condition.
108  * This constructor will also copy the subconditions of the given
109  * condition.
110  *
111  * @param condition the condition which to copy
112  * @param pInSuperiorCondition the condition which contains the
113  * new condition
114  * @param pInDefiningFibElement the Fib-element which defines/ uses
115  * the new condition
116  */
117  cConditionComparison( const cConditionComparison & condition,
118  cCondition * pInSuperiorCondition = NULL,
119  cFibElement *pInDefiningFibElement = NULL );
120 
121 
122  /**
123  * The destructor of the condition.
124  */
125  virtual ~cConditionComparison();
126 
127  /**
128  * This method returns if this condition is valid, else false.
129  * All subcondition and underfunctions must be valid.
130  * No condition should contain itself or should be contained in one
131  * of its condition (no cycles allowed).
132  *
133  * @return true if this condition is valid, else false
134  */
135  virtual bool isValid() const;
136 
137  /**
138  * This method checks if the given variable is used in this condition.
139  *
140  * @see cFibVariable
141  * @param variable the variable to check if it is used
142  * @return true if the variable is used, else false
143  */
144  virtual bool isUsedVariable( const cFibVariable * variable ) const;
145 
146  /**
147  * This method returns all variables used in this condition.
148  *
149  * @see cFibVariable
150  * @return all variables used in this condition
151  */
152  virtual set<cFibVariable*> getUsedVariables();
153 
154  /**
155  * This method replace the variable variableOld with the variable
156  * variableNew in the condition.
157  *
158  * @see cFibVariable
159  * @see isVariable()
160  * @see isUsedVariable()
161  * @param variableOld the variable to replace
162  * @param variableNew the variable with which the variable variableOld
163  * is to replace
164  * @return true if the variable variableOld is replaced with variableNew,
165  * else false
166  */
167  virtual bool replaceVariable( cFibVariable * variableOld,
168  cFibVariable * variableNew );
169 
170  /**
171  * @return the number of conditions, a condition of this type has
172  */
173  virtual unsignedIntFib getNumberOfConditions() const;
174 
175  /**
176  * @return the number of underfunctions, a condition of this type has
177  */
179 
180  /**
181  * Sets the Fib-element which defines/ uses this condition.
182  * If the given pointer is the nullpointer (standardvalue), no
183  * Fib-element defines this condition.
184  *
185  * @param pDefiningFibElement a pointer to the Fib-element which
186  * defines/ uses this condition
187  * @param bCheckDomains get the domains of the defining element and
188  * check the underfunctionelements with it
189  */
191  bool bCheckDomains=true );
192 
193  /**
194  * This method evaluades a value for the time needed to evalue the
195  * condition.
196  * This value should not exceed lMaxTime, if the value for the time
197  * is greater than lMaxTime the evaluation will be stopt and lMaxTime
198  * returned. If lMaxTime is 0 (for infinity) the evaluation won't be
199  * stoped, this is the standard case.
200  *
201  * @see cFibElement::evalueObject()
202  * @param lMaxTime the maximum time for the evaluation, the returned
203  * exceed this value; the value 0 stands for infinity, so the
204  * evaluation won't be stoped
205  * @return a value for the time needed to evalue this condition
206  */
207  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const;
208 
209  /**
210  * This method evaluades the size of the Fib-object in bits in the
211  * compressed file form.
212  * The optionalpart field of point -elements will be ignored.
213  *
214  * @see store()
215  * @return the size of the Fib-object in bits in the compressed form
216  */
217  virtual unsignedLongFib getCompressedSize() const;
218 
219  /**
220  * This method stores this Fib-object in the compressed Fib-format
221  * into the given stream.
222  * It is needed becouse the stream can yust store byts but the size of
223  * Fib-elements can be any number of bits. Because of that ther have to
224  * be a possibility to exchange the missing bits betwean the Fib-elements.
225  *
226  * @see store
227  * @param stream the stream where this Fib-object should be stored to
228  * @param cRestBits the not yet writen bits which should be stored
229  * @param uiRestBitPosition the number of bits in the cRestBits which
230  * should be writen respectively containing valid information
231  * @return true if this Fib-object is stored, else false
232  */
233  virtual bool store( ostream & stream, char & cRestBits,
234  unsigned char & uiRestBitPosition ) const;
235 
236  /**
237  * This method stores this condition in the XML-format into the
238  * given stream.
239  * Variables should have ther number as ther value.
240  *
241  * @param stream the stream where this conditionshould be
242  * stored to
243  * @return true if this condition is stored, else false
244  */
245  virtual bool storeXml( ostream & stream ) const;
246 
247 #ifndef FEATURE_EQUAL_FIB_OBJECT
248 
249  /**
250  * This Method checks if the given condition is equal to this condition.
251  *
252  * @param condition the condition to compare with this condition
253  * @return true if the given condition is equal to this condition, else false
254  */
255  virtual bool equal( const cCondition & condition ) const;
256 
257 #endif //FEATURE_EQUAL_FIB_OBJECT
258 
259  /**
260  * @see pFirstSubFunction
261  * @see setFirstSubFunction()
262  * @return a pointer to the first function this condition contains (@see pSubFunction)
263  */
265 
266  /**
267  * @see pFirstSubFunction
268  * @see setFirstSubFunction()
269  * @return a pointer to the first function this condition contains (@see pSubFunction)
270  */
271  const cUnderFunction * getFirstSubFunction() const;
272 
273  /**
274  * This method sets the contained first function (@see pSubFunction) to the
275  * given condition pInSubFunction.
276  * Beware: It (pInSubFunction) won't be copied.
277  *
278  * @see pFirstSubFunction
279  * @see getFirstSubFunction()
280  * @param pInSubFunction a pointer to the subcondition to set
281  * @param bDeleteOld if true, delete the old subcondition from the memory
282  * @return true if pInSubFunction condition was set, else false
283  */
284  bool setFirstSubFunction( cUnderFunction * pInSubFunction, bool bDeleteOld=true );
285 
286  /**
287  * This method sets the contained first function (@see pSubFunction) to the
288  * given condition pInSubFunction.
289  *
290  * @see pFirstSubFunction
291  * @see getFirstSubFunction()
292  * @param pInSubFunction the subcondition to set
293  * @param bDeleteOld if true, delete the old subcondition from the memory
294  * @return true if pInSubFunction condition was set, else false
295  */
296  bool setFirstSubFunction( const cUnderFunction & pInSubFunction, bool bDeleteOld=true );
297 
298  /**
299  * @see pSecondSubFunction
300  * @see setSecondSubFunction()
301  * @return a pointer to the second function this condition contains (@see pSubFunction)
302  */
304 
305  /**
306  * @see pSecondSubFunction
307  * @see setSecondSubFunction()
308  * @return a pointer to the second function this condition contains (@see pSubFunction)
309  */
310  const cUnderFunction * getSecondSubFunction() const;
311 
312  /**
313  * This method sets the contained second function (@see pSubFunction) to the
314  * given condition pInSubFunction.
315  * Beware: It (pInSubFunction) won't be copied.
316  *
317  * @see pSecondSubFunction
318  * @see getSecondSubFunction()
319  * @param pInSubFunction a pointer to the subcondition to set
320  * @param bDeleteOld if true, delete the old subcondition from the memory
321  * @return true if pInSubFunction condition was set, else false
322  */
323  bool setSecondSubFunction( cUnderFunction * pInSubFunction, bool bDeleteOld=true );
324 
325  /**
326  * This method sets the contained second function (@see pSubFunction) to the
327  * given condition pInSubFunction.
328  *
329  * @see pSecondSubFunction
330  * @see getSecondSubFunction()
331  * @param pInSubFunction the subcondition to set
332  * @param bDeleteOld if true, delete the old subcondition from the memory
333  * @return true if pInSubFunction condition was set, else false
334  */
335  bool setSecondSubFunction( const cUnderFunction & pInSubFunction, bool bDeleteOld=true );
336 
337 
338 protected:
339 
340  /**
341  * @return the compressed type bits for this type of condition
342  */
343  virtual char getTypeBit() const = 0;
344 
345 #ifdef FEATURE_EQUAL_FIB_OBJECT
346 
347  /**
348  * This method checks if the given Fib-object is equal to this fib
349  * -object.
350  * Variables can be others, but must be defined and used in equivalent
351  * Fib-elements.
352  *
353  * @param condition the condition to which this condition should be
354  * equal
355  * @param mapEqualRootObjects the root objects of this object that wher
356  * already checked as equal
357  * map entries:
358  * key: the root-element of this Fib object that was checked
359  * value: the to the key correspondending root-element of the
360  * fibObject that was checked and which is equal to the key
361  * root-element
362  * @param mapEqualDefinedVariables the Fib elements that defines
363  * variables and are equal;
364  * map entries:
365  * key: the Fib element of this Fib object that was checked
366  * value: the to the key correspondending Fib element of the
367  * fibObject that was checked and which sets its defined
368  * variables to the same values as the key Fib element
369  * @param bCheckExternalObjects if true the external objects of
370  * cExtObject will be compared
371  * @return true if this Fib-object is equal to the given Fib-object,
372  * else false
373  */
374  virtual bool equalInternal( const cCondition & condition,
375  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
376  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
377  const bool bCheckExternalObjects ) const;
378 
379 #endif //FEATURE_EQUAL_FIB_OBJECT
380 
381 };//end class cConditionComparison
382 
383 
384 }//end namespace Fib
385 
386 #endif //___C_CONDITION_COMPARISON_H__