Implementing VNAV support in FlightGear: Difference between revisions

Jump to navigation Jump to search
Line 297: Line 297:
   void Debug(int from);
   void Debug(int from);
  };
  };
</syntaxhighlight>
== Adding new Functions ==
Here's a stub that demonstrates how to add a new mathematical function named '''myFunction''':
<syntaxhighlight lang="diff">
diff --git a/src/math/FGFunction.cpp b/src/math/FGFunction.cpp
index 6beeedb..03c38e0 100644
--- a/src/math/FGFunction.cpp
+++ b/src/math/FGFunction.cpp
@@ -107,6 +107,8 @@ const std::string FGFunction::not_string = "not";
const std::string FGFunction::ifthen_string = "ifthen";
const std::string FGFunction::switch_string = "switch";
const std::string FGFunction::interpolate1d_string = "interpolate1d";
+const std::string FGFunction::myfunction_string = "myfunction";
+
FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& prefix)
                                      : PropertyManager(propMan), Prefix(prefix)
@@ -228,6 +230,8 @@ FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& pr
    Type = eSwitch;
  } else if (operation == interpolate1d_string) {
    Type = eInterpolate1D;
+  } else if (operation == myfunction_string) {
+    Type = eMyFunction;
  } else if (operation != description_string) {
    cerr << "Bad operation " << operation << " detected in configuration file" << endl;
  }
@@ -765,6 +769,9 @@ double FGFunction::GetValue(void) const
    else //
    {temp = 1;}
    break;
+  case eMyFunction:
+    cerr << "FIXME: Implement myFunction!" << endl;
+    break;
  default:
    cerr << "Unknown function operation type" << endl;
    break;
diff --git a/src/math/FGFunction.h b/src/math/FGFunction.h
index 49d3e15..e5ba140 100644
--- a/src/math/FGFunction.h
+++ b/src/math/FGFunction.h
@@ -799,6 +799,7 @@ private:
  static const std::string ifthen_string;
  static const std::string switch_string;
  static const std::string interpolate1d_string;
+  static const std::string myfunction_string;
  double cachedValue;
  enum functionType {eTopLevel=0, eProduct, eDifference, eSum, eQuotient, ePow, eSqrt, eToRadians,
                      eToDegrees, eExp, eAbs, eSign, eSin, eCos, eTan, eASin, eACos, eATan, eATan2,
@@ -806,7 +807,7 @@ private:
                      eLog2, eLn, eLog10, eLT, eLE, eGE, eGT, eEQ, eNE,  eAND, eOR, eNOT,
                      eIfThen, eSwitch, eInterpolate1D, eRotation_alpha_local,
                      eRotation_beta_local, eRotation_gamma_local, eRotation_bf_to_wf,
-                    eRotation_wf_to_bf} Type;
+                    eRotation_wf_to_bf, eMyFunction } Type;
  std::string Name;
  std::string sCopyTo;        // Property name to copy function value to
  FGPropertyNode_ptr pCopyTo; // Property node for CopyTo property string


</syntaxhighlight>
</syntaxhighlight>

Navigation menu