Code Cleanup

- Removed used of foreach macro.
This commit is contained in:
Paul Beckingham 2010-11-27 19:42:34 -05:00
parent 4c3354fa50
commit bfc2367bdb
7 changed files with 55 additions and 36 deletions

View file

@ -657,23 +657,25 @@ void Config::set (const std::string& key, const std::string& value)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Provide a vector of all configuration keys. // Provide a vector of all configuration keys.
void Config::all (std::vector<std::string>& items) void Config::all (std::vector<std::string>& items) const
{ {
foreach (i, *this) std::map <std::string, std::string>::const_iterator it;
items.push_back (i->first); for (it = this->begin (); it != this->end (); ++it)
items.push_back (it->first);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Config::checkForDeprecatedColor () std::string Config::checkForDeprecatedColor ()
{ {
std::vector <std::string> deprecated; std::vector <std::string> deprecated;
foreach (i, *this) std::map <std::string, std::string>::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
{ {
if (i->first.find ("color.") != std::string::npos) if (it->first.find ("color.") != std::string::npos)
{ {
std::string value = get (i->first); std::string value = get (it->first);
if (value.find ("_") != std::string::npos) if (value.find ("_") != std::string::npos)
deprecated.push_back (i->first); deprecated.push_back (it->first);
} }
} }
@ -683,8 +685,9 @@ std::string Config::checkForDeprecatedColor ()
out << "Your .taskrc file contains color settings that use deprecated " out << "Your .taskrc file contains color settings that use deprecated "
<< "underscores. Please check:\n"; << "underscores. Please check:\n";
foreach (i, deprecated) std::vector <std::string>::iterator it2;
out << " " << *i << "=" << get (*i) << "\n"; for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
out << " " << *it2 << "=" << get (*it2) << "\n";
out << "\n"; out << "\n";
} }
@ -696,15 +699,16 @@ std::string Config::checkForDeprecatedColor ()
std::string Config::checkForDeprecatedColumns () std::string Config::checkForDeprecatedColumns ()
{ {
std::vector <std::string> deprecated; std::vector <std::string> deprecated;
foreach (i, *this) std::map <std::string, std::string>::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
{ {
if (i->first.find ("report") == 0) if (it->first.find ("report") == 0)
{ {
std::string value = get (i->first); std::string value = get (it->first);
if (value.find ("entry_time") != std::string::npos || if (value.find ("entry_time") != std::string::npos ||
value.find ("start_time") != std::string::npos || value.find ("start_time") != std::string::npos ||
value.find ("end_time") != std::string::npos) value.find ("end_time") != std::string::npos)
deprecated.push_back (i->first); deprecated.push_back (it->first);
} }
} }
@ -716,8 +720,9 @@ std::string Config::checkForDeprecatedColumns ()
out << "Your .taskrc file contains reports with deprecated columns. " out << "Your .taskrc file contains reports with deprecated columns. "
<< "Please check for entry_time, start_time or end_time in:\n"; << "Please check for entry_time, start_time or end_time in:\n";
foreach (i, deprecated) std::vector <std::string>::iterator it2;
out << " " << *i << "\n"; for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
out << " " << *it2 << "=" << get (*it2) << "\n";
out << "\n"; out << "\n";
} }

View file

@ -57,7 +57,7 @@ public:
void set (const std::string&, const int); void set (const std::string&, const int);
void set (const std::string&, const double); void set (const std::string&, const double);
void set (const std::string&, const std::string&); void set (const std::string&, const std::string&);
void all (std::vector <std::string>&); void all (std::vector <std::string>&) const;
std::string checkForDeprecatedColor (); std::string checkForDeprecatedColor ();
std::string checkForDeprecatedColumns (); std::string checkForDeprecatedColumns ();

View file

@ -131,8 +131,9 @@ bool Record::has (const std::string& name) const
std::vector <Att> Record::all () std::vector <Att> Record::all ()
{ {
std::vector <Att> all; std::vector <Att> all;
foreach (a, (*this)) std::map <std::string, Att>::iterator i;
all.push_back (a->second); for (i = this->begin (); i != this->end (); ++i)
all.push_back (i->second);
return all; return all;
} }

View file

@ -135,13 +135,17 @@ void Sequence::combine (const Sequence& other)
// Create a map using the sequence elements as keys. This will create a // Create a map using the sequence elements as keys. This will create a
// unique list, with no duplicates. // unique list, with no duplicates.
std::map <int, int> both; std::map <int, int> both;
foreach (i, *this) both[*i] = 0; std::vector <int>::iterator i1;
foreach (i, other) both[*i] = 0; for (i1 = this->begin (); i1 != this->end (); ++i1) both[*i1] = 0;
std::vector <int>::const_iterator i2;
for (i2 = other.begin (); i2 != other.end (); ++i2) both[*i2] = 0;
// Now make a sequence out of the keys of the map. // Now make a sequence out of the keys of the map.
this->clear (); this->clear ();
foreach (i, both) std::map <int, int>::iterator i3;
this->push_back (i->first); for (i3 = both.begin (); i3 != both.end (); ++i3)
this->push_back (i3->first);
std::sort (this->begin (), this->end ()); std::sort (this->begin (), this->end ());
} }

View file

@ -161,7 +161,8 @@ static std::string formatTask (Task task)
std::vector <Att> annotations; std::vector <Att> annotations;
task.getAnnotations (annotations); task.getAnnotations (annotations);
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 ()));
before << " Annotation: " << dt.toString (context.config.get ("dateformat.annotation")) before << " Annotation: " << dt.toString (context.config.get ("dateformat.annotation"))
@ -533,7 +534,8 @@ static void parseTask (Task& task, const std::string& after)
split (dependencies, value, ","); split (dependencies, value, ",");
task.remove ("depends"); task.remove ("depends");
foreach (dep, dependencies) std::vector <std::string>::iterator dep;
for (dep = dependencies.begin (); dep != dependencies.end (); ++dep)
{ {
int id = atoi (dep->c_str ()); int id = atoi (dep->c_str ());
if (id) if (id)
@ -644,7 +646,8 @@ int handleEdit (std::string& outs)
std::vector <Task> all = tasks; std::vector <Task> all = tasks;
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks) std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{ {
editFile (*task); editFile (*task);
context.tdb.update (*task); context.tdb.update (*task);
@ -652,7 +655,8 @@ int handleEdit (std::string& outs)
TODO Figure out what this is. I can't remember, but don't want to remove TODO Figure out what this is. I can't remember, but don't want to remove
it until I do. it until I do.
foreach (other, all) std::vector <Task>::iterator other;
for (other = all.begin (); other != all.end (); ++other)
{ {
if (other->id != task.id) // Don't edit the same task again. if (other->id != task.id) // Don't edit the same task again.
{ {

View file

@ -49,14 +49,15 @@ void initializeColorRules ()
std::vector <std::string> rules; std::vector <std::string> rules;
std::vector <std::string> variables; std::vector <std::string> variables;
context.config.all (variables); context.config.all (variables);
foreach (it, variables) std::vector <std::string>::iterator v;
for (v = variables.begin (); v != variables.end (); ++v)
{ {
if (it->substr (0, 6) == "color.") if (v->substr (0, 6) == "color.")
{ {
Color c (context.config.get (*it)); Color c (context.config.get (*v));
gsColor[*it] = c; gsColor[*v] = c;
rules.push_back (*it); rules.push_back (*v);
} }
} }
@ -66,13 +67,15 @@ void initializeColorRules ()
std::vector <std::string> precedence; std::vector <std::string> precedence;
split (precedence, context.config.get ("rule.precedence.color"), ','); split (precedence, context.config.get ("rule.precedence.color"), ',');
foreach (it, precedence) std::vector <std::string>::iterator p;
for (p = precedence.begin (); p != precedence.end (); ++p)
{ {
// Add the leading "color." string. // Add the leading "color." string.
std::string rule = "color." + *it; std::string rule = "color." + *p;
autoComplete (rule, rules, results); autoComplete (rule, rules, results);
foreach (r, results) std::vector <std::string>::iterator r;
for (r = results.begin (); r != results.end (); ++r)
gsPrecedence.push_back (*r); gsPrecedence.push_back (*r);
} }
} }

View file

@ -152,7 +152,8 @@ void ReportStats::gatherStats ()
std::vector <std::string> undo; std::vector <std::string> undo;
File::read (file, undo); File::read (file, undo);
int undoCount = 0; int undoCount = 0;
foreach (tx, undo) std::vector <std::string>::iterator tx;
for (tx = undo.begin (); tx != undo.end (); ++tx)
if (tx->substr (0, 3) == "---") if (tx->substr (0, 3) == "---")
++undoCount; ++undoCount;
@ -213,7 +214,8 @@ void ReportStats::gatherStats ()
it->getTags (tags); it->getTags (tags);
if (tags.size ()) ++taggedT; if (tags.size ()) ++taggedT;
foreach (t, tags) std::vector <std::string>::iterator t;
for (t = tags.begin (); t != tags.end (); ++t)
allTags[*t] = 0; allTags[*t] = 0;
std::string project = it->get ("project"); std::string project = it->get ("project");