X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Fcondition.hxx;h=719f68795411ad609664557e4079d5494f3be63f;hb=708ae35068499af33329f9db91f55441f4956acb;hp=3da63712f081d8d7f03eb057340bb44e5064f94b;hpb=525d2df3ccbf80152492a8632267f228a41ac393;p=simgear.git diff --git a/simgear/props/condition.hxx b/simgear/props/condition.hxx index 3da63712..719f6879 100644 --- a/simgear/props/condition.hxx +++ b/simgear/props/condition.hxx @@ -1,8 +1,11 @@ -// condition.hxx - Declarations and inline methods for property conditions. -// Written by David Megginson, started 2000. -// CLO May 2003 - Split out condition specific code. -// -// This file is in the Public Domain, and comes with no warranty. +/** + * \file condition.hxx + * Declarations and inline methods for property conditions. + * Written by David Megginson, started 2000. + * CLO May 2003 - Split out condition specific code. + * + * This file is in the Public Domain, and comes with no warranty. + */ #ifndef __SG_CONDITION_HXX #define __SG_CONDITION_HXX @@ -10,7 +13,7 @@ #include #include #include - +#include //////////////////////////////////////////////////////////////////////// // Conditions. @@ -25,117 +28,15 @@ * * This class should migrate to somewhere more general. */ -class FGCondition +class SGCondition : public SGReferenced { public: - FGCondition (); - virtual ~FGCondition (); + SGCondition (); + virtual ~SGCondition (); virtual bool test () const = 0; }; -/** - * Condition for a single property. - * - * This condition is true only if the property returns a boolean - * true value. - */ -class FGPropertyCondition : public FGCondition -{ -public: - FGPropertyCondition ( SGPropertyNode *prop_root, - const char * propname ); - virtual ~FGPropertyCondition (); - virtual bool test () const { return _node->getBoolValue(); } -private: - const SGPropertyNode * _node; -}; - - -/** - * Condition for a 'not' operator. - * - * This condition is true only if the child condition is false. - */ -class FGNotCondition : public FGCondition -{ -public: - // transfer pointer ownership - FGNotCondition (FGCondition * condition); - virtual ~FGNotCondition (); - virtual bool test () const; -private: - FGCondition * _condition; -}; - - -/** - * Condition for an 'and' group. - * - * This condition is true only if all of the conditions - * in the group are true. - */ -class FGAndCondition : public FGCondition -{ -public: - FGAndCondition (); - virtual ~FGAndCondition (); - virtual bool test () const; - // transfer pointer ownership - virtual void addCondition (FGCondition * condition); -private: - vector _conditions; -}; - - -/** - * Condition for an 'or' group. - * - * This condition is true if at least one of the conditions in the - * group is true. - */ -class FGOrCondition : public FGCondition -{ -public: - FGOrCondition (); - virtual ~FGOrCondition (); - virtual bool test () const; - // transfer pointer ownership - virtual void addCondition (FGCondition * condition); -private: - vector _conditions; -}; - - -/** - * Abstract base class for property comparison conditions. - */ -class FGComparisonCondition : public FGCondition -{ -public: - enum Type { - LESS_THAN, - GREATER_THAN, - EQUALS - }; - FGComparisonCondition (Type type, bool reverse = false); - virtual ~FGComparisonCondition (); - virtual bool test () const; - virtual void setLeftProperty( SGPropertyNode *prop_root, - const char * propname ); - virtual void setRightProperty( SGPropertyNode *prop_root, - const char * propname ); - // will make a local copy - virtual void setRightValue (const SGPropertyNode * value); -private: - Type _type; - bool _reverse; - const SGPropertyNode * _left_property; - const SGPropertyNode * _right_property; - const SGPropertyNode * _right_value; -}; - - /** * Base class for a conditional components. * @@ -143,17 +44,17 @@ private: * invoke the test() method whenever it needs to decide whether to * active itself, draw itself, and so on. */ -class FGConditional +class SGConditional : public SGReferenced { public: - FGConditional (); - virtual ~FGConditional (); + SGConditional (); + virtual ~SGConditional (); // transfer pointer ownership - virtual void setCondition (FGCondition * condition); - virtual const FGCondition * getCondition () const { return _condition; } + virtual void setCondition (SGCondition * condition); + virtual const SGCondition * getCondition () const { return _condition; } virtual bool test () const; private: - FGCondition * _condition; + SGSharedPtr _condition; }; @@ -168,8 +69,8 @@ private: * responsibility of the caller to delete the condition when * it is no longer needed. */ -FGCondition * fgReadCondition( SGPropertyNode *prop_root, - const SGPropertyNode *node ); +SGCondition *sgReadCondition( SGPropertyNode *prop_root, + const SGPropertyNode *node ); #endif // __SG_CONDITION_HXX