diff --git a/include/core/command.hpp b/include/core/command.hpp index 37bb844b..d261bfe8 100644 --- a/include/core/command.hpp +++ b/include/core/command.hpp @@ -4,9 +4,9 @@ #include #include #include -#include "library/commands.hpp" +#include "library/command.hpp" -extern command_group lsnes_cmd; +extern command::group lsnes_cmd; void refresh_alias_binds(); diff --git a/include/library/commands.hpp b/include/library/command.hpp similarity index 81% rename from include/library/commands.hpp rename to include/library/command.hpp index 4f1f8ce5..eac77cd3 100644 --- a/include/library/commands.hpp +++ b/include/library/command.hpp @@ -1,5 +1,5 @@ -#ifndef _library_commands__hpp__included__ -#define _library_commands__hpp__included__ +#ifndef _library_command__hpp__included__ +#define _library_command__hpp__included__ #include #include @@ -8,22 +8,24 @@ #include #include "threadtypes.hpp" -class command; +namespace command +{ +class base; /** * A group of commands (with aliases). */ -class command_group +class group { public: /** * Create a new command group. This also places some builtin commands in that new group. */ - command_group() throw(std::bad_alloc); + group() throw(std::bad_alloc); /** * Destroy a group. */ - ~command_group() throw(); + ~group() throw(); /** * Look up and invoke a command. The command will undergo alias expansion and recursion checking. * @@ -49,7 +51,7 @@ public: /** * Register a command. */ - void do_register(const std::string& name, command& cmd) throw(std::bad_alloc); + void do_register(const std::string& name, base& cmd) throw(std::bad_alloc); /** * Unregister a command. */ @@ -63,19 +65,19 @@ public: */ void set_oom_panic(void (*fn)()); private: - std::map commands; + std::map commands; std::set command_stack; std::map> aliases; mutex_class int_mutex; std::ostream* output; void (*oom_panic_routine)(); - command* builtin[1]; + base* builtin[1]; }; /** * A command. */ -class command +class base { public: /** @@ -85,12 +87,12 @@ public: * parameter cmd: The command to register. * throws std::bad_alloc: Not enough memory. */ - command(command_group& group, const std::string& cmd) throw(std::bad_alloc); + base(group& group, const std::string& cmd) throw(std::bad_alloc); /** * Deregister a command. */ - virtual ~command() throw(); + virtual ~base() throw(); /** * Invoke a command. @@ -114,10 +116,10 @@ public: */ const std::string& get_name() { return commandname; } private: - command(const command&); - command& operator=(const command&); + base(const base&); + base& operator=(const base&); std::string commandname; - command_group& in_group; + group& in_group; }; /** @@ -144,13 +146,13 @@ struct arg_filename * parameter a: The arguments to pass. */ template -void invoke_command_fn(void (*fn)(args... arguments), const std::string& a); +void invoke_fn(void (*fn)(args... arguments), const std::string& a); /** * Warp function pointer as command. */ template -class function_ptr_command : public command +class fnptr : public base { public: /** @@ -162,9 +164,9 @@ public: * parameter help: Help for the command. * parameter fn: Function to call on command. */ - function_ptr_command(command_group& group, const std::string& name, const std::string& _description, + fnptr(group& group, const std::string& name, const std::string& _description, const std::string& _help, void (*_fn)(args... arguments)) throw(std::bad_alloc) - : command(group, name) + : base(group, name) { description = _description; help = _help; @@ -173,7 +175,7 @@ public: /** * Destroy a commnad. */ - ~function_ptr_command() throw() + ~fnptr() throw() { } /** @@ -183,7 +185,7 @@ public: */ void invoke(const std::string& a) throw(std::bad_alloc, std::runtime_error) { - invoke_command_fn(fn, a); + invoke_fn(fn, a); } /** * Get short description. @@ -210,5 +212,6 @@ private: std::string description; std::string help; }; +} #endif diff --git a/include/library/keyboard-cmd-bridge.hpp b/include/library/keyboard-cmd-bridge.hpp index bab8dfd0..548577bd 100644 --- a/include/library/keyboard-cmd-bridge.hpp +++ b/include/library/keyboard-cmd-bridge.hpp @@ -2,7 +2,7 @@ #define _library__keyboard_cmd_bridge__hpp__ #include "keyboard.hpp" -#include "commands.hpp" +#include "command.hpp" class inverse_bind; @@ -15,7 +15,7 @@ public: /** * Create a bridge. */ - keyboard_command_bridge(keyboard& kgroup, command_group& cgroup); + keyboard_command_bridge(keyboard& kgroup, command::group& cgroup); /** * Destroy a bridge. */ diff --git a/include/library/keymapper.hpp b/include/library/keymapper.hpp index b8df5c6c..2c28f1d5 100644 --- a/include/library/keymapper.hpp +++ b/include/library/keymapper.hpp @@ -1,7 +1,7 @@ #ifndef _library__keymapper__hpp__included__ #define _library__keymapper__hpp__included__ -#include "commands.hpp" +#include "command.hpp" #include #include #include @@ -77,7 +77,7 @@ public: /** * Create new keyboard mapper. */ - keyboard_mapper(keyboard& kbd, command_group& domain) throw(std::bad_alloc); + keyboard_mapper(keyboard& kbd, command::group& domain) throw(std::bad_alloc); /** * Destroy a keyboard mapper. */ @@ -206,7 +206,7 @@ public: /** * Get command group to run commands in.. */ - command_group& get_command_group() throw(); + command::group& get_command_group() throw(); /** * Fixup command based on polarity. * @@ -244,7 +244,7 @@ private: std::map bindings; std::set listening; keyboard& kbd; - command_group& domain; + command::group& domain; mutex_class mutex; }; diff --git a/src/core/actions.cpp b/src/core/actions.cpp index b5baf4d0..8c1ea3b1 100644 --- a/src/core/actions.cpp +++ b/src/core/actions.cpp @@ -5,7 +5,7 @@ namespace { - function_ptr_command action(lsnes_cmd, "action", "Execute core action", + command::fnptr action(lsnes_cmd, "action", "Execute core action", "Syntax: action [...]\nExecutes core action.\n", [](const std::string& _args) throw(std::bad_alloc, std::runtime_error) { if(_args == "") { diff --git a/src/core/command.cpp b/src/core/command.cpp index c45aeea1..2cdb81df 100644 --- a/src/core/command.cpp +++ b/src/core/command.cpp @@ -8,7 +8,7 @@ #include #include -command_group lsnes_cmd; +command::group lsnes_cmd; namespace { diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 4e318138..1bb143ac 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -436,73 +436,73 @@ namespace } } - function_ptr_command button_p(lsnes_cmd, "+controller", "Press a button", + command::fnptr button_p(lsnes_cmd, "+controller", "Press a button", "Syntax: +controller