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