JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
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 "FGParameter.h"
38 #include "input_output/FGPropertyManager.h"
39 
40 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 FORWARD DECLARATIONS
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 
44 namespace JSBSim {
45 
46 class Element;
47 class FGPropertyValue;
48 class FGFDMExec;
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS DOCUMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
746 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 DECLARATION: FGFunction
748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
749 
750 // Todo: Does this class need a copy constructor, like FGLGear?
751 
752 class FGFunction : public FGParameter, public FGJSBBase
753 {
754 public:
757  : cached(false), cachedValue(-HUGE_VAL), PropertyManager(nullptr),
758  pNode(nullptr), pCopyTo(nullptr) {}
759 
760  explicit FGFunction(FGPropertyManager* pm)
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 
816 protected:
817  bool cached;
818  double cachedValue;
819  std::vector <FGParameter_ptr> Parameters;
820  FGPropertyManager* PropertyManager;
821  FGPropertyNode_ptr pNode;
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 
831 private:
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
JSBSim::FGFunction
Represents a mathematical function.
Definition: FGFunction.h:752
JSBSim::FGFunction::IsConstant
bool IsConstant(void) const override
Does the function always return the same result (i.e.
Definition: FGFunction.cpp:901
JSBSim::FGParameter
Represents various types of parameters.
Definition: FGParameter.h:58
JSBSim::FGJSBBase
JSBSim Base class.
Definition: FGJSBBase.h:78
JSBSim::FGFunction::FGFunction
FGFunction()
Default constructor.
Definition: FGFunction.h:756
JSBSim::FGFunction::GetName
std::string GetName(void) const override
Retrieves the name of the function.
Definition: FGFunction.h:798
JSBSim::FGFunction::cacheValue
void cacheValue(bool shouldCache)
Specifies whether to cache the value of the function, so it is calculated only once per frame.
Definition: FGFunction.cpp:913
JSBSim::FGFunction::GetValue
double GetValue(void) const override
Retrieves the value of the function object.
Definition: FGFunction.cpp:925
JSBSim::FGFunction::~FGFunction
~FGFunction(void) override
Destructor Make sure the function is untied before destruction.
Definition: FGFunction.cpp:891
JSBSim::FGPropertyManager
Definition: FGPropertyManager.h:373
JSBSim::FGFunction::GetValueAsString
std::string GetValueAsString(void) const
The value that the function evaluates to, as a string.
Definition: FGFunction.cpp:938