From d1fe1279edd448ee2ef85b82a2db5c4907615966 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 6 Sep 2015 14:07:21 -0400 Subject: [PATCH] Command: Code cleanup, added ::category accessor - The Command object failed to initialize all member on construction and initialized them out of order (is this still a thing in C++11?). - The _category was the only member with no accessor, which is not right. --- src/commands/CmdCommands.cpp | 4 ++-- src/commands/Command.cpp | 14 +++++++++++--- src/commands/Command.h | 37 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/commands/CmdCommands.cpp b/src/commands/CmdCommands.cpp index 9034503a9..ca256d1a0 100644 --- a/src/commands/CmdCommands.cpp +++ b/src/commands/CmdCommands.cpp @@ -88,7 +88,7 @@ int CmdCommands::execute (std::string& output) { int row = view.addRow (); view.set (row, 0, command.first); - view.set (row, 1, Command::categoryNames.at (command.second->_category)); + view.set (row, 1, Command::categoryNames.at (command.second->category ())); if (command.second->read_only ()) view.set (row, 2, "RO"); @@ -213,7 +213,7 @@ int CmdZshCommands::execute (std::string& output) std::vector commands; for (auto& command : context.commands) { - ZshCommand zshCommand {command.second->_category, + ZshCommand zshCommand {command.second->category (), command.first, command.second->description ()}; commands.push_back (zshCommand); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index a5bb64f58..1b857d34b 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -213,7 +213,7 @@ const std::map Command::categoryNames = //////////////////////////////////////////////////////////////////////////////// Command::Command () -: _category(Category::unassigned) +: _keyword ("") , _usage ("") , _description ("") , _read_only (true) @@ -221,8 +221,10 @@ Command::Command () , _needs_confirm (false) , _needs_gc (true) , _uses_context (false) -, _accepts_filter (true) -, _accepts_modifications (true) +, _accepts_filter (false) +, _accepts_modifications (false) +, _accepts_miscellaneous (false) +, _category(Category::unassigned) , _permission_quit (false) , _permission_all (false) , _first_iteration (true) @@ -294,6 +296,12 @@ bool Command::accepts_miscellaneous () const return _accepts_miscellaneous; } +//////////////////////////////////////////////////////////////////////////////// +Command::Category Command::category () const +{ + return _category; +} + //////////////////////////////////////////////////////////////////////////////// // Returns true or false indicating whether to proceed with a write command, on // a per-task basis, after (potentially) asking for permission. diff --git a/src/commands/Command.h b/src/commands/Command.h index 7c87f3874..70c3cb7b9 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -35,23 +35,6 @@ class Command { public: - Command (); - virtual ~Command (); - - static void factory (std::map &); - - std::string keyword () const; - std::string usage () const; - std::string description () const; - bool read_only () const; - bool displays_id () const; - bool needs_gc () const; - bool uses_context () const; - bool accepts_filter () const; - bool accepts_modifications () const; - bool accepts_miscellaneous () const; - virtual int execute (std::string&) = 0; - enum class Category { unassigned, @@ -68,7 +51,24 @@ public: UNDOCUMENTED, // Whenever you extend this enum, update categoryNames. }; - Category _category; + + Command (); + virtual ~Command (); + + static void factory (std::map &); + + std::string keyword () const; + std::string usage () const; + std::string description () const; + bool read_only () const; + bool displays_id () const; + bool needs_gc () const; + bool uses_context () const; + bool accepts_filter () const; + bool accepts_modifications () const; + bool accepts_miscellaneous () const; + Category category () const; + virtual int execute (std::string&) = 0; protected: bool permission (const Task&, const std::string&, unsigned int); @@ -86,6 +86,7 @@ protected: bool _accepts_filter; bool _accepts_modifications; bool _accepts_miscellaneous; + Category _category; // Permission support bool _permission_quit;