40 #include "FGFDMExec.h"
41 #include "FGModelFunctions.h"
42 #include "input_output/FGXMLElement.h"
52 FGModelFunctions::~FGModelFunctions()
54 for (
auto prefunc: PreFunctions)
delete prefunc;
55 for (
auto postfunc: PostFunctions)
delete postfunc;
57 if (debug_lvl & 2) cout <<
"Destroyed: FGModelFunctions" << endl;
62 bool FGModelFunctions::InitModel(
void)
64 LocalProperties.ResetToIC();
71 bool FGModelFunctions::Load(Element* el, FGFDMExec* fdmex,
string prefix)
73 LocalProperties.Load(el, fdmex->GetPropertyManager(),
false);
74 PreLoad(el, fdmex, prefix);
81 void FGModelFunctions::PreLoad(Element* el, FGFDMExec* fdmex,
string prefix)
85 Element *
function = el->FindElement(
"function");
88 string fType =
function->GetAttributeValue(
"type");
89 if (fType.empty() || fType ==
"pre")
90 PreFunctions.push_back(
new FGFunction(fdmex,
function, prefix));
91 else if (fType ==
"template") {
92 string name =
function->GetAttributeValue(
"name");
93 fdmex->AddTemplateFunc(name,
function);
96 function = el->FindNextElement(
"function");
102 void FGModelFunctions::PostLoad(Element* el, FGFDMExec* fdmex,
string prefix)
106 Element *
function = el->FindElement(
"function");
108 if (function->GetAttributeValue(
"type") ==
"post") {
109 PostFunctions.push_back(
new FGFunction(fdmex,
function, prefix));
111 function = el->FindNextElement(
"function");
121 void FGModelFunctions::RunPreFunctions(
void)
123 for (
auto prefunc: PreFunctions)
124 prefunc->cacheValue(
true);
133 void FGModelFunctions::RunPostFunctions(
void)
135 for (
auto postfunc: PostFunctions)
136 postfunc->cacheValue(
true);
141 FGFunction* FGModelFunctions::GetPreFunction(
const std::string& name)
143 for (
auto prefunc: PreFunctions) {
144 if (prefunc->GetName() == name)
153 string FGModelFunctions::GetFunctionStrings(
const string& delimeter)
const
155 string FunctionStrings;
157 for (
auto prefunc: PreFunctions) {
158 if (!FunctionStrings.empty())
159 FunctionStrings += delimeter;
161 FunctionStrings += prefunc->
GetName();
164 for (
auto postfunc: PostFunctions) {
165 if (!FunctionStrings.empty())
166 FunctionStrings += delimeter;
168 FunctionStrings += postfunc->GetName();
171 return FunctionStrings;
176 string FGModelFunctions::GetFunctionValues(
const string& delimeter)
const
180 for (
auto prefunc: PreFunctions) {
181 if (buf.tellp() > 0) buf << delimeter;
182 buf << prefunc->GetValue();
185 for (
auto postfunc: PostFunctions) {
186 if (buf.tellp() > 0) buf << delimeter;
187 buf << postfunc->GetValue();