From: Tim Moore Date: Sun, 19 Jul 2009 21:05:04 +0000 (+0200) Subject: Create a singleton for the parser table X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=59ef7d8fd12da6a2651fd915f0bcefaedc0d7c28;p=simgear.git Create a singleton for the parser table --- diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index fa665030..16241487 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -690,11 +690,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) diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index 2dac8efb..1589aab1 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -31,6 +31,7 @@ #include #include #include +#include /// Expression tree implementation. @@ -1009,10 +1010,16 @@ namespace simgear class ExpressionParser : public Parser { public: - ParserMap& getParserMap() { return _parserTable; } + ParserMap& getParserMap() + { + return ParserMapSingleton::instance()->_parserTable; + } static void addExpParser(const std::string&, exp_parser); protected: - static ParserMap _parserTable; + struct ParserMapSingleton : public simgear::Singleton + { + ParserMap _parserTable; + }; }; /**