Date started: 8/25/2004
Purpose: Stores various parameter types for functions
- ------------- Copyright (C) 2004 Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2004 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#include <stdio.h>
-
+#include <sstream>
+#include <iomanip>
+#include <cstdlib>
+#include <cmath>
#include "FGFunction.h"
#include "FGTable.h"
#include "FGPropertyValue.h"
#include "FGRealValue.h"
+#include "input_output/FGXMLElement.h"
+#include "input_output/FGPropertyManager.h"
+
+using namespace std;
namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, string prefix)
+FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& prefix)
: PropertyManager(propMan), Prefix(prefix)
{
Element* element;
string operation, property_name;
- int size = el->GetNumElements();
cached = false;
cachedValue = -HUGE_VAL;
+ invlog2val = 1.0/log10(2.0);
property_string = "property";
value_string = "value";
quotient_string = "quotient";
pow_string = "pow";
exp_string = "exp";
+ log2_string = "log2";
+ ln_string = "ln";
+ log10_string = "log10";
abs_string = "abs";
sin_string = "sin";
cos_string = "cos";
Type = eQuotient;
} else if (operation == pow_string) {
Type = ePow;
+ } else if (operation == log2_string) {
+ Type = eLog2;
+ } else if (operation == ln_string) {
+ Type = eLn;
+ } else if (operation == log10_string) {
+ Type = eLog10;
} else if (operation == abs_string) {
Type = eAbs;
} else if (operation == sin_string) {
operation == quotient_string ||
operation == pow_string ||
operation == exp_string ||
+ operation == log2_string ||
+ operation == ln_string ||
+ operation == log10_string ||
operation == abs_string ||
operation == sin_string ||
operation == cos_string ||
case eExp:
temp = exp(temp);
break;
+ case eLog2:
+ if (temp > 0.00) temp = log10(temp)*invlog2val;
+ else temp = -HUGE_VAL;
+ break;
+ case eLn:
+ if (temp > 0.00) temp = log(temp);
+ else temp = -HUGE_VAL;
+ break;
+ case eLog10:
+ if (temp > 0.00) temp = log10(temp);
+ else temp = -HUGE_VAL;
+ break;
case eAbs:
temp = fabs(temp);
break;
string FGFunction::GetValueAsString(void) const
{
- char buffer[20];
- string value;
+ ostringstream buffer;
- sprintf(buffer,"%9.6f",GetValue());
- value = string(buffer);
- return value;
+ buffer << setw(9) << setprecision(6) << GetValue();
+ return buffer.str();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGFunction::bind(void)
{
if ( !Name.empty() ) {
- string tmp = PropertyManager->mkPropertyName(Prefix + Name, false); // Allow upper case
+ string tmp;
+ if (Prefix.empty())
+ tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper case
+ else
+ tmp = PropertyManager->mkPropertyName(Prefix + "/" + Name, false); // Allow upper case
+
PropertyManager->Tie( tmp, this, &FGFunction::GetValue);
}
}