From fab2979b87956dd337378809d7d5bdd494144572 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 31 Dec 2016 15:44:13 -0500 Subject: [PATCH] Task: Improved method signature --- src/Task.cpp | 4 ++-- src/Task.h | 2 +- src/commands/CmdEdit.cpp | 9 ++------- src/commands/CmdInfo.cpp | 3 +-- src/commands/CmdStats.cpp | 3 +-- src/commands/CmdTags.cpp | 12 ++---------- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index ed65af137..82b904b17 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1313,9 +1313,9 @@ void Task::addTags (const std::vector & tags) } //////////////////////////////////////////////////////////////////////////////// -void Task::getTags (std::vector& tags) const +std::vector Task::getTags () const { - tags = split (get ("tags"), ','); + return split (get ("tags"), ','); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Task.h b/src/Task.h index 21d2fea7e..a323bbbd6 100644 --- a/src/Task.h +++ b/src/Task.h @@ -125,7 +125,7 @@ public: bool hasTag (const std::string&) const; void addTag (const std::string&); void addTags (const std::vector &); - void getTags (std::vector&) const; + std::vector getTags () const; void removeTag (const std::string&); bool hasAnnotations () const; diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index 9a8980148..55e2900a7 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -224,14 +224,10 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat) << "# iMask: " << task.get ("imask") << '\n' << " Project: " << task.get ("project") << '\n'; - std::vector tags; - task.getTags (tags); - auto allTags = join (" ", tags); - if (verbose) before << "# " << STRING_EDIT_TAG_SEP << '\n'; - before << " Tags: " << allTags << '\n' + before << " Tags: " << join (" ", task.getTags ()) << '\n' << " Description: " << task.get ("description") << '\n' << " Created: " << formatDate (task, "entry", dateformat) << '\n' << " Started: " << formatDate (task, "start", dateformat) << '\n' @@ -353,9 +349,8 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string // tags value = findValue (after, "\n Tags:"); - auto tags = split (value, ' '); task.remove ("tags"); - task.addTags (tags); + task.addTags (split (value, ' ')); // description. value = findMultilineValue (after, "\n Description:", "\n Created:"); diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index fdb6fd981..c028490fe 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -300,8 +300,7 @@ int CmdInfo::execute (std::string& output) } // tags ... - std::vector tags; - task.getTags (tags); + auto tags = task.getTags (); if (tags.size ()) { auto allTags = join (" ", tags); diff --git a/src/commands/CmdStats.cpp b/src/commands/CmdStats.cpp index 599c83960..9eefc4bad 100644 --- a/src/commands/CmdStats.cpp +++ b/src/commands/CmdStats.cpp @@ -145,8 +145,7 @@ int CmdStats::execute (std::string& output) task.getAnnotations (annotations); annotationsT += annotations.size (); - std::vector tags; - task.getTags (tags); + auto tags = task.getTags (); if (tags.size ()) ++taggedT; diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index c50d201c9..6241ddd96 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -79,10 +79,7 @@ int CmdTags::execute (std::string& output) std::map unique; for (auto& task : filtered) { - std::vector tags; - task.getTags (tags); - - for (auto& tag : tags) + for (auto& tag : task.getTags ()) if (unique.find (tag) != unique.end ()) unique[tag]++; else @@ -182,13 +179,8 @@ int CmdCompletionTags::execute (std::string& output) // names as keys. std::map unique; for (auto& task : filtered) - { - std::vector tags; - task.getTags (tags); - - for (auto& tag : tags) + for (auto& tag : task.getTags ()) unique[tag] = 0; - } // Add built-in tags to map. unique["nocolor"] = 0;