aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/CommandParser.hh
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-06-03 07:15:37 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-06-03 07:15:37 (GMT)
commitbfaec62d795ffe17ef82640efa06be6b056475cc (patch)
tree91905e4bc986a8b220dc38bd9b40eeb8ad37477d /src/FbTk/CommandParser.hh
parentb7e693c42518a2558d9a18b9eab6a55122ce1f43 (diff)
downloadfluxbox_pavel-bfaec62d795ffe17ef82640efa06be6b056475cc.zip
fluxbox_pavel-bfaec62d795ffe17ef82640efa06be6b056475cc.tar.bz2
remove some unnecessary architecture
Diffstat (limited to 'src/FbTk/CommandParser.hh')
-rw-r--r--src/FbTk/CommandParser.hh24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/FbTk/CommandParser.hh b/src/FbTk/CommandParser.hh
index 006036d..45ce001 100644
--- a/src/FbTk/CommandParser.hh
+++ b/src/FbTk/CommandParser.hh
@@ -22,9 +22,11 @@
22#ifndef CommandParser_HH 22#ifndef CommandParser_HH
23#define CommandParser_HH 23#define CommandParser_HH
24 24
25#include "ObjectRegistry.hh"
26#include "StringUtil.hh" 25#include "StringUtil.hh"
27 26
27#include <string>
28#include <map>
29
28using std::string; 30using std::string;
29 31
30namespace FbTk { 32namespace FbTk {
@@ -86,6 +88,7 @@ template <typename Type>
86class CommandParser { 88class CommandParser {
87public: 89public:
88 typedef Command<Type> *(*Creator)(const string &, const string &, bool); 90 typedef Command<Type> *(*Creator)(const string &, const string &, bool);
91 typedef std::map<std::string, Creator> CreatorMap;
89 92
90 static CommandParser<Type> &instance() { 93 static CommandParser<Type> &instance() {
91 static CommandParser<Type> s_instance; 94 static CommandParser<Type> s_instance;
@@ -93,9 +96,9 @@ public:
93 } 96 }
94 97
95 Command<Type> *parse(const string &name, const string &args, 98 Command<Type> *parse(const string &name, const string &args,
96 bool trusted = true) const { 99 bool trusted = true) const {
97 string lc = StringUtil::toLower(name); 100 string lc = StringUtil::toLower(name);
98 Creator creator = ObjectRegistry<Creator>::instance().lookup(lc); 101 Creator creator = lookup(lc);
99 if (creator) 102 if (creator)
100 return creator(lc, args, trusted); 103 return creator(lc, args, trusted);
101 return 0; 104 return 0;
@@ -114,13 +117,24 @@ public:
114 117
115 bool registerCommand(string name, Creator creator) { 118 bool registerCommand(string name, Creator creator) {
116 name = StringUtil::toLower(name); 119 name = StringUtil::toLower(name);
117 return ObjectRegistry<Creator>::instance().registerObject(name, 120 m_creators[name] = creator;
118 creator); 121 return true;
122 }
123
124 Creator lookup(const std::string &name) const {
125 typename CreatorMap::const_iterator it = m_creators.find(name);
126 if (it == m_creators.end())
127 return 0;
128 return it->second;
119 } 129 }
120 130
131 const CreatorMap creatorMap() const { return m_creators; }
132
121private: 133private:
122 CommandParser() {} 134 CommandParser() {}
123 ~CommandParser() {} 135 ~CommandParser() {}
136
137 CreatorMap m_creators;
124}; 138};
125 139
126} // end namespace FbTk 140} // end namespace FbTk