diff options
author | simonb <simonb> | 2006-04-22 12:16:38 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-04-22 12:16:38 (GMT) |
commit | de4dfdad163abaff265adde0af4ff48e7424d7af (patch) | |
tree | 7c747ac158803e3d452b9570f0bbb70c279d851d /src/CommandParser.cc | |
parent | 1028f4cb51ea998f475ec9ffc61aac164d0ca793 (diff) | |
download | fluxbox_pavel-de4dfdad163abaff265adde0af4ff48e7424d7af.zip fluxbox_pavel-de4dfdad163abaff265adde0af4ff48e7424d7af.tar.bz2 |
fix static management of CommandParser, sf.net 1474444
Diffstat (limited to 'src/CommandParser.cc')
-rw-r--r-- | src/CommandParser.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/CommandParser.cc b/src/CommandParser.cc index 6fcb771..1f8218e 100644 --- a/src/CommandParser.cc +++ b/src/CommandParser.cc | |||
@@ -32,6 +32,9 @@ using std::vector; | |||
32 | using FbTk::StringUtil::removeFirstWhitespace; | 32 | using FbTk::StringUtil::removeFirstWhitespace; |
33 | using FbTk::StringUtil::toLower; | 33 | using FbTk::StringUtil::toLower; |
34 | 34 | ||
35 | |||
36 | CommandParser *CommandParser::s_singleton = 0; | ||
37 | |||
35 | CommandFactory::CommandFactory() { | 38 | CommandFactory::CommandFactory() { |
36 | 39 | ||
37 | } | 40 | } |
@@ -39,15 +42,24 @@ CommandFactory::CommandFactory() { | |||
39 | CommandFactory::~CommandFactory() { | 42 | CommandFactory::~CommandFactory() { |
40 | // remove all associations with this factory | 43 | // remove all associations with this factory |
41 | CommandParser::instance().removeAssociation(*this); | 44 | CommandParser::instance().removeAssociation(*this); |
45 | |||
42 | } | 46 | } |
43 | 47 | ||
44 | void CommandFactory::addCommand(const string &command_name) { | 48 | void CommandFactory::addCommand(const string &command_name) { |
45 | CommandParser::instance().associateCommand(command_name, *this); | 49 | CommandParser::instance().associateCommand(command_name, *this); |
46 | } | 50 | } |
47 | 51 | ||
52 | // ensure it is singleton | ||
53 | CommandParser::CommandParser() { | ||
54 | if (s_singleton != 0) | ||
55 | throw std::string("CommandParser currently meant ot be singleton"); | ||
56 | } | ||
57 | |||
48 | CommandParser &CommandParser::instance() { | 58 | CommandParser &CommandParser::instance() { |
49 | static CommandParser singleton; | 59 | if (s_singleton == 0) |
50 | return singleton; | 60 | s_singleton = new CommandParser(); |
61 | |||
62 | return *s_singleton; | ||
51 | } | 63 | } |
52 | 64 | ||
53 | FbTk::Command *CommandParser::parseLine(const string &line) { | 65 | FbTk::Command *CommandParser::parseLine(const string &line) { |
@@ -105,4 +117,7 @@ void CommandParser::removeAssociation(CommandFactory &factory) { | |||
105 | m_commandfactorys.erase(commands.back()); | 117 | m_commandfactorys.erase(commands.back()); |
106 | commands.pop_back(); | 118 | commands.pop_back(); |
107 | } | 119 | } |
120 | |||
121 | if (m_commandfactorys.empty()) | ||
122 | delete s_singleton; | ||
108 | } | 123 | } |