From 61e549c80caa0b2beb23078633341016d8a0460d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 4 Jun 2011 23:02:18 -0400 Subject: [PATCH] Code Cleanup - Removed many more uses of the 'foreach' macro. --- src/Context.cpp | 21 +++++++++++++++------ src/Task.cpp | 12 ++++++++---- src/TransportCurl.cpp | 6 +++--- src/commands/CmdLog.cpp | 3 ++- src/helpers.cpp | 5 ++++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index c2e7a8b4a..f49774584 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -164,7 +164,8 @@ int Context::run () // Dump all debug messages, controlled by rc.debug. if (config.getBoolean ("debug")) { - foreach (d, debugMessages) + std::vector ::iterator d; + for (d = debugMessages.begin (); d != debugMessages.end (); ++d) if (color ()) std::cout << colorizeDebug (*d) << "\n"; else @@ -175,22 +176,28 @@ int Context::run () // Dump all headers, controlled by 'header' verbosity token. if (verbose ("header")) - foreach (h, headers) + { + std::vector ::iterator h; + for (h = headers.begin (); h != headers.end (); ++h) if (color ()) std::cout << colorizeHeader (*h) << "\n"; else std::cout << *h << "\n"; + } // Dump the report output. std::cout << output; // Dump all footnotes, controlled by 'footnote' verbosity token. if (verbose ("footnote")) - foreach (f, footnotes) + { + std::vector ::iterator f; + for (f = footnotes.begin (); f != footnotes.end (); ++f) if (color ()) std::cout << colorizeFootnote (*f) << "\n"; else std::cout << *f << "\n"; + } hooks.trigger ("on-exit"); return rc; @@ -453,7 +460,8 @@ void Context::autoFilter (Att& a, Filter& f) { std::vector words; split (words, a.value (), ' '); - foreach (word, words) + std::vector ::iterator word; + for (word = words.begin (); word != words.end (); ++word) { f.push_back (Att ("description", "has", *word)); debug ("auto filter: " + a.name () + ".has:" + *word); @@ -537,14 +545,15 @@ void Context::autoFilter (Filter& f) // modifiers. See bug #293. // Include tagAdditions. - foreach (tag, tagAdditions) + std::vector ::iterator tag; + for (tag = tagAdditions.begin (); tag != tagAdditions.end (); ++tag) { f.push_back (Att ("tags", "word", *tag)); debug ("auto filter: +" + *tag); } // Include tagRemovals. - foreach (tag, tagRemovals) + for (tag = tagRemovals.begin (); tag != tagRemovals.end (); ++tag) { f.push_back (Att ("tags", "noword", *tag)); debug ("auto filter: -" + *tag); diff --git a/src/Task.cpp b/src/Task.cpp index 652cf323f..aedfae1e4 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -78,7 +78,8 @@ bool Task::operator== (const Task& other) if (size () != other.size ()) return false; - foreach (att, *this) + std::map ::iterator att; + for (att = this->begin (); att != this->end (); ++att) if (att->second.name () != "uuid") if (att->second.value () != other.get (att->second.name ())) return false; @@ -423,14 +424,16 @@ std::string Task::composeYAML () const // Only include non-trivial attributes. std::string value; - foreach (name, names) + std::vector ::iterator name; + for (name = names.begin (); name != names.end (); ++name) if ((value = get (*name)) != "") out << " " << *name << ": " << value << "\n"; // Now the annotations, which are not listed by the Att::allNames call. std::vector annotations; getAnnotations (annotations); - foreach (a, annotations) + std::vector ::iterator a; + for (a = annotations.begin (); a != annotations.end (); ++a) out << " annotation:\n" << " entry: " << a->name().substr (11) << "\n" << " description: " << a->value () << "\n"; @@ -1045,7 +1048,8 @@ float Task::urgency () std::vector all; context.config.all (all); - foreach (var, all) + std::vector ::iterator var; + for (var = all.begin (); var != all.end (); ++var) { if (var->substr (0, 13) == "urgency.user.") { diff --git a/src/TransportCurl.cpp b/src/TransportCurl.cpp index 0623e3d7c..65fd2945f 100644 --- a/src/TransportCurl.cpp +++ b/src/TransportCurl.cpp @@ -121,10 +121,10 @@ void TransportCurl::recv(std::string target) split (splitted, toSplit.substr(0, pos), ','); target = ""; - foreach (file, splitted) - { + + std::vector ::iterator file; + for (file = splitted.begin (); file != splitted.end (); ++file) target += " -o " + prefix + *file + suffix; - } } else { diff --git a/src/commands/CmdLog.cpp b/src/commands/CmdLog.cpp index dbd93d1f0..62403dd0d 100644 --- a/src/commands/CmdLog.cpp +++ b/src/commands/CmdLog.cpp @@ -93,7 +93,8 @@ int CmdLog::execute (std::string& output) } // Include tags. - foreach (tag, context.tagAdditions) + std::vector ::iterator tag; + for (tag = tagAdditions.begin 90; tag != tagAdditions.end (); ++tag) context.task.addTag (*tag); // Only valid tasks can be added. diff --git a/src/helpers.cpp b/src/helpers.cpp index 55383b3db..411b28a9b 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -85,7 +85,9 @@ std::string getFullDescription (Task& task, const std::string& report) desc += "\n" + when + " " + anno.value (); } else - foreach (anno, annotations) + { + std::vector ::iterator anno; + for (anno = annotations.begin (); anno != annotations.end (); ++anno) { Date dt (atoi (anno->name ().substr (11).c_str ())); std::string format = context.config.get ("dateformat.annotation"); @@ -94,6 +96,7 @@ std::string getFullDescription (Task& task, const std::string& report) std::string when = dt.toString (format); desc += "\n" + when + " " + anno->value (); } + } } return desc;