Code Cleanup

- Removed many more uses of the 'foreach' macro.
This commit is contained in:
Paul Beckingham 2011-06-04 23:02:18 -04:00
parent f9c1820740
commit 61e549c80c
5 changed files with 32 additions and 15 deletions

View file

@ -164,7 +164,8 @@ int Context::run ()
// Dump all debug messages, controlled by rc.debug. // Dump all debug messages, controlled by rc.debug.
if (config.getBoolean ("debug")) if (config.getBoolean ("debug"))
{ {
foreach (d, debugMessages) std::vector <std::string>::iterator d;
for (d = debugMessages.begin (); d != debugMessages.end (); ++d)
if (color ()) if (color ())
std::cout << colorizeDebug (*d) << "\n"; std::cout << colorizeDebug (*d) << "\n";
else else
@ -175,22 +176,28 @@ int Context::run ()
// Dump all headers, controlled by 'header' verbosity token. // Dump all headers, controlled by 'header' verbosity token.
if (verbose ("header")) if (verbose ("header"))
foreach (h, headers) {
std::vector <std::string>::iterator h;
for (h = headers.begin (); h != headers.end (); ++h)
if (color ()) if (color ())
std::cout << colorizeHeader (*h) << "\n"; std::cout << colorizeHeader (*h) << "\n";
else else
std::cout << *h << "\n"; std::cout << *h << "\n";
}
// Dump the report output. // Dump the report output.
std::cout << output; std::cout << output;
// Dump all footnotes, controlled by 'footnote' verbosity token. // Dump all footnotes, controlled by 'footnote' verbosity token.
if (verbose ("footnote")) if (verbose ("footnote"))
foreach (f, footnotes) {
std::vector <std::string>::iterator f;
for (f = footnotes.begin (); f != footnotes.end (); ++f)
if (color ()) if (color ())
std::cout << colorizeFootnote (*f) << "\n"; std::cout << colorizeFootnote (*f) << "\n";
else else
std::cout << *f << "\n"; std::cout << *f << "\n";
}
hooks.trigger ("on-exit"); hooks.trigger ("on-exit");
return rc; return rc;
@ -453,7 +460,8 @@ void Context::autoFilter (Att& a, Filter& f)
{ {
std::vector <std::string> words; std::vector <std::string> words;
split (words, a.value (), ' '); split (words, a.value (), ' ');
foreach (word, words) std::vector <std::string>::iterator word;
for (word = words.begin (); word != words.end (); ++word)
{ {
f.push_back (Att ("description", "has", *word)); f.push_back (Att ("description", "has", *word));
debug ("auto filter: " + a.name () + ".has:" + *word); debug ("auto filter: " + a.name () + ".has:" + *word);
@ -537,14 +545,15 @@ void Context::autoFilter (Filter& f)
// modifiers. See bug #293. // modifiers. See bug #293.
// Include tagAdditions. // Include tagAdditions.
foreach (tag, tagAdditions) std::vector <std::string>::iterator tag;
for (tag = tagAdditions.begin (); tag != tagAdditions.end (); ++tag)
{ {
f.push_back (Att ("tags", "word", *tag)); f.push_back (Att ("tags", "word", *tag));
debug ("auto filter: +" + *tag); debug ("auto filter: +" + *tag);
} }
// Include tagRemovals. // Include tagRemovals.
foreach (tag, tagRemovals) for (tag = tagRemovals.begin (); tag != tagRemovals.end (); ++tag)
{ {
f.push_back (Att ("tags", "noword", *tag)); f.push_back (Att ("tags", "noword", *tag));
debug ("auto filter: -" + *tag); debug ("auto filter: -" + *tag);

View file

@ -78,7 +78,8 @@ bool Task::operator== (const Task& other)
if (size () != other.size ()) if (size () != other.size ())
return false; return false;
foreach (att, *this) std::map <std::string, Att>::iterator att;
for (att = this->begin (); att != this->end (); ++att)
if (att->second.name () != "uuid") if (att->second.name () != "uuid")
if (att->second.value () != other.get (att->second.name ())) if (att->second.value () != other.get (att->second.name ()))
return false; return false;
@ -423,14 +424,16 @@ std::string Task::composeYAML () const
// Only include non-trivial attributes. // Only include non-trivial attributes.
std::string value; std::string value;
foreach (name, names) std::vector <std::string>::iterator name;
for (name = names.begin (); name != names.end (); ++name)
if ((value = get (*name)) != "") if ((value = get (*name)) != "")
out << " " << *name << ": " << value << "\n"; out << " " << *name << ": " << value << "\n";
// Now the annotations, which are not listed by the Att::allNames call. // Now the annotations, which are not listed by the Att::allNames call.
std::vector <Att> annotations; std::vector <Att> annotations;
getAnnotations (annotations); getAnnotations (annotations);
foreach (a, annotations) std::vector <Att>::iterator a;
for (a = annotations.begin (); a != annotations.end (); ++a)
out << " annotation:\n" out << " annotation:\n"
<< " entry: " << a->name().substr (11) << "\n" << " entry: " << a->name().substr (11) << "\n"
<< " description: " << a->value () << "\n"; << " description: " << a->value () << "\n";
@ -1045,7 +1048,8 @@ float Task::urgency ()
std::vector <std::string> all; std::vector <std::string> all;
context.config.all (all); context.config.all (all);
foreach (var, all) std::vector <std::string>::iterator var;
for (var = all.begin (); var != all.end (); ++var)
{ {
if (var->substr (0, 13) == "urgency.user.") if (var->substr (0, 13) == "urgency.user.")
{ {

View file

@ -121,10 +121,10 @@ void TransportCurl::recv(std::string target)
split (splitted, toSplit.substr(0, pos), ','); split (splitted, toSplit.substr(0, pos), ',');
target = ""; target = "";
foreach (file, splitted)
{ std::vector <std::string>::iterator file;
for (file = splitted.begin (); file != splitted.end (); ++file)
target += " -o " + prefix + *file + suffix; target += " -o " + prefix + *file + suffix;
}
} }
else else
{ {

View file

@ -93,7 +93,8 @@ int CmdLog::execute (std::string& output)
} }
// Include tags. // Include tags.
foreach (tag, context.tagAdditions) std::vector <std::string>::iterator tag;
for (tag = tagAdditions.begin 90; tag != tagAdditions.end (); ++tag)
context.task.addTag (*tag); context.task.addTag (*tag);
// Only valid tasks can be added. // Only valid tasks can be added.

View file

@ -85,7 +85,9 @@ std::string getFullDescription (Task& task, const std::string& report)
desc += "\n" + when + " " + anno.value (); desc += "\n" + when + " " + anno.value ();
} }
else else
foreach (anno, annotations) {
std::vector <Att>::iterator anno;
for (anno = annotations.begin (); anno != annotations.end (); ++anno)
{ {
Date dt (atoi (anno->name ().substr (11).c_str ())); Date dt (atoi (anno->name ().substr (11).c_str ()));
std::string format = context.config.get ("dateformat.annotation"); 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); std::string when = dt.toString (format);
desc += "\n" + when + " " + anno->value (); desc += "\n" + when + " " + anno->value ();
} }
}
} }
return desc; return desc;