40 #include "FGFDMExec.h"
41 #include "FGModelFunctions.h"
42 #include "input_output/FGXMLElement.h"
52 bool FGModelFunctions::InitModel(
void)
54 LocalProperties.ResetToIC();
61 bool FGModelFunctions::Load(Element* el, FGFDMExec* fdmex,
string prefix)
63 LocalProperties.Load(el, fdmex->GetPropertyManager().get(),
false);
64 PreLoad(el, fdmex, prefix);
71 void FGModelFunctions::PreLoad(Element* el, FGFDMExec* fdmex,
string prefix)
75 Element *
function = el->FindElement(
"function");
78 string fType =
function->GetAttributeValue(
"type");
79 if (fType.empty() || fType ==
"pre")
80 PreFunctions.push_back(std::make_shared<FGFunction>(fdmex,
function, prefix));
81 else if (fType ==
"template") {
82 string name =
function->GetAttributeValue(
"name");
83 fdmex->AddTemplateFunc(name,
function);
86 function = el->FindNextElement(
"function");
92 void FGModelFunctions::PostLoad(Element* el, FGFDMExec* fdmex,
string prefix)
96 Element *
function = el->FindElement(
"function");
98 if (function->GetAttributeValue(
"type") ==
"post") {
99 PostFunctions.push_back(std::make_shared<FGFunction>(fdmex,
function, prefix));
101 function = el->FindNextElement(
"function");
111 void FGModelFunctions::RunPreFunctions(
void)
113 for (
auto& prefunc: PreFunctions)
114 prefunc->cacheValue(
true);
123 void FGModelFunctions::RunPostFunctions(
void)
125 for (
auto& postfunc: PostFunctions)
126 postfunc->cacheValue(
true);
131 std::shared_ptr<FGFunction> FGModelFunctions::GetPreFunction(
const std::string& name)
133 for (
auto& prefunc: PreFunctions) {
134 if (prefunc->GetName() == name)
143 string FGModelFunctions::GetFunctionStrings(
const string& delimeter)
const
145 string FunctionStrings;
147 for (
auto& prefunc: PreFunctions) {
148 if (!FunctionStrings.empty())
149 FunctionStrings += delimeter;
151 FunctionStrings += prefunc->GetName();
154 for (
auto& postfunc: PostFunctions) {
155 if (!FunctionStrings.empty())
156 FunctionStrings += delimeter;
158 FunctionStrings += postfunc->GetName();
161 return FunctionStrings;
166 string FGModelFunctions::GetFunctionValues(
const string& delimeter)
const
170 for (
auto& prefunc: PreFunctions) {
171 if (buf.tellp() > 0) buf << delimeter;
172 buf << prefunc->GetValue();
175 for (
auto& postfunc: PostFunctions) {
176 if (buf.tellp() > 0) buf << delimeter;
177 buf << postfunc->GetValue();