condition.hxx

Go to the documentation of this file.
00001 
00010 #ifndef __SG_CONDITION_HXX
00011 #define __SG_CONDITION_HXX
00012 
00013 #include <simgear/debug/logstream.hxx>
00014 #include <simgear/props/props.hxx>
00015 #include <simgear/props/props_io.hxx>
00016 
00017 
00019 // Conditions.
00021 
00022 
00031 class SGCondition
00032 {
00033 public:
00034   SGCondition ();
00035   virtual ~SGCondition ();
00036   virtual bool test () const = 0;
00037 };
00038 
00039 
00046 class SGPropertyCondition : public SGCondition
00047 {
00048 public:
00049   SGPropertyCondition ( SGPropertyNode *prop_root,
00050                         const char * propname  );
00051   virtual ~SGPropertyCondition ();
00052   virtual bool test () const { return _node->getBoolValue(); }
00053 private:
00054   SGConstPropertyNode_ptr _node;
00055 };
00056 
00057 
00063 class SGNotCondition : public SGCondition
00064 {
00065 public:
00066                                 // transfer pointer ownership
00067   SGNotCondition (SGCondition * condition);
00068   virtual ~SGNotCondition ();
00069   virtual bool test () const;
00070 private:
00071   SGCondition * _condition;
00072 };
00073 
00074 
00081 class SGAndCondition : public SGCondition
00082 {
00083 public:
00084   SGAndCondition ();
00085   virtual ~SGAndCondition ();
00086   virtual bool test () const;
00087                                 // transfer pointer ownership
00088   virtual void addCondition (SGCondition * condition);
00089 private:
00090   vector<SGCondition *> _conditions;
00091 };
00092 
00093 
00100 class SGOrCondition : public SGCondition
00101 {
00102 public:
00103   SGOrCondition ();
00104   virtual ~SGOrCondition ();
00105   virtual bool test () const;
00106                                 // transfer pointer ownership
00107   virtual void addCondition (SGCondition * condition);
00108 private:
00109   vector<SGCondition *> _conditions;
00110 };
00111 
00112 
00116 class SGComparisonCondition : public SGCondition
00117 {
00118 public:
00119   enum Type {
00120     LESS_THAN,
00121     GREATER_THAN,
00122     EQUALS
00123   };
00124   SGComparisonCondition (Type type, bool reverse = false);
00125   virtual ~SGComparisonCondition ();
00126   virtual bool test () const;
00127   virtual void setLeftProperty( SGPropertyNode *prop_root,
00128                                 const char * propname );
00129   virtual void setRightProperty( SGPropertyNode *prop_root,
00130                                  const char * propname );
00131                                 // will make a local copy
00132   virtual void setRightValue (const SGPropertyNode * value);
00133 private:
00134   Type _type;
00135   bool _reverse;
00136   SGConstPropertyNode_ptr _left_property;
00137   SGConstPropertyNode_ptr _right_property;
00138   SGConstPropertyNode_ptr _right_value;
00139 };
00140 
00141 
00149 class SGConditional
00150 {
00151 public:
00152   SGConditional ();
00153   virtual ~SGConditional ();
00154                                 // transfer pointer ownership
00155   virtual void setCondition (SGCondition * condition);
00156   virtual const SGCondition * getCondition () const { return _condition; }
00157   virtual bool test () const;
00158 private:
00159   SGCondition * _condition;
00160 };
00161 
00162 
00174 SGCondition *sgReadCondition( SGPropertyNode *prop_root,
00175                               const SGPropertyNode *node );
00176 
00177 
00178 #endif // __SG_CONDITION_HXX
00179 

Generated on Mon Dec 17 09:30:54 2007 for SimGear by  doxygen 1.5.1