]> git.mxchange.org Git - simgear.git/blob - simgear/props/condition.hxx
Melchior FRANZ: fix SGPropertyNode::LAST_USED_ATTRIBUTE
[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 <simgear/debug/logstream.hxx>
14 #include <simgear/props/props.hxx>
15 #include <simgear/props/props_io.hxx>
16 #include <simgear/structure/SGReferenced.hxx>
17 \f
18 ////////////////////////////////////////////////////////////////////////
19 // Conditions.
20 ////////////////////////////////////////////////////////////////////////
21
22
23 /**
24  * An encoded condition.
25  *
26  * This class encodes a single condition of some sort, possibly
27  * connected with properties.
28  *
29  * This class should migrate to somewhere more general.
30  */
31 class SGCondition : public SGReferenced
32 {
33 public:
34   SGCondition ();
35   virtual ~SGCondition ();
36   virtual bool test () const = 0;
37 };
38
39
40 /**
41  * Base class for a conditional components.
42  *
43  * This class manages the conditions and tests; the component should
44  * invoke the test() method whenever it needs to decide whether to
45  * active itself, draw itself, and so on.
46  */
47 class SGConditional : public SGReferenced
48 {
49 public:
50   SGConditional ();
51   virtual ~SGConditional ();
52                                 // transfer pointer ownership
53   virtual void setCondition (SGCondition * condition);
54   virtual const SGCondition * getCondition () const { return _condition; }
55   virtual bool test () const;
56 private:
57   SGSharedPtr<SGCondition> _condition;
58 };
59
60
61 /**
62  * Global function to make a condition out of properties.
63  *
64  * The top-level is always an implicit 'and' group, whatever the
65  * node's name (it should usually be "condition").
66  *
67  * @param node The top-level condition node (usually named "condition").
68  * @return A pointer to a newly-allocated condition; it is the
69  *         responsibility of the caller to delete the condition when
70  *         it is no longer needed.
71  */
72 SGCondition *sgReadCondition( SGPropertyNode *prop_root,
73                               const SGPropertyNode *node );
74
75
76 #endif // __SG_CONDITION_HXX
77