X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGExpression.cxx;h=d534aad07274fa698a28e4d4c6f248c905a19ab7;hb=4e46bb667179cd45cfb2f9934734ceddd1ea01b4;hp=4c746d885d74a34e5314058ab1706c86c71b7004;hpb=03b9303f229c605c72a1f8f74ee0a8e752770e65;p=simgear.git diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index 4c746d88..d534aad0 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -332,6 +332,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 +617,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) } return new SGTanhExpression(inputExpression); } - -// if (name == "table") { -// } + // if (name == "step") { // } // if (name == "condition") { @@ -682,44 +712,6 @@ namespace simgear namespace expression { -class Parser { -public: - void addParser(const std::string& name, exp_parser parser) - { - _parserTable.insert(std::make_pair(name, parser)); - } - Expression* read(const SGPropertyNode* exp) - { - ParserMap::iterator itr = _parserTable.find(exp->getName()); - if (itr == _parserTable.end()) - throw ParseError(string("unknown expression ") + exp->getName()); - exp_parser parser = itr->second; - return (*parser)(exp, this); - } - // XXX vector of SGSharedPtr? - bool readChildren(const SGPropertyNode* exp, - vector& result); -protected: - typedef std::map ParserMap; - ParserMap _parserTable; -}; - -class ExpressionParser : public Parser, public Singleton -{ -}; - -void addExpParser(const string& token, exp_parser parsefn) -{ - ExpressionParser::instance()->addParser(token, parsefn); -} - -Expression* read(const SGPropertyNode* exp, Parser* parser) -{ - if (!parser) - parser = ExpressionParser::instance(); - return parser->read(exp); -} - bool Parser::readChildren(const SGPropertyNode* exp, vector& result) { @@ -728,6 +720,12 @@ bool Parser::readChildren(const SGPropertyNode* exp, return true; } +void ExpressionParser::addExpParser(const string& token, exp_parser parsefn) +{ + ParserMapSingleton::instance() + ->_parserTable.insert(std::make_pair(token, parsefn)); +} + Expression* valueParser(const SGPropertyNode* exp, Parser* parser) { switch (exp->getType()) { @@ -867,10 +865,14 @@ Expression* logicopParser(const SGPropertyNode* exp, Parser* parser) ExpParserRegistrar andRegistrar("and", logicopParser); ExpParserRegistrar orRegistrar("or", logicopParser); - 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); + if (itr != bindings.end()) + return itr->location; int result = bindings.size(); bindings.push_back(VariableBinding(name, type, bindings.size())); return result;