57 : Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr),
60 InitializeConditionals();
64 if (logic ==
"OR") Logic = eOR;
65 else if (logic ==
"AND") Logic = eAND;
68 <<
"Unrecognized LOGIC token " << logic << endl;
69 throw std::invalid_argument(
"JSBSim FGCondition: unrecognized logic value:'" + logic +
"'");
77 conditions.push_back(
new FGCondition(data, PropertyManager, element));
81 const string& elName = element->
GetName();
83 while (condition_element) {
84 string tagName = condition_element->
GetName();
86 if (tagName != elName) {
87 cerr << condition_element->
ReadFrom()
88 <<
"Unrecognized tag <" << tagName <<
"> in the condition statement."
90 throw std::invalid_argument(
"JSBSim FGCondition: unrecognized tag:'" + tagName +
"'");
93 conditions.push_back(
new FGCondition(condition_element, PropertyManager));
106 : Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr),
109 InitializeConditionals();
111 vector<string> test_strings =
split(test,
' ');
113 if (test_strings.size() == 3) {
115 conditional = test_strings[1];
119 <<
" Conditional test is invalid: \"" << test
120 <<
"\" has " << test_strings.size() <<
" elements in the "
121 <<
"test condition." << endl;
122 throw std::invalid_argument(
"JSBSim FGCondition: incorrect numner of test elments:" + std::to_string(test_strings.size()));
125 Comparison = mComparison[conditional];
126 if (Comparison == ecUndef) {
127 throw std::invalid_argument(
"JSBSim FGCondition: Comparison operator: \""+conditional
128 +
"\" does not exist. Please check the conditional.");
134void FGCondition::InitializeConditionals(
void)
136 mComparison[
"EQ"] = eEQ;
137 mComparison[
"NE"] = eNE;
138 mComparison[
"GT"] = eGT;
139 mComparison[
"GE"] = eGE;
140 mComparison[
"LT"] = eLT;
141 mComparison[
"LE"] = eLE;
142 mComparison[
"eq"] = eEQ;
143 mComparison[
"ne"] = eNE;
144 mComparison[
"gt"] = eGT;
145 mComparison[
"ge"] = eGE;
146 mComparison[
"lt"] = eLT;
147 mComparison[
"le"] = eLE;
148 mComparison[
"=="] = eEQ;
149 mComparison[
"!="] = eNE;
150 mComparison[
">"] = eGT;
151 mComparison[
">="] = eGE;
152 mComparison[
"<"] = eLT;
153 mComparison[
"<="] = eLE;
160 for (
auto cond: conditions)
delete cond;
176 for (
auto cond: conditions) {
177 if (!cond->Evaluate()) pass =
false;
183 for (
auto cond: conditions) {
184 if (cond->Evaluate()) pass =
true;
191 double compareValue = TestParam2->GetValue();
193 switch (Comparison) {
195 cerr <<
"Undefined comparison operator." << endl;
198 pass = TestParam1->getDoubleValue() == compareValue;
201 pass = TestParam1->getDoubleValue() != compareValue;
204 pass = TestParam1->getDoubleValue() > compareValue;
207 pass = TestParam1->getDoubleValue() >= compareValue;
210 pass = TestParam1->getDoubleValue() < compareValue;
213 pass = TestParam1->getDoubleValue() <= compareValue;
216 cerr <<
"Unknown comparison operator." << endl;
229 if (!conditions.empty()) {
234 cerr <<
"unset logic for test condition" << endl;
237 scratch = indent +
"if all of the following are true: {";
240 scratch = indent +
"if any of the following are true: {";
243 scratch =
" UNKNOWN";
244 cerr <<
"Unknown logic for test condition" << endl;
246 cout << scratch << endl;
248 for (
auto cond: conditions) {
249 cond->PrintCondition(indent +
" ");
253 cout << indent <<
"}";
256 cout << indent << TestParam1->GetName() <<
" " << conditional
257 <<
" " << TestParam2->GetName();
280void FGCondition::Debug(
int from)
290 if (from == 0) cout <<
"Instantiated: FGCondition" << endl;
291 if (from == 1) cout <<
"Destroyed: FGCondition" << endl;
const std::string & GetName(void) const
Retrieves the element name.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element * GetNextElement(void)
Returns a pointer to the next element in the list.
unsigned int GetNumDataLines(void)
Returns the number of lines of data stored.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * GetElement(unsigned int el=0)
Returns a pointer to the element requested by index.
FGCondition(Element *element, FGPropertyManager *PropertyManager)
void PrintCondition(std::string indent=" ")
Represents a either a real value or a property value.
Represents a property value which can use late binding.
std::vector< std::string > split(std::string str, char d)