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
cCondition.h
Go to the documentation of this file.
1 /**
2  * @class cCondition
3  * file name: cCondition.h
4  * @author Betti Oesterholz
5  * @date 29.04.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a basic Fib-condition.
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 file contains the basisclass of all Fib-condition. It's not
28  * possible to create instances from this class.
29  * Conditions are used in Fib-elements, especialy if-elements, to
30  * represent logical conditions such like "not" or the "and" condition.
31  *
32  */
33 /*
34 History:
35 29.04.2011 Oesterholz created
36 19.10.2011 Oesterholz FEATURE_EQUAL_FIB_OBJECT implemented
37 */
38 
39 #ifndef ___C_CONDITION_H__
40 #define ___C_CONDITION_H__
41 
42 
43 #include "version.h"
44 #include "fibDatatyps.h"
45 #include "cReadBits.h"
46 
47 #include "cFibVariable.h"
48 #include "cDomainSingle.h"
49 
50 #include "tinyxml.h"
51 
52 #include <sstream>
53 #include <ostream>
54 #include <istream>
55 #include <set>
56 #include <map>
57 #include <list>
58 
59 using std::set;
60 using std::map;
61 using std::list;
62 
63 namespace fib{
64 
65 
66 class cFibElement;//cyclic dependencie
67 
68 
69 class cCondition{
70 
71  friend class cIf;
72  friend class cFunctionIf;
73  friend class cConditionNot;
74  friend class cConditionTwoValue;
75 
76 public:
77 
78  /**
79  * the definitions for the condition
80  */
81  static const unsignedIntFib CONDITION_FALSE = 0; // cConditionFalse
82  static const unsignedIntFib CONDITION_TRUE = 1; // cConditionTrue
83  static const unsignedIntFib CONDITION_NOT = 10; // cConditionNot
84  static const unsignedIntFib CONDITION_OR = 20; // cConditionTrue
85  static const unsignedIntFib CONDITION_AND = 21; // cConditionTrue
86  static const unsignedIntFib CONDITION_XOR = 23; // cConditionTrue
87  static const unsignedIntFib CONDITION_EQUAL_INTEGER = 25; // cConditionEqualInteger
88  static const unsignedIntFib CONDITION_LOWER = 26; // cConditionLower
89  static const unsignedIntFib CONDITION_GREATER = 27; // cConditionGreater
90 
91 protected:
92 
93  /**
94  * the Fib-element which defines/ uses the condition
95  */
97 
98  /**
99  * the Fib-element which defines/ uses the condition
100  */
102 
103 
104  /**
105  * The constructor of the condition.
106  *
107  * @param pInSuperiorCondition the condition which contains
108  * @param pInDefiningFibElement the Fib-element which defines/ uses
109  * the new condition
110  */
111  cCondition( cCondition * pInSuperiorCondition = NULL,
112  cFibElement * pInDefiningFibElement = NULL );
113 
114  /**
115  * The copy constructor of the condition.
116  *
117  * @param condition the condition which to copy
118  * @param pSuperiorCondition the condition which contains
119  * @param pInDefiningFibElement the Fib-element which defines/ uses
120  */
121  cCondition( const cCondition & condition,
122  cCondition * pInSuperiorCondition = NULL,
123  cFibElement *pInDefiningFibElement = NULL );
124 
125 public:
126 
127  /**
128  * The destructor of the condition.
129  */
130  virtual ~cCondition();
131 
132  /**
133  * This method returns if this condition is valid, else false.
134  * All subcondition and underfunctions must be valid.
135  * No condition should contain itself or should be contained in one
136  * of its condition (no cycles allowed).
137  *
138  * @return true if this condition is valid, else false
139  */
140  virtual bool isValid() const = 0;
141 
142 
143  /**
144  * This method checks if the given variable is used in this condition.
145  *
146  * @see cFibVariable
147  * @param variable the variable to check if it is used
148  * @return true if the variable is used, else false
149  */
150  virtual bool isUsedVariable( const cFibVariable * variable ) const = 0;
151 
152  /**
153  * This method returns all variables used in this condition.
154  *
155  * @see cFibVariable
156  * @return all variables used in this condition
157  */
158  virtual set<cFibVariable*> getUsedVariables() = 0;
159 
160  /**
161  * This method replace the variable variableOld with the variable
162  * variableNew in the condition.
163  *
164  * @see cFibVariable
165  * @see isVariable()
166  * @see isUsedVariable()
167  * @param variableOld the variable to replace
168  * @param variableNew the variable with which the variable variableOld
169  * is to replace
170  * @return true if the variable variableOld is replaced with variableNew,
171  * else false
172  */
173  virtual bool replaceVariable( cFibVariable *variableOld,
174  cFibVariable *variableNew ) = 0;
175 
176  /**
177  * Returns the value of the condition (if it is true or false).
178  *
179  * @return the value of the condition
180  */
181  virtual bool getValue() const = 0;
182 
183  /**
184  * @return the number of sub-condition, a condition of this type has
185  */
186  virtual unsignedIntFib getNumberOfConditions() const = 0;
187 
188  /**
189  * @return the number of underfunctions, a condition of this type has
190  */
191  virtual unsignedIntFib getNumberOfUnderFunctions() const = 0;
192 
193  /**
194  * @return the Fib-element which defines/ uses this condition or
195  * a Nullpointer NULL if non such Fib-element exists
196  */
198 
199  /**
200  * @return the superior condition to this or NULL, if non such
201  * exists (the superior condition is the condition, which
202  * contains this condition)
203  */
205 
206  /**
207  * Sets the Fib-element which defines/ uses this condition.
208  * If the given pointer is the nullpointer (standardvalue), no
209  * Fib-element defines this condition.
210  *
211  * @param definingFibElement a pointer to the Fib-element which
212  * defines/ uses this condition
213  * @param bCheckDomains get the domains of the defining element and
214  * check the conditionelements 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  * condition.
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 condition
232  */
233  virtual unsignedLongFib getTimeNeed( unsignedLongFib lMaxTime=0 ) const = 0;
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 = 0;
244 
245  /**
246  * This method restores a condition in the XML-format from an
247  * TinyXml element.
248  *
249  * @param pXmlNode a pointer to the TinyXml node wher the condition is stored in
250  * @param outStatus an integervalue with the errorvalue
251  * possible errorvalues are:
252  * - 0 loading successful
253  * - -1 loading error, invalid pXmlElement
254  * - -2 loading error, invalid data in pXmlElement
255  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
256  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
257  * object is wrong
258  * @param liDefinedVariables a list with the defined variables for the
259  * to restore Fib-element, every variable should have it's number
260  * (the number under which it is stored) as it's value
261  * @param pInSuperiorCondition the condition which contains the
262  * to restore condition
263  * @param pInDefiningFibElement the Fib-element which defines/ uses
264  * the to restore condition
265  * @return the pointers to the restored condition, if non could be restored
266  * the returned pointer is NULL
267  */
268  static cCondition * restoreXml( const TiXmlElement * pXmlElement,
269  intFib & outStatus, list<cFibVariable*> & liDefinedVariables,
270  cCondition * pInSuperiorCondition = NULL,
271  cFibElement *pInDefiningFibElement = NULL );
272 
273  /**
274  * This method stores this condition in the XML -format into the
275  * given stream.
276  * Variables should have ther number as ther value.
277  *
278  * @param stream the stream where this conditionhould be
279  * stored to
280  * @return true if this condition is stored, else false
281  */
282  virtual bool storeXml( ostream &stream ) const = 0;
283 
284  /**
285  * This method restores a condition from a bitstream, wher it is
286  * stored in the compressed Fib-format.
287  *
288  * @see store
289  * @param iBitStream the stream where the condition is stored in,
290  * because the stream is an cReadBits, any number of bits can be
291  * readed from it
292  * @param outStatus an integervalue with the errorvalue
293  * possible errorvalues are:
294  * - 0 loading successful
295  * - -1 loading error, invalid pXmlElement
296  * - -2 loading error, invalid data in pXmlElement
297  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
298  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
299  * object is wrong
300  * @param liDefinedVariables a list with the defined variables for the
301  * to restore Fib-element, every variable should have it's number
302  * (the number under which it is stored) as it's value
303  * @param pInValueDomain the domain for value condition
304  * @param pInDomainVariable the domain for variables
305  * @param pInSuperiorCondition the condition which contains the
306  * to restore condition
307  * @param pInDefiningFibElement the Fib-element which defines/ uses
308  * the to restore condition
309  * @return a pointer to the restored condition or NULL
310  */
311  static cCondition * restore( cReadBits & iBitStream, intFib & outStatus,
312  list<cFibVariable*> & liDefinedVariables,
313  const cDomainSingle * pInValueDomain, const cDomainSingle * pInDomainVariable,
314  cCondition * pInSuperiorCondition = NULL,
315  cFibElement *pInDefiningFibElement = NULL );
316 
317  /**
318  * This method stores this Fib-object in the compressed Fib-format
319  * into the given stream.
320  * It is needed becouse the stream can yust store byts but the size of
321  * Fib-elements can be any number of bits. Because of that ther have to
322  * be a possibility to exchange the missing bits betwean the Fib-elements.
323  *
324  * @see store
325  * @param stream the stream where this Fib-object should be stored to
326  * @param cRestBits the not yet writen bits which should be stored
327  * @param uiRestBitPosition the number of bits in the cRestBits which
328  * should be writen respectively containing valid information
329  * @return true if this Fib-object is stored, else false
330  */
331  virtual bool store( ostream & stream, char & cRestBits,
332  unsigned char & uiRestBitPosition ) const = 0;
333 
334  /**
335  * @return the type for the condition
336  */
337  virtual unsignedIntFib getType() const = 0;
338 
339  /**
340  * @return the name for the condition
341  */
342  virtual string getConditionName() const = 0;
343 
344 #ifdef FEATURE_EQUAL_FIB_OBJECT
345  /**
346  * This method checks if the given condition is equal to this condition.
347  *
348  * @param condition the condition to compare with this condition
349  * @param bCheckExternalObjects if true the external objects of
350  * cExtObject will be compared
351  * @return true if the given condition is equal to this condition, else false
352  */
353  virtual bool equal( const cCondition &condition,
354  const bool bCheckExternalObjects=true ) const;
355 
356 #else //FEATURE_EQUAL_FIB_OBJECT
357  /**
358  * This method checks if the given condition is equal to this condition.
359  *
360  * @param condition the condition to compare with this condition
361  * @return true if the given condition is equal to this condition, else false
362  */
363  virtual bool equal( const cCondition &condition ) const = 0;
364 #endif //FEATURE_EQUAL_FIB_OBJECT
365 
366  /**
367  * This method checks if the given condition is equal to this condition.
368  *
369  * @param condition the condition to compare with this condition
370  * @return true if the given condition is equal to this condition, else false
371  */
372  virtual bool operator==( const cCondition &condition ) const;
373 
374  /**
375  * This method checks if the given condition is not equal to this condition.
376  *
377  * @param condition the condition to compare with this condition
378  * @return true if the given condition is not equal to this condition, else false
379  */
380  bool operator!=( const cCondition &condition ) const;
381 
382  /**
383  * This method duplicates this whole condition.
384  * subcondition of this condition are also cloned.
385  *
386  * @param pSuperiorCondition the condition which contains the cloned
387  * condition
388  * @param pInDefiningFibElement the Fib-element which defines/ uses
389  * the cloned condition
390  * @return the cloned/ duplicated condition
391  */
392  virtual cCondition * clone(
393  cCondition * pInSuperiorCondition = NULL,
394  cFibElement *pInDefiningFibElement = NULL) const = 0;
395 
396 protected:
397 
398 #ifdef FEATURE_EQUAL_FIB_OBJECT
399 
400  /**
401  * This method checks if the given Fib-object is equal to this fib
402  * -object.
403  * Variables can be others, but must be defined and used in equivalent
404  * Fib-elements.
405  *
406  * @param condition the condition to which this condition should be equal
407  * @param mapEqualRootObjects the root objects of this object that wher
408  * already checked as equal
409  * map entries:
410  * key: the root-element of this Fib object that was checked
411  * value: the to the key correspondending root-element of the
412  * fibObject that was checked and which is equal to the key
413  * root-element
414  * (it is empty if bCheckExternalObjects == false)
415  * @param mapEqualDefinedVariables the Fib elements that defines
416  * variables and are equal;
417  * map entries:
418  * key: the Fib element of this Fib object that was checked
419  * value: the to the key correspondending Fib element of the
420  * fibObject that was checked and which sets its defined
421  * variables to the same values as the key Fib element
422  * @param bCheckExternalObjects if true the external objects of
423  * cExtObject will be compared
424  * @return true if this Fib-object is equal to the given Fib-object,
425  * else false
426  */
427  virtual bool equalInternal( const cCondition & condition,
428  map< const cRoot *, const cRoot * > & mapEqualRootObjects,
429  map< const cFibElement *, const cFibElement * > & mapEqualDefinedVariables,
430  const bool bCheckExternalObjects ) const = 0;
431 
432 #endif //FEATURE_EQUAL_FIB_OBJECT
433 
434 
435 };//end class cCondition
436 
437 
438 }//end namespace fib
439 
440 #endif //___C_CONDITION_H__