3 * Declarations and inline methods for property conditions.
4 * Written by David Megginson, started 2000.
5 * CLO May 2003 - Split out condition specific code.
7 * This file is in the Public Domain, and comes with no warranty.
10 #ifndef __SG_CONDITION_HXX
11 #define __SG_CONDITION_HXX
13 #include <simgear/debug/logstream.hxx>
14 #include <simgear/props/props.hxx>
15 #include <simgear/props/props_io.hxx>
18 ////////////////////////////////////////////////////////////////////////
20 ////////////////////////////////////////////////////////////////////////
24 * An encoded condition.
26 * This class encodes a single condition of some sort, possibly
27 * connected with properties.
29 * This class should migrate to somewhere more general.
35 virtual ~SGCondition ();
36 virtual bool test () const = 0;
41 * Condition for a single property.
43 * This condition is true only if the property returns a boolean
46 class SGPropertyCondition : public SGCondition
49 SGPropertyCondition ( SGPropertyNode *prop_root,
50 const char * propname );
51 virtual ~SGPropertyCondition ();
52 virtual bool test () const { return _node->getBoolValue(); }
54 SGConstPropertyNode_ptr _node;
59 * Condition for a 'not' operator.
61 * This condition is true only if the child condition is false.
63 class SGNotCondition : public SGCondition
66 // transfer pointer ownership
67 SGNotCondition (SGCondition * condition);
68 virtual ~SGNotCondition ();
69 virtual bool test () const;
71 SGCondition * _condition;
76 * Condition for an 'and' group.
78 * This condition is true only if all of the conditions
79 * in the group are true.
81 class SGAndCondition : public SGCondition
85 virtual ~SGAndCondition ();
86 virtual bool test () const;
87 // transfer pointer ownership
88 virtual void addCondition (SGCondition * condition);
90 vector<SGCondition *> _conditions;
95 * Condition for an 'or' group.
97 * This condition is true if at least one of the conditions in the
100 class SGOrCondition : public SGCondition
104 virtual ~SGOrCondition ();
105 virtual bool test () const;
106 // transfer pointer ownership
107 virtual void addCondition (SGCondition * condition);
109 vector<SGCondition *> _conditions;
114 * Abstract base class for property comparison conditions.
116 class SGComparisonCondition : public SGCondition
124 SGComparisonCondition (Type type, bool reverse = false);
125 virtual ~SGComparisonCondition ();
126 virtual bool test () const;
127 virtual void setLeftProperty( SGPropertyNode *prop_root,
128 const char * propname );
129 virtual void setRightProperty( SGPropertyNode *prop_root,
130 const char * propname );
131 // will make a local copy
132 virtual void setRightValue (const SGPropertyNode * value);
136 SGConstPropertyNode_ptr _left_property;
137 SGConstPropertyNode_ptr _right_property;
138 SGConstPropertyNode_ptr _right_value;
143 * Base class for a conditional components.
145 * This class manages the conditions and tests; the component should
146 * invoke the test() method whenever it needs to decide whether to
147 * active itself, draw itself, and so on.
153 virtual ~SGConditional ();
154 // transfer pointer ownership
155 virtual void setCondition (SGCondition * condition);
156 virtual const SGCondition * getCondition () const { return _condition; }
157 virtual bool test () const;
159 SGCondition * _condition;
164 * Global function to make a condition out of properties.
166 * The top-level is always an implicit 'and' group, whatever the
167 * node's name (it should usually be "condition").
169 * @param node The top-level condition node (usually named "condition").
170 * @return A pointer to a newly-allocated condition; it is the
171 * responsibility of the caller to delete the condition when
172 * it is no longer needed.
174 SGCondition *sgReadCondition( SGPropertyNode *prop_root,
175 const SGPropertyNode *node );
178 #endif // __SG_CONDITION_HXX