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 #include <simgear/structure/SGReferenced.hxx> 00017 00018 00020 // Conditions. 00022 00023 00032 class SGCondition : public SGReferenced 00033 { 00034 public: 00035 SGCondition (); 00036 virtual ~SGCondition (); 00037 virtual bool test () const = 0; 00038 }; 00039 00040 00047 class SGPropertyCondition : public SGCondition 00048 { 00049 public: 00050 SGPropertyCondition ( SGPropertyNode *prop_root, 00051 const char * propname ); 00052 virtual ~SGPropertyCondition (); 00053 virtual bool test () const { return _node->getBoolValue(); } 00054 private: 00055 SGConstPropertyNode_ptr _node; 00056 }; 00057 00058 00064 class SGNotCondition : public SGCondition 00065 { 00066 public: 00067 SGNotCondition (SGCondition * condition); 00068 virtual ~SGNotCondition (); 00069 virtual bool test () const; 00070 private: 00071 SGSharedPtr<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 std::vector<SGSharedPtr<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 std::vector<SGSharedPtr<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 : public SGReferenced 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 SGSharedPtr<SGCondition> _condition; 00160 }; 00161 00162 00174 SGCondition *sgReadCondition( SGPropertyNode *prop_root, 00175 const SGPropertyNode *node ); 00176 00177 00178 #endif // __SG_CONDITION_HXX 00179