Create a singleton for the parser table

This commit is contained in:
Tim Moore
2009-07-19 23:05:04 +02:00
parent 1f308c9ec3
commit 59ef7d8fd1
2 changed files with 11 additions and 5 deletions

View File

@@ -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)

View File

@@ -31,6 +31,7 @@
#include <simgear/math/SGMath.hxx>
#include <simgear/scene/model/persparam.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/structure/Singleton.hxx>
/// 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<ParserMapSingleton>
{
ParserMap _parserTable;
};
};
/**