diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-17 22:16:58 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-17 22:16:58 (GMT) |
commit | 3a5fd7342d6cfd00acafeec4c1f35948a550e4ab (patch) | |
tree | 63986359afdcae9015e557c757e8c1819c473b05 | |
parent | c6099d777d844699fb8a4243921159898bc4f45c (diff) | |
download | fluxbox-3a5fd7342d6cfd00acafeec4c1f35948a550e4ab.zip fluxbox-3a5fd7342d6cfd00acafeec4c1f35948a550e4ab.tar.bz2 |
use function pointer for CommandParser::Command
-rw-r--r-- | src/CommandDialog.cc | 4 | ||||
-rw-r--r-- | src/FbTk/CommandParser.hh | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc index 346a1a4..37e7bdd 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::ObjectRegistry<FbTk::CommandParser<void>::Creator>::CreatorMap::const_iterator it = FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::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::ObjectRegistry<FbTk::CommandParser<void>::Creator>::CreatorMap::const_iterator it_end = FbTk::ObjectRegistry<FbTk::CommandParser<void>::Creator>::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 89cac7d..006036d 100644 --- a/src/FbTk/CommandParser.hh +++ b/src/FbTk/CommandParser.hh | |||
@@ -32,7 +32,7 @@ namespace FbTk { | |||
32 | // helper for registering a function to parse arguments | 32 | // helper for registering a function to parse arguments |
33 | #define REGISTER_COMMAND_PARSER(name, parser, type) \ | 33 | #define REGISTER_COMMAND_PARSER(name, parser, type) \ |
34 | namespace { \ | 34 | namespace { \ |
35 | static const bool p_register_command_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, parser); \ | 35 | static const bool p_register_command_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, &parser); \ |
36 | } | 36 | } |
37 | 37 | ||
38 | // include some basic Command<void> creators | 38 | // include some basic Command<void> creators |
@@ -44,7 +44,7 @@ Command<Type> *CommandCreator(const string &name, const string &args, | |||
44 | 44 | ||
45 | #define REGISTER_COMMAND(name, classname, type) \ | 45 | #define REGISTER_COMMAND(name, classname, type) \ |
46 | namespace { \ | 46 | namespace { \ |
47 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, FbTk::CommandCreator<classname, type>); \ | 47 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, &FbTk::CommandCreator<classname, type>); \ |
48 | } | 48 | } |
49 | 49 | ||
50 | template <typename ClassName, typename Type> | 50 | template <typename ClassName, typename Type> |
@@ -55,7 +55,7 @@ Command<Type> *CommandCreatorWithArgs(const string &name, const string &args, | |||
55 | 55 | ||
56 | #define REGISTER_COMMAND_WITH_ARGS(name, classname, type) \ | 56 | #define REGISTER_COMMAND_WITH_ARGS(name, classname, type) \ |
57 | namespace { \ | 57 | namespace { \ |
58 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, FbTk::CommandCreatorWithArgs<classname, type>); \ | 58 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, &FbTk::CommandCreatorWithArgs<classname, type>); \ |
59 | } | 59 | } |
60 | 60 | ||
61 | template <typename ClassName, typename Type> | 61 | template <typename ClassName, typename Type> |
@@ -67,7 +67,7 @@ Command<Type> *UntrustedCommandCreator(const string &name, const string &args, | |||
67 | 67 | ||
68 | #define REGISTER_UNTRUSTED_COMMAND(name, classname, type) \ | 68 | #define REGISTER_UNTRUSTED_COMMAND(name, classname, type) \ |
69 | namespace { \ | 69 | namespace { \ |
70 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, FbTk::UntrustedCommandCreator<classname, type>); \ | 70 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, &FbTk::UntrustedCommandCreator<classname, type>); \ |
71 | } | 71 | } |
72 | 72 | ||
73 | template <typename ClassName, typename Type> | 73 | template <typename ClassName, typename Type> |
@@ -79,13 +79,13 @@ Command<Type> *UntrustedCommandCreatorWithArgs(const string &name, | |||
79 | 79 | ||
80 | #define REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(name, classname, type) \ | 80 | #define REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(name, classname, type) \ |
81 | namespace { \ | 81 | namespace { \ |
82 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, FbTk::UntrustedCommandCreatorWithArgs<classname, type>); \ | 82 | static const bool p_register_##type_##name = FbTk::CommandParser<type>::instance().registerCommand(#name, &FbTk::UntrustedCommandCreatorWithArgs<classname, type>); \ |
83 | } | 83 | } |
84 | 84 | ||
85 | template <typename Type> | 85 | template <typename Type> |
86 | class CommandParser { | 86 | class CommandParser { |
87 | public: | 87 | public: |
88 | typedef Command<Type> *Creator(const string &, const string &, bool); | 88 | typedef Command<Type> *(*Creator)(const string &, const string &, bool); |
89 | 89 | ||
90 | static CommandParser<Type> &instance() { | 90 | static CommandParser<Type> &instance() { |
91 | static CommandParser<Type> s_instance; | 91 | static CommandParser<Type> s_instance; |
@@ -95,7 +95,7 @@ public: | |||
95 | Command<Type> *parse(const string &name, const string &args, | 95 | Command<Type> *parse(const string &name, const string &args, |
96 | bool trusted = true) const { | 96 | bool trusted = true) const { |
97 | string lc = StringUtil::toLower(name); | 97 | string lc = StringUtil::toLower(name); |
98 | Creator *creator = ObjectRegistry<Creator *>::instance().lookup(lc); | 98 | Creator creator = ObjectRegistry<Creator>::instance().lookup(lc); |
99 | if (creator) | 99 | if (creator) |
100 | return creator(lc, args, trusted); | 100 | return creator(lc, args, trusted); |
101 | return 0; | 101 | return 0; |
@@ -114,7 +114,7 @@ public: | |||
114 | 114 | ||
115 | bool registerCommand(string name, Creator creator) { | 115 | bool registerCommand(string name, Creator creator) { |
116 | name = StringUtil::toLower(name); | 116 | name = StringUtil::toLower(name); |
117 | return ObjectRegistry<Creator *>::instance().registerObject(name, | 117 | return ObjectRegistry<Creator>::instance().registerObject(name, |
118 | creator); | 118 | creator); |
119 | } | 119 | } |
120 | 120 | ||