From 28d0c534b1917cdb625b48413b80a8bbad3d1a53 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 5 Sep 2015 14:39:52 -0400 Subject: [PATCH] CmdContext: Added 'const' for method args that are const --- src/commands/CmdContext.cpp | 34 ++++++++++++++-------------------- src/commands/CmdContext.h | 14 +++++++------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index 60fbf3034..9a335b120 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -41,7 +41,7 @@ extern Context context; CmdContext::CmdContext () { _keyword = "context"; - _usage = "task context [ | subcommand]"; + _usage = "task context [ | ]"; _description = STRING_CMD_CONTEXT_USAGE; _read_only = true; _displays_id = false; @@ -66,18 +66,12 @@ int CmdContext::execute (std::string& output) { std::string subcommand = words[0]; - if (subcommand == "define") - rc = defineContext (words, out); - else if (subcommand == "delete") - rc = deleteContext (words, out); - else if (subcommand == "list") - rc = listContexts (words, out); - else if (subcommand == "none") - rc = unsetContext (words, out); - else if (subcommand == "show") - rc = showContext (words, out); - else - rc = setContext (words, out); + if (subcommand == "define") rc = defineContext (words, out); + else if (subcommand == "delete") rc = deleteContext (words, out); + else if (subcommand == "list") rc = listContexts (words, out); + else if (subcommand == "none") rc = unsetContext (words, out); + else if (subcommand == "show") rc = showContext (words, out); + else rc = setContext (words, out); } output = out.str (); @@ -90,7 +84,7 @@ int CmdContext::execute (std::string& output) // // If to is specified as 0 (default value), all the remaining words will be joined. // -std::string CmdContext::joinWords (std::vector & words, unsigned int from, unsigned int to /* = 0 */) +std::string CmdContext::joinWords (const std::vector & words, unsigned int from, unsigned int to /* = 0 */) { std::string value = ""; @@ -132,7 +126,7 @@ std::vector CmdContext::getContexts () // Invoked with: task context define // Example: task context define home project:Home // -int CmdContext::defineContext (std::vector & words, std::stringstream& out) +int CmdContext::defineContext (const std::vector & words, std::stringstream& out) { int rc = 0; bool confirmation = context.config.getBoolean ("confirmation"); @@ -194,7 +188,7 @@ int CmdContext::defineContext (std::vector & words, std::stringstre // Invoked with: task context delete // Example: task context delete home // -int CmdContext::deleteContext (std::vector & words, std::stringstream& out) +int CmdContext::deleteContext (const std::vector & words, std::stringstream& out) { int rc = 0; @@ -235,7 +229,7 @@ int CmdContext::deleteContext (std::vector & words, std::stringstre // Invoked with: task context list // Example: task context list // -int CmdContext::listContexts (std::vector & words, std::stringstream& out) +int CmdContext::listContexts (const std::vector & words, std::stringstream& out) { int rc = 0; std::vector contexts = getContexts(); @@ -294,7 +288,7 @@ int CmdContext::listContexts (std::vector & words, std::stringstrea // Invoked with: task context // Example: task context home // -int CmdContext::setContext (std::vector & words, std::stringstream& out) +int CmdContext::setContext (const std::vector & words, std::stringstream& out) { int rc = 0; std::string value = words[0]; @@ -327,7 +321,7 @@ int CmdContext::setContext (std::vector & words, std::stringstream& // Invoked with: task context show // Example: task context show // -int CmdContext::showContext (std::vector & words, std::stringstream& out) +int CmdContext::showContext (const std::vector & words, std::stringstream& out) { std::string currentContext = context.config.get ("context"); @@ -352,7 +346,7 @@ int CmdContext::showContext (std::vector & words, std::stringstream // Invoked with: task context none // Example: task context none // -int CmdContext::unsetContext (std::vector & words, std::stringstream& out) +int CmdContext::unsetContext (const std::vector & words, std::stringstream& out) { int rc = 0; int status = CmdConfig::unsetConfigVariable ("context", false); diff --git a/src/commands/CmdContext.h b/src/commands/CmdContext.h index 4d0f1df75..d06b8f934 100644 --- a/src/commands/CmdContext.h +++ b/src/commands/CmdContext.h @@ -35,14 +35,14 @@ class CmdContext : public Command public: CmdContext (); int execute (std::string&); - std::string joinWords (std::vector & words, unsigned int from, unsigned int to = 0); + std::string joinWords (const std::vector & words, unsigned int from, unsigned int to = 0); static std::vector getContexts (); - int defineContext (std::vector & words, std::stringstream& out); - int deleteContext (std::vector & words, std::stringstream& out); - int listContexts (std::vector & words, std::stringstream& out); - int setContext (std::vector & words, std::stringstream& out); - int showContext (std::vector & words, std::stringstream& out); - int unsetContext (std::vector & words, std::stringstream& out); + int defineContext (const std::vector & words, std::stringstream& out); + int deleteContext (const std::vector & words, std::stringstream& out); + int listContexts (const std::vector & words, std::stringstream& out); + int setContext (const std::vector & words, std::stringstream& out); + int showContext (const std::vector & words, std::stringstream& out); + int unsetContext (const std::vector & words, std::stringstream& out); }; class CmdCompletionContext : public Command