C++11: Cleaned up commands code with range-based for

This commit is contained in:
Paul Beckingham
2015-05-11 17:45:15 -04:00
parent bd3d58484a
commit 5a57dfd70d
42 changed files with 911 additions and 1065 deletions

View File

@@ -65,75 +65,73 @@ int CmdDenotate::execute (std::string& output)
// Extract all the ORIGINAL MODIFICATION args as simple text patterns.
std::string pattern = "";
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
for (auto& a : context.cli._args)
{
if (a->hasTag ("ORIGINAL") &&
a->hasTag ("MODIFICATION"))
if (a.hasTag ("ORIGINAL") &&
a.hasTag ("MODIFICATION"))
{
if (pattern != "")
pattern += ' ';
pattern += a->attribute ("raw");
pattern += a.attribute ("raw");
}
}
// Accumulated project change notifications.
std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)
for (auto& task : filtered)
{
Task before (*task);
Task before (task);
std::map <std::string, std::string> annotations;
task->getAnnotations (annotations);
task.getAnnotations (annotations);
if (annotations.size () == 0)
throw std::string (STRING_CMD_DENO_NONE);
std::map <std::string, std::string>::iterator i;
std::string anno;
bool match = false;
for (i = annotations.begin (); i != annotations.end (); ++i)
for (auto i = annotations.begin (); i != annotations.end (); ++i)
{
if (i->second == pattern)
{
match = true;
anno = i->second;
annotations.erase (i);
task->setAnnotations (annotations);
task.setAnnotations (annotations);
break;
}
}
if (! match)
{
for (i = annotations.begin (); i != annotations.end (); ++i)
for (auto i = annotations.begin (); i != annotations.end (); ++i)
{
std::string::size_type loc = find (i->second, pattern, sensitive);
if (loc != std::string::npos)
{
anno = i->second;
annotations.erase (i);
task->setAnnotations (annotations);
task.setAnnotations (annotations);
break;
}
}
}
if (taskDiff (before, *task))
if (taskDiff (before, task))
{
std::string question = format (STRING_CMD_DENO_CONFIRM,
task->id,
task->get ("description"));
task.id,
task.get ("description"));
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{
++count;
context.tdb2.modify (*task);
context.tdb2.modify (task);
feedback_affected (format (STRING_CMD_DENO_FOUND, anno));
if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false);
projectChanges[task.get ("project")] = onProjectChange (task, false);
}
else
{
@@ -151,10 +149,9 @@ int CmdDenotate::execute (std::string& output)
}
// Now list the project changes.
std::map <std::string, std::string>::iterator i;
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
if (i->first != "")
context.footnote (i->second);
for (auto& change : projectChanges)
if (change.first != "")
context.footnote (change.second);
feedback_affected (count == 1 ? STRING_CMD_DENO_1 : STRING_CMD_DENO_N, count);
return rc;