aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentb7e693c42518a2558d9a18b9eab6a55122ce1f43 (diff)
downloadfluxbox_paul-bfaec62d795ffe17ef82640efa06be6b056475cc.zip
fluxbox_paul-bfaec62d795ffe17ef82640efa06be6b056475cc.tar.bz2
remove some unnecessary architecture
Diffstat (limited to 'src')
-rw-r--r--src/CommandDialog.cc4
-rw-r--r--src/FbTk/CommandParser.hh24
-rw-r--r--src/FbTk/Makefile.am2
-rw-r--r--src/FbTk/ObjectRegistry.hh63
4 files changed, 22 insertions, 71 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc
index 37e7bdd..3746b98 100644
--- a/src/CommandDialog.cc
+++ b/src/CommandDialog.cc
@@ -167,8 +167,8 @@ void CommandDialog::tabComplete() {
167 return; 167 return;
168 } 168 }
169 169
170 FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::CreatorMap::const_iterator it = FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::instance().creatorMap().begin(); 170 FbTk::CommandParser<void>::CreatorMap::const_iterator it = FbTk::CommandParser<void>::instance().creatorMap().begin();
171 const FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::CreatorMap::const_iterator it_end = FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::instance().creatorMap().end(); 171 const FbTk::CommandParser<void>::CreatorMap::const_iterator it_end = FbTk::CommandParser<void>::instance().creatorMap().end();
172 vector<string> matches; 172 vector<string> matches;
173 for (; it != it_end; ++it) { 173 for (; it != it_end; ++it) {
174 if ((*it).first.find(prefix) == 0) { 174 if ((*it).first.find(prefix) == 0) {
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
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index f830e4a..ad5a048 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -16,7 +16,7 @@ imlib2_SOURCE= ImageImlib2.hh ImageImlib2.cc
16endif 16endif
17 17
18libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ 18libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
19 ObjectRegistry.hh Accessor.hh DefaultValue.hh \ 19 Accessor.hh DefaultValue.hh \
20 FileUtil.hh FileUtil.cc \ 20 FileUtil.hh FileUtil.cc \
21 EventHandler.hh EventManager.hh EventManager.cc \ 21 EventHandler.hh EventManager.hh EventManager.cc \
22 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \ 22 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \
diff --git a/src/FbTk/ObjectRegistry.hh b/src/FbTk/ObjectRegistry.hh
deleted file mode 100644
index 4f47b77..0000000
--- a/src/FbTk/ObjectRegistry.hh
+++ /dev/null
@@ -1,63 +0,0 @@
1// ObjectRegistry.hh for FbTk
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#ifndef OBJECTREGISTRY_HH
23#define OBJECTREGISTRY_HH
24
25#include <map>
26#include <string>
27
28namespace FbTk {
29
30template <typename Creator>
31class ObjectRegistry {
32public:
33 typedef std::map<std::string, Creator> CreatorMap;
34
35 static ObjectRegistry<Creator> &instance() {
36 static ObjectRegistry<Creator> s_instance;
37 return s_instance;
38 }
39
40 Creator lookup(const std::string &name) {
41 typename CreatorMap::const_iterator it = m_creators.find(name);
42 if (it == m_creators.end())
43 return 0;
44 return it->second;
45 }
46
47 bool registerObject(const std::string &name, Creator creator) {
48 m_creators[name] = creator;
49 return true;
50 }
51
52 const CreatorMap creatorMap() const { return m_creators; }
53
54private:
55 ObjectRegistry() {}
56 ~ObjectRegistry() {}
57
58 CreatorMap m_creators;
59};
60
61} // end namespace FbTk
62
63#endif // OBJECTREGISTRY_HH