FlightGear next
FGFunction.h
Go to the documentation of this file.
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3Header: FGFunction.h
4Author: Jon Berndt
5Date started: August 25 2004
6
7 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
8
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later version.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17 details.
18
19 You should have received a copy of the GNU Lesser General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27SENTRY
28%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
29
30#ifndef FGFUNCTION_H
31#define FGFUNCTION_H
32
33/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34INCLUDES
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36
37#include "FGParameter.h"
39
40/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41FORWARD DECLARATIONS
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44namespace JSBSim {
45
46class Element;
47class FGPropertyValue;
48class FGFDMExec;
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS DOCUMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
745
746/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747DECLARATION: FGFunction
748%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
749
750// Todo: Does this class need a copy constructor, like FGLGear?
751
752class FGFunction : public FGParameter, public FGJSBBase
753{
754public:
757 : cached(false), cachedValue(-HUGE_VAL), PropertyManager(nullptr),
758 pNode(nullptr), pCopyTo(nullptr) {}
759
761 : FGFunction()
762 { PropertyManager = pm; }
763
781 FGFunction(FGFDMExec* fdmex, Element* element, const std::string& prefix="",
782 FGPropertyValue* var=0L);
783
787 ~FGFunction(void) override;
788
791 double GetValue(void) const override;
792
795 std::string GetValueAsString(void) const;
796
798 std::string GetName(void) const override {return Name;}
799
802 bool IsConstant(void) const override;
803
812 void cacheValue(bool shouldCache);
813
814 enum class OddEven {Either, Odd, Even};
815
816protected:
817 bool cached;
819 std::vector <FGParameter_ptr> Parameters;
822
823 void Load(Element* element, FGPropertyValue* var, FGFDMExec* fdmex,
824 const std::string& prefix="");
825 virtual void bind(Element*, const std::string&);
826 void CheckMinArguments(Element* el, unsigned int _min);
827 void CheckMaxArguments(Element* el, unsigned int _max);
828 void CheckOddOrEvenArguments(Element* el, OddEven odd_even);
829 std::string CreateOutputNode(Element* el, const std::string& Prefix);
830
831private:
832 std::string Name;
833 FGPropertyNode_ptr pCopyTo; // Property node for CopyTo property string
834
835 void Debug(int from);
836};
837
838} // namespace JSBSim
839
840#endif
FGFunction(FGPropertyManager *pm)
Definition FGFunction.h:760
std::string GetName(void) const override
Retrieves the name of the function.
Definition FGFunction.h:798
FGPropertyNode_ptr pNode
Definition FGFunction.h:821
~FGFunction(void) override
Destructor Make sure the function is untied before destruction.
void CheckMaxArguments(Element *el, unsigned int _max)
FGFunction()
Default constructor.
Definition FGFunction.h:756
void CheckOddOrEvenArguments(Element *el, OddEven odd_even)
double GetValue(void) const override
Retrieves the value of the function object.
std::string GetValueAsString(void) const
The value that the function evaluates to, as a string.
std::string CreateOutputNode(Element *el, const std::string &Prefix)
virtual void bind(Element *, const std::string &)
std::vector< FGParameter_ptr > Parameters
Definition FGFunction.h:819
FGPropertyManager * PropertyManager
Definition FGFunction.h:820
bool IsConstant(void) const override
Does the function always return the same result (i.e.
void CheckMinArguments(Element *el, unsigned int _min)
FGFunction(FGFDMExec *fdmex, Element *element, const std::string &prefix="", FGPropertyValue *var=0L)
Constructor.
void cacheValue(bool shouldCache)
Specifies whether to cache the value of the function, so it is calculated only once per frame.
void Load(Element *element, FGPropertyValue *var, FGFDMExec *fdmex, const std::string &prefix="")
FGJSBBase()
Constructor for FGJSBBase.
Definition FGJSBBase.h:81
Represents various types of parameters.
Definition FGParameter.h:59
Represents a property value which can use late binding.
SGSharedPtr< FGPropertyNode > FGPropertyNode_ptr