JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGFunction.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3 Header: FGFunction.h
4 Author: Jon Berndt
5 Date 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 SENTRY
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
29 
30 #ifndef FGFUNCTION_H
31 #define FGFUNCTION_H
32 
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 INCLUDES
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 
37 #include <memory>
38 
39 #include "FGParameter.h"
40 #include "input_output/FGPropertyManager.h"
41 
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 FORWARD DECLARATIONS
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 
46 namespace JSBSim {
47 
48 class Element;
49 class FGPropertyValue;
50 class FGFDMExec;
51 
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS DOCUMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 
748 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
749 DECLARATION: FGFunction
750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
751 
752 // Todo: Does this class need a copy constructor, like FGLGear?
753 
754 class FGFunction : public FGParameter, public FGJSBBase
755 {
756 public:
759  : cached(false), cachedValue(-HUGE_VAL), pNode(nullptr), pCopyTo(nullptr) {}
760 
761  explicit FGFunction(std::shared_ptr<FGPropertyManager> pm)
762  : FGFunction()
763  { PropertyManager = pm; }
764 
782  FGFunction(FGFDMExec* fdmex, Element* element, const std::string& prefix="",
783  FGPropertyValue* var=0L);
784 
788  ~FGFunction(void) override;
789 
792  double GetValue(void) const override;
793 
796  std::string GetValueAsString(void) const;
797 
799  std::string GetName(void) const override {return Name;}
800 
803  bool IsConstant(void) const override;
804 
813  void cacheValue(bool shouldCache);
814 
815  enum class OddEven {Either, Odd, Even};
816 
817 protected:
818  bool cached;
819  double cachedValue;
820  std::vector <FGParameter_ptr> Parameters;
821  std::shared_ptr<FGPropertyManager> PropertyManager;
822  FGPropertyNode_ptr pNode;
823 
824  void Load(Element* element, FGPropertyValue* var, FGFDMExec* fdmex,
825  const std::string& prefix="");
826  virtual void bind(Element*, const std::string&);
827  void CheckMinArguments(Element* el, unsigned int _min);
828  void CheckMaxArguments(Element* el, unsigned int _max);
829  void CheckOddOrEvenArguments(Element* el, OddEven odd_even);
830  std::string CreateOutputNode(Element* el, const std::string& Prefix);
831 
832 private:
833  std::string Name;
834  FGPropertyNode_ptr pCopyTo; // Property node for CopyTo property string
835 
836  void Debug(int from);
837 };
838 
839 } // namespace JSBSim
840 
841 #endif
Represents a mathematical function.
Definition: FGFunction.h:755
FGFunction()
Default constructor.
Definition: FGFunction.h:758
double GetValue(void) const override
Retrieves the value of the function object.
Definition: FGFunction.cpp:960
bool IsConstant(void) const override
Does the function always return the same result (i.e.
Definition: FGFunction.cpp:936
void cacheValue(bool shouldCache)
Specifies whether to cache the value of the function, so it is calculated only once per frame.
Definition: FGFunction.cpp:948
std::string GetName(void) const override
Retrieves the name of the function.
Definition: FGFunction.h:799
std::string GetValueAsString(void) const
The value that the function evaluates to, as a string.
Definition: FGFunction.cpp:973
~FGFunction(void) override
Destructor Make sure the function is untied before destruction.
Definition: FGFunction.cpp:926
JSBSim Base class.
Definition: FGJSBBase.h:118
Represents various types of parameters.
Definition: FGParameter.h:61