X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGExpression.cxx;h=a6776636a0eba906dc6b070ea4251d1c0e9f012a;hb=200df49d6e2d8896e1deaa6da7af5b4a91058a4f;hp=fa6650300fce9a0bf55f395b91b805ae4f6eb01b;hpb=efec9070e178c9aef98332cb03d967868179ae4a;p=simgear.git diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index fa665030..a6776636 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -33,6 +33,7 @@ #include #include #include +#include // for strcmp #include @@ -332,6 +333,38 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) return output; } + if (name == "table") { + SGInterpTable* tab = new SGInterpTable(expression); + if (!tab) { + SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression: malformed table"); + return 0; + } + + // find input expression - i.e a child not named 'entry' + const SGPropertyNode* inputNode = NULL; + for (int i=0; (inChildren()) && !inputNode; ++i) { + if (strcmp(expression->getChild(i)->getName(), "entry") == 0) { + continue; + } + + inputNode = expression->getChild(i); + } + + if (!inputNode) { + SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression: no input found"); + return 0; + } + + SGSharedPtr > inputExpression; + inputExpression = SGReadIExpression(inputRoot, inputNode); + if (!inputExpression) { + SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression."); + return 0; + } + + return new SGInterpTableExpression(inputExpression, tab); + } + return 0; } @@ -585,9 +618,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) } return new SGTanhExpression(inputExpression); } - -// if (name == "table") { -// } + // if (name == "step") { // } // if (name == "condition") { @@ -690,11 +721,10 @@ bool Parser::readChildren(const SGPropertyNode* exp, return true; } -Parser::ParserMap ExpressionParser::_parserTable; - void ExpressionParser::addExpParser(const string& token, exp_parser parsefn) { - _parserTable.insert(std::make_pair(token, parsefn)); + ParserMapSingleton::instance() + ->_parserTable.insert(std::make_pair(token, parsefn)); } Expression* valueParser(const SGPropertyNode* exp, Parser* parser) @@ -825,7 +855,7 @@ Expression* logicopParser(const SGPropertyNode* exp, Parser* parser) parser->readChildren(exp, children); vector::iterator notBool = find_if(children.begin(), children.end(), - bind(&Expression::getType, _1) != BOOL); + boost::bind(&Expression::getType, _1) != BOOL); if (notBool != children.end()) throw("non boolean operand to logical expression"); Logicop *expr = new Logicop; @@ -841,7 +871,7 @@ int BindingLayout::addBinding(const string& name, Type type) //XXX error checkint vector::iterator itr = find_if(bindings.begin(), bindings.end(), - bind(&VariableBinding::name, _1) == name); + boost::bind(&VariableBinding::name, _1) == name); if (itr != bindings.end()) return itr->location; int result = bindings.size(); @@ -856,7 +886,7 @@ bool BindingLayout::findBinding(const std::string& name, using namespace boost; vector::const_iterator itr = find_if(bindings.begin(), bindings.end(), - bind(&VariableBinding::name, _1) == name); + boost::bind(&VariableBinding::name, _1) == name); if (itr != bindings.end()) { result = *itr; return true;