From 3a5fd7342d6cfd00acafeec4c1f35948a550e4ab Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Thu, 17 Jan 2008 14:16:58 -0800 Subject: use function pointer for CommandParser::Command --- src/CommandDialog.cc | 4 ++-- 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() { return; } - FbTk::ObjectRegistry::Creator *>::CreatorMap::const_iterator it = FbTk::ObjectRegistry::Creator *>::instance().creatorMap().begin(); - const FbTk::ObjectRegistry::Creator *>::CreatorMap::const_iterator it_end = FbTk::ObjectRegistry::Creator *>::instance().creatorMap().end(); + FbTk::ObjectRegistry::Creator>::CreatorMap::const_iterator it = FbTk::ObjectRegistry::Creator>::instance().creatorMap().begin(); + const FbTk::ObjectRegistry::Creator>::CreatorMap::const_iterator it_end = FbTk::ObjectRegistry::Creator>::instance().creatorMap().end(); vector matches; for (; it != it_end; ++it) { 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 { // helper for registering a function to parse arguments #define REGISTER_COMMAND_PARSER(name, parser, type) \ namespace { \ - static const bool p_register_command_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, parser); \ + static const bool p_register_command_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, &parser); \ } // include some basic Command creators @@ -44,7 +44,7 @@ Command *CommandCreator(const string &name, const string &args, #define REGISTER_COMMAND(name, classname, type) \ namespace { \ - static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, FbTk::CommandCreator); \ + static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, &FbTk::CommandCreator); \ } template @@ -55,7 +55,7 @@ Command *CommandCreatorWithArgs(const string &name, const string &args, #define REGISTER_COMMAND_WITH_ARGS(name, classname, type) \ namespace { \ - static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, FbTk::CommandCreatorWithArgs); \ + static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, &FbTk::CommandCreatorWithArgs); \ } template @@ -67,7 +67,7 @@ Command *UntrustedCommandCreator(const string &name, const string &args, #define REGISTER_UNTRUSTED_COMMAND(name, classname, type) \ namespace { \ - static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, FbTk::UntrustedCommandCreator); \ + static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, &FbTk::UntrustedCommandCreator); \ } template @@ -79,13 +79,13 @@ Command *UntrustedCommandCreatorWithArgs(const string &name, #define REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(name, classname, type) \ namespace { \ - static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, FbTk::UntrustedCommandCreatorWithArgs); \ + static const bool p_register_##type_##name = FbTk::CommandParser::instance().registerCommand(#name, &FbTk::UntrustedCommandCreatorWithArgs); \ } template class CommandParser { public: - typedef Command *Creator(const string &, const string &, bool); + typedef Command *(*Creator)(const string &, const string &, bool); static CommandParser &instance() { static CommandParser s_instance; @@ -95,7 +95,7 @@ public: Command *parse(const string &name, const string &args, bool trusted = true) const { string lc = StringUtil::toLower(name); - Creator *creator = ObjectRegistry::instance().lookup(lc); + Creator creator = ObjectRegistry::instance().lookup(lc); if (creator) return creator(lc, args, trusted); return 0; @@ -114,7 +114,7 @@ public: bool registerCommand(string name, Creator creator) { name = StringUtil::toLower(name); - return ObjectRegistry::instance().registerObject(name, + return ObjectRegistry::instance().registerObject(name, creator); } -- cgit v0.11.2