]> git.mxchange.org Git - simgear.git/blob - simgear/props/condition.hxx
Collect properties from expression/condition trees.
[simgear.git] / simgear / props / condition.hxx
1 /**
2  * \file condition.hxx
3  * Declarations and inline methods for property conditions.
4  * Written by David Megginson, started 2000.
5  * CLO May 2003 - Split out condition specific code.
6  *
7  * This file is in the Public Domain, and comes with no warranty.
8  */
9
10 #ifndef __SG_CONDITION_HXX
11 #define __SG_CONDITION_HXX
12
13 #include <set>
14 #include <simgear/structure/SGReferenced.hxx>
15 #include <simgear/structure/SGSharedPtr.hxx>
16
17 class SGPropertyNode;
18
19 ////////////////////////////////////////////////////////////////////////
20 // Conditions.
21 ////////////////////////////////////////////////////////////////////////
22
23
24 /**
25  * An encoded condition.
26  *
27  * This class encodes a single condition of some sort, possibly
28  * connected with properties.
29  *
30  * This class should migrate to somewhere more general.
31  */
32 class SGCondition : public SGReferenced
33 {
34 public:
35   SGCondition ();
36   virtual ~SGCondition ();
37   virtual bool test () const = 0;
38   virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const { }
39 };
40
41
42 /**
43  * Base class for a conditional components.
44  *
45  * This class manages the conditions and tests; the component should
46  * invoke the test() method whenever it needs to decide whether to
47  * active itself, draw itself, and so on.
48  */
49 class SGConditional : public SGReferenced
50 {
51 public:
52   SGConditional ();
53   virtual ~SGConditional ();
54                                 // transfer pointer ownership
55   virtual void setCondition (SGCondition * condition);
56   virtual const SGCondition * getCondition () const { return _condition; }
57   virtual bool test () const;
58 private:
59   SGSharedPtr<SGCondition> _condition;
60 };
61
62
63 /**
64  * Global function to make a condition out of properties.
65  *
66  * The top-level is always an implicit 'and' group, whatever the
67  * node's name (it should usually be "condition").
68  *
69  * @param node The top-level condition node (usually named "condition").
70  * @return A pointer to a newly-allocated condition; it is the
71  *         responsibility of the caller to delete the condition when
72  *         it is no longer needed.
73  */
74 SGCondition *sgReadCondition( SGPropertyNode *prop_root,
75                               const SGPropertyNode *node );
76
77
78 #endif // __SG_CONDITION_HXX
79