]> git.mxchange.org Git - simgear.git/blob - simgear/props/condition.hxx
SGConditionRef typedef. No functional changes.
[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 typedef SGSharedPtr<SGCondition> SGConditionRef;
42
43
44 /**
45  * Base class for a conditional components.
46  *
47  * This class manages the conditions and tests; the component should
48  * invoke the test() method whenever it needs to decide whether to
49  * active itself, draw itself, and so on.
50  */
51 class SGConditional : public SGReferenced
52 {
53 public:
54   SGConditional ();
55   virtual ~SGConditional ();
56                                 // transfer pointer ownership
57   virtual void setCondition (SGCondition * condition);
58   virtual const SGCondition * getCondition () const { return _condition; }
59   virtual bool test () const;
60 private:
61   SGConditionRef _condition;
62 };
63
64
65 /**
66  * Global function to make a condition out of properties.
67  *
68  * The top-level is always an implicit 'and' group, whatever the
69  * node's name (it should usually be "condition").
70  *
71  * @param node The top-level condition node (usually named "condition").
72  * @return A pointer to a newly-allocated condition; it is the
73  *         responsibility of the caller to delete the condition when
74  *         it is no longer needed.
75  */
76 SGCondition *sgReadCondition( SGPropertyNode *prop_root,
77                               const SGPropertyNode *node );
78
79
80 #endif // __SG_CONDITION_HXX
81