summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/CommandParser.cc19
-rw-r--r--src/CommandParser.hh5
3 files changed, 24 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 6eb863c..523a59a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
1(Format: Year/Month/Day) 1(Format: Year/Month/Day)
2Changes for 0.9.16: 2Changes for 0.9.16:
3*06/04/22: 3*06/04/22:
4 * static CommandParser could be used after destruction (Simon)
5 Fixes sf.net #1474444, segfault when DISPLAY not set
6 CommmandParser.hh/cc
4 * Minor cosmetic changes, thanks Semushin Slava (php-coder AT ngs ru) 7 * Minor cosmetic changes, thanks Semushin Slava (php-coder AT ngs ru)
5 main.cc Screen.cc util/startfluxbox.in 8 main.cc Screen.cc util/startfluxbox.in
6 * First draft of new docs in docs/asciidoc (Mathias) 9 * First draft of new docs in docs/asciidoc (Mathias)
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;
32using FbTk::StringUtil::removeFirstWhitespace; 32using FbTk::StringUtil::removeFirstWhitespace;
33using FbTk::StringUtil::toLower; 33using FbTk::StringUtil::toLower;
34 34
35
36CommandParser *CommandParser::s_singleton = 0;
37
35CommandFactory::CommandFactory() { 38CommandFactory::CommandFactory() {
36 39
37} 40}
@@ -39,15 +42,24 @@ CommandFactory::CommandFactory() {
39CommandFactory::~CommandFactory() { 42CommandFactory::~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
44void CommandFactory::addCommand(const string &command_name) { 48void 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
53CommandParser::CommandParser() {
54 if (s_singleton != 0)
55 throw std::string("CommandParser currently meant ot be singleton");
56}
57
48CommandParser &CommandParser::instance() { 58CommandParser &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
53FbTk::Command *CommandParser::parseLine(const string &line) { 65FbTk::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}
diff --git a/src/CommandParser.hh b/src/CommandParser.hh
index 10f47aa..5501345 100644
--- a/src/CommandParser.hh
+++ b/src/CommandParser.hh
@@ -54,6 +54,8 @@ public:
54 /// @return parses and returns a command matching the line 54 /// @return parses and returns a command matching the line
55 FbTk::Command *parseLine(const std::string &line); 55 FbTk::Command *parseLine(const std::string &line);
56 56
57 CommandParser();
58
57 /// @return instance of command parser 59 /// @return instance of command parser
58 static CommandParser &instance(); 60 static CommandParser &instance();
59 /// @return map of factorys 61 /// @return map of factorys
@@ -71,7 +73,8 @@ private:
71 const std::string &arguments); 73 const std::string &arguments);
72 74
73 CommandFactoryMap m_commandfactorys; ///< a string to factory map 75 CommandFactoryMap m_commandfactorys; ///< a string to factory map
74 76
77 static CommandParser *s_singleton;
75}; 78};
76 79
77#endif // COMMANDPARSER_HH 80#endif // COMMANDPARSER_HH