44 #include "FGModelFunctions.h" 45 #include "FGFunction.h" 46 #include "input_output/FGXMLElement.h" 52 IDENT(IdSrc,
"$Id: FGModelFunctions.cpp,v 1.15 2015/03/28 14:49:01 bcoconni Exp $");
53 IDENT(IdHdr,ID_MODELFUNCTIONS);
59 FGModelFunctions::~FGModelFunctions()
61 for (
unsigned int i=0; i<PreFunctions.size(); i++)
delete PreFunctions[i];
62 for (
unsigned int i=0; i<PostFunctions.size(); i++)
delete PostFunctions[i];
64 if (debug_lvl & 2) cout <<
"Destroyed: FGModelFunctions" << endl;
69 bool FGModelFunctions::InitModel(
void)
71 LocalProperties.ResetToIC();
78 bool FGModelFunctions::Load(Element* el, FGPropertyManager* PM,
string prefix)
80 LocalProperties.Load(el, PM,
false);
81 PreLoad(el, PM, prefix);
88 void FGModelFunctions::PreLoad(Element* el, FGPropertyManager* PM,
string prefix)
92 Element *
function = el->FindElement(
"function");
95 string fType =
function->GetAttributeValue(
"type");
96 if (fType.empty() || fType ==
"pre")
97 PreFunctions.push_back(
new FGFunction(PM,
function, prefix));
99 function = el->FindNextElement(
"function");
105 void FGModelFunctions::PostLoad(Element* el, FGPropertyManager* PM,
string prefix)
109 Element *
function = el->FindElement(
"function");
111 if (function->GetAttributeValue(
"type") ==
"post") {
112 PostFunctions.push_back(
new FGFunction(PM,
function, prefix));
114 function = el->FindNextElement(
"function");
124 void FGModelFunctions::RunPreFunctions(
void)
126 size_t sz = PreFunctions.size();
127 for (
unsigned int i=0; i<sz; i++) {
128 PreFunctions[i]->cacheValue(
true);
138 void FGModelFunctions::RunPostFunctions(
void)
140 size_t sz = PostFunctions.size();
141 for (
unsigned int i=0; i<sz; i++) {
142 PostFunctions[i]->cacheValue(
true);
148 FGFunction* FGModelFunctions::GetPreFunction(
const std::string& name)
151 vector<FGFunction*>::iterator it = PreFunctions.begin();
153 for (; it != PreFunctions.end(); ++it) {
164 string FGModelFunctions::GetFunctionStrings(
const string& delimeter)
const 166 string FunctionStrings =
"";
167 bool firstime =
true;
170 for (sd = 0; sd < PreFunctions.size(); sd++) {
174 FunctionStrings += delimeter;
176 FunctionStrings += PreFunctions[sd]->
GetName();
179 for (sd = 0; sd < PostFunctions.size(); sd++) {
183 FunctionStrings += delimeter;
185 FunctionStrings += PostFunctions[sd]->GetName();
188 return FunctionStrings;
193 string FGModelFunctions::GetFunctionValues(
const string& delimeter)
const 197 for (
unsigned int sd = 0; sd < PreFunctions.size(); sd++) {
198 if (buf.tellp() > 0) buf << delimeter;
199 buf << PreFunctions[sd]->GetValue();
202 for (
unsigned int sd = 0; sd < PostFunctions.size(); sd++) {
203 if (buf.tellp() > 0) buf << delimeter;
204 buf << PostFunctions[sd]->GetValue();
std::string GetName(void) const
Retrieves the name of the function.
Represents a mathematical function.