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

@ -45,10 +45,9 @@ CmdCompletionAliases::CmdCompletionAliases ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionAliases::execute (std::string& output) int CmdCompletionAliases::execute (std::string& output)
{ {
std::map <std::string, std::string>::iterator alias; for (auto& alias : context.config)
for (alias = context.config.begin (); alias != context.config.end (); ++alias) if (alias.first.substr (0, 6) == "alias.")
if (alias->first.substr (0, 6) == "alias.") output += alias.first.substr (6) + "\n";
output += alias->first.substr (6) + "\n";
return 0; return 0;
} }

View file

@ -67,46 +67,44 @@ int CmdAnnotate::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
// Annotate the specified task. // Annotate the specified task.
std::string question = format (STRING_CMD_ANNO_CONFIRM, std::string question = format (STRING_CMD_ANNO_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modAnnotate, true); task.modify (Task::modAnnotate, true);
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_ANNO_TASK, *task); feedback_affected (STRING_CMD_ANNO_TASK, task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false); projectChanges[task.get ("project")] = onProjectChange (task, false);
// Annotate siblings. // Annotate siblings.
if (task->has ("parent")) if (task.has ("parent"))
{ {
if ((context.config.get ("recurrence.confirmation") == "prompt" if ((context.config.get ("recurrence.confirmation") == "prompt"
&& confirm (STRING_CMD_ANNO_CONFIRM_R)) || && confirm (STRING_CMD_ANNO_CONFIRM_R)) ||
context.config.getBoolean ("recurrence.confirmation")) context.config.getBoolean ("recurrence.confirmation"))
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (task);
std::vector <Task>::iterator sibling; for (auto& sibling : siblings)
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
sibling->modify (Task::modAnnotate, true); sibling.modify (Task::modAnnotate, true);
context.tdb2.modify (*sibling); context.tdb2.modify (sibling);
++count; ++count;
feedback_affected (STRING_CMD_ANNO_TASK_R, *sibling); feedback_affected (STRING_CMD_ANNO_TASK_R, sibling);
} }
// Annotate the parent // Annotate the parent
Task parent; Task parent;
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task.get ("parent"), parent);
parent.modify (Task::modAnnotate, true); parent.modify (Task::modAnnotate, true);
context.tdb2.modify (parent); context.tdb2.modify (parent);
} }
@ -122,10 +120,9 @@ int CmdAnnotate::execute (std::string& output)
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_ANNO_1 : STRING_CMD_ANNO_N, count); feedback_affected (count == 1 ? STRING_CMD_ANNO_1 : STRING_CMD_ANNO_N, count);
return rc; return rc;

View file

@ -67,46 +67,44 @@ int CmdAppend::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
// Append to the specified task. // Append to the specified task.
std::string question = format (STRING_CMD_APPEND_CONFIRM, std::string question = format (STRING_CMD_APPEND_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modAppend, true); task.modify (Task::modAppend, true);
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_APPEND_TASK, *task); feedback_affected (STRING_CMD_APPEND_TASK, task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false); projectChanges[task.get ("project")] = onProjectChange (task, false);
// Append to siblings. // Append to siblings.
if (task->has ("parent")) if (task.has ("parent"))
{ {
if ((context.config.get ("recurrence.confirmation") == "prompt" if ((context.config.get ("recurrence.confirmation") == "prompt"
&& confirm (STRING_CMD_APPEND_CONFIRM_R)) || && confirm (STRING_CMD_APPEND_CONFIRM_R)) ||
context.config.getBoolean ("recurrence.confirmation")) context.config.getBoolean ("recurrence.confirmation"))
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (task);
std::vector <Task>::iterator sibling; for (auto& sibling : siblings)
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
sibling->modify (Task::modAppend, true); sibling.modify (Task::modAppend, true);
context.tdb2.modify (*sibling); context.tdb2.modify (sibling);
++count; ++count;
feedback_affected (STRING_CMD_APPEND_TASK_R, *sibling); feedback_affected (STRING_CMD_APPEND_TASK_R, sibling);
} }
// Append to the parent // Append to the parent
Task parent; Task parent;
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task.get ("parent"), parent);
parent.modify (Task::modAppend, true); parent.modify (Task::modAppend, true);
context.tdb2.modify (parent); context.tdb2.modify (parent);
} }
@ -122,10 +120,9 @@ int CmdAppend::execute (std::string& output)
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_APPEND_1 : STRING_CMD_APPEND_N, count); feedback_affected (count == 1 ? STRING_CMD_APPEND_1 : STRING_CMD_APPEND_N, count);
return rc; return rc;

View file

@ -48,16 +48,13 @@ CmdZshAttributes::CmdZshAttributes ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdZshAttributes::execute (std::string& output) int CmdZshAttributes::execute (std::string& output)
{ {
// Get a list of all columns. // Get a list of all columns, sort them.
std::vector <std::string> columns = context.getColumns (); std::vector <std::string> columns = context.getColumns ();
// Sort alphabetically.
std::sort (columns.begin (), columns.end ()); std::sort (columns.begin (), columns.end ());
std::stringstream out; std::stringstream out;
std::vector <std::string>::iterator c; for (auto& col : columns)
for (c = columns.begin (); c != columns.end (); ++c) out << col << ":" << col << "\n";
out << *c << ":" << *c << "\n";
output = out.str (); output = out.str ();
return 0; return 0;

View file

@ -229,11 +229,10 @@ void Chart::scan (std::vector <Task>& tasks)
Date now; Date now;
time_t epoch; time_t epoch;
std::vector <Task>::iterator task; for (auto& task : tasks)
for (task = tasks.begin (); task != tasks.end (); ++task)
{ {
// The entry date is when the counting starts. // The entry date is when the counting starts.
Date from = quantize (Date (task->get_date ("entry"))); Date from = quantize (Date (task.get_date ("entry")));
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) if (_bars.find (epoch) != _bars.end ())
@ -241,24 +240,26 @@ void Chart::scan (std::vector <Task>& tasks)
// e--> e--s--> // e--> e--s-->
// ppp> pppsss> // ppp> pppsss>
Task::status status = task->getStatus (); Task::status status = task.getStatus ();
if (status == Task::pending || if (status == Task::pending ||
status == Task::waiting) status == Task::waiting)
{ {
if (task->has ("start")) if (task.has ("start"))
{ {
Date start = quantize (Date (task->get_date ("start"))); Date start = quantize (Date (task.get_date ("start")));
while (from < start) while (from < start)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
while (from < now) while (from < now)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._started;
from = increment (from); from = increment (from);
} }
} }
@ -267,7 +268,8 @@ void Chart::scan (std::vector <Task>& tasks)
while (from < now) while (from < now)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
} }
@ -278,7 +280,7 @@ void Chart::scan (std::vector <Task>& tasks)
else if (status == Task::completed) else if (status == Task::completed)
{ {
// Truncate history so it starts at 'earliest' for completed tasks. // Truncate history so it starts at 'earliest' for completed tasks.
Date end = quantize (Date (task->get_date ("end"))); Date end = quantize (Date (task.get_date ("end")));
epoch = end.toEpoch (); epoch = end.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) if (_bars.find (epoch) != _bars.end ())
@ -292,44 +294,49 @@ void Chart::scan (std::vector <Task>& tasks)
continue; continue;
} }
if (task->has ("start")) if (task.has ("start"))
{ {
Date start = quantize (Date (task->get_date ("start"))); Date start = quantize (Date (task.get_date ("start")));
while (from < start) while (from < start)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
while (from < end) while (from < end)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._started;
from = increment (from); from = increment (from);
} }
while (from < now) while (from < now)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._done; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._done;
from = increment (from); from = increment (from);
} }
} }
else else
{ {
Date end = quantize (Date (task->get_date ("end"))); Date end = quantize (Date (task.get_date ("end")));
while (from < end) while (from < end)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
while (from < now) while (from < now)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._done; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._done;
from = increment (from); from = increment (from);
} }
} }
@ -340,7 +347,7 @@ void Chart::scan (std::vector <Task>& tasks)
else if (status == Task::deleted) else if (status == Task::deleted)
{ {
// Skip old deleted tasks. // Skip old deleted tasks.
Date end = quantize (Date (task->get_date ("end"))); Date end = quantize (Date (task.get_date ("end")));
epoch = end.toEpoch (); epoch = end.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._removed; ++_bars[epoch]._removed;
@ -348,30 +355,33 @@ void Chart::scan (std::vector <Task>& tasks)
if (end < _earliest) if (end < _earliest)
continue; continue;
if (task->has ("start")) if (task.has ("start"))
{ {
Date start = quantize (Date (task->get_date ("start"))); Date start = quantize (Date (task.get_date ("start")));
while (from < start) while (from < start)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
while (from < end) while (from < end)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._started;
from = increment (from); from = increment (from);
} }
} }
else else
{ {
Date end = quantize (Date (task->get_date ("end"))); Date end = quantize (Date (task.get_date ("end")));
while (from < end) while (from < end)
{ {
epoch = from.toEpoch (); epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from); from = increment (from);
} }
} }
@ -474,16 +484,14 @@ std::string Chart::render ()
// Draw x-axis labels. // Draw x-axis labels.
std::vector <time_t> bars_in_sequence; std::vector <time_t> bars_in_sequence;
std::map <time_t, Bar>::iterator it; for (auto& bar : _bars)
for (it = _bars.begin (); it != _bars.end (); ++it) bars_in_sequence.push_back (bar.first);
bars_in_sequence.push_back (it->first);
std::sort (bars_in_sequence.begin (), bars_in_sequence.end ()); std::sort (bars_in_sequence.begin (), bars_in_sequence.end ());
std::vector <time_t>::iterator seq;
std::string _major_label; std::string _major_label;
for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq) for (auto& seq : bars_in_sequence)
{ {
Bar bar = _bars[*seq]; Bar bar = _bars[seq];
// If it fits within the allowed space. // If it fits within the allowed space.
if (bar._offset < _actual_bars) if (bar._offset < _actual_bars)
@ -498,9 +506,9 @@ std::string Chart::render ()
} }
// Draw bars. // Draw bars.
for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq) for (auto& seq : bars_in_sequence)
{ {
Bar bar = _bars[*seq]; Bar bar = _bars[seq];
// If it fits within the allowed space. // If it fits within the allowed space.
if (bar._offset < _actual_bars) if (bar._offset < _actual_bars)
@ -772,13 +780,12 @@ void Chart::maxima ()
_max_value = 0; _max_value = 0;
_max_label = 1; _max_label = 1;
std::map <time_t, Bar>::iterator it; for (auto& bar : _bars)
for (it = _bars.begin (); it != _bars.end (); it++)
{ {
// Determine _max_label. // Determine _max_label.
int total = it->second._pending + int total = bar.second._pending +
it->second._started + bar.second._started +
it->second._done + bar.second._done +
_carryover_done; _carryover_done;
// Determine _max_value. // Determine _max_value.

View file

@ -64,9 +64,8 @@ int CmdCalc::execute (std::string& output)
// Compile all the args into one expression. // Compile all the args into one expression.
std::string expression; std::string expression;
std::vector <std::string> words = context.cli.getWords (); std::vector <std::string> words = context.cli.getWords ();
std::vector <std::string>::iterator word; for (auto& word : words)
for (word = words.begin (); word != words.end (); ++word) expression += word + " ";
expression += *word + " ";
// Evaluate according to preference. // Evaluate according to preference.
Variant result; Variant result;

View file

@ -66,7 +66,7 @@ int CmdCalendar::execute (std::string& output)
// Load the pending tasks. // Load the pending tasks.
handleRecurrence (); handleRecurrence ();
std::vector <Task> tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
Date today; Date today;
bool getpendingdate = false; bool getpendingdate = false;
@ -104,43 +104,42 @@ int CmdCalendar::execute (std::string& output)
std::vector <std::string> words = context.cli.getWords (); std::vector <std::string> words = context.cli.getWords ();
std::vector <std::string>::iterator arg; for (auto& arg : words)
for (arg = words.begin (); arg != words.end (); ++arg)
{ {
// Some version of "calendar". // Some version of "calendar".
if (autoComplete (lowerCase (*arg), commandNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1) if (autoComplete (lowerCase (arg), commandNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
continue; continue;
// "due". // "due".
else if (autoComplete (lowerCase (*arg), keywordNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1) else if (autoComplete (lowerCase (arg), keywordNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
getpendingdate = true; getpendingdate = true;
// "y". // "y".
else if (lowerCase (*arg) == "y") else if (lowerCase (arg) == "y")
argWholeYear = true; argWholeYear = true;
// YYYY. // YYYY.
else if (Lexer::isAllDigits (*arg) && arg->length () == 4) else if (Lexer::isAllDigits (arg) && arg.length () == 4)
argYear = strtol (arg->c_str (), NULL, 10); argYear = strtol (arg.c_str (), NULL, 10);
// MM. // MM.
else if (Lexer::isAllDigits (*arg) && arg->length () <= 2) else if (Lexer::isAllDigits (arg) && arg.length () <= 2)
{ {
argMonth = strtol (arg->c_str (), NULL, 10); argMonth = strtol (arg.c_str (), NULL, 10);
if (argMonth < 1 || argMonth > 12) if (argMonth < 1 || argMonth > 12)
throw format (STRING_CMD_CAL_BAD_MONTH, *arg); throw format (STRING_CMD_CAL_BAD_MONTH, arg);
} }
// "January" etc. // "January" etc.
else if (autoComplete (lowerCase (*arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1) else if (autoComplete (lowerCase (arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
{ {
argMonth = Date::monthOfYear (matches[0]); argMonth = Date::monthOfYear (matches[0]);
if (argMonth == -1) if (argMonth == -1)
throw format (STRING_CMD_CAL_BAD_MONTH, *arg); throw format (STRING_CMD_CAL_BAD_MONTH, arg);
} }
else else
throw format (STRING_CMD_CAL_BAD_ARG, *arg); throw format (STRING_CMD_CAL_BAD_ARG, arg);
} }
// Supported combinations: // Supported combinations:
@ -172,16 +171,15 @@ int CmdCalendar::execute (std::string& output)
{ {
// Find the oldest pending due date. // Find the oldest pending due date.
Date oldest (12, 31, 2037); Date oldest (12, 31, 2037);
std::vector <Task>::iterator task; for (auto& task : tasks)
for (task = tasks.begin (); task != tasks.end (); ++task)
{ {
if (task->getStatus () == Task::pending) if (task.getStatus () == Task::pending)
{ {
if (task->has ("due") && if (task.has ("due") &&
!task->hasTag ("nocal")) !task.hasTag ("nocal"))
{ {
++countDueDates; ++countDueDates;
Date d (task->get ("due")); Date d (task.get ("due"));
if (d < oldest) oldest = d; if (d < oldest) oldest = d;
} }
} }
@ -365,21 +363,18 @@ int CmdCalendar::execute (std::string& output)
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL)); holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL));
holTable.colorHeader (color_label); holTable.colorHeader (color_label);
Config::const_iterator it;
std::map <time_t, std::vector<std::string>> hm; // we need to store multiple holidays per day std::map <time_t, std::vector<std::string>> hm; // we need to store multiple holidays per day
for (it = context.config.begin (); it != context.config.end (); ++it) for (auto& it : context.config)
if (it->first.substr (0, 8) == "holiday.") if (it.first.substr (0, 8) == "holiday.")
if (it->first.substr (it->first.size () - 4) == "name") if (it.first.substr (it.first.size () - 4) == "name")
{ {
std::string holName = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".name"); std::string holName = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".date"); std::string holDate = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".date");
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday")); Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
if (date_after < hDate && hDate < date_before) if (date_after < hDate && hDate < date_before)
{
hm[hDate.toEpoch()].push_back(holName); hm[hDate.toEpoch()].push_back(holName);
} }
}
std::string format = context.config.get ("report." + std::string format = context.config.get ("report." +
context.config.get ("calendar.details.report") + context.config.get ("calendar.details.report") +
@ -389,11 +384,10 @@ int CmdCalendar::execute (std::string& output)
if (format == "") if (format == "")
format = context.config.get ("dateformat"); format = context.config.get ("dateformat");
std::map <time_t, std::vector<std::string>>::iterator hm_it; for (auto& hm_it : hm)
for (hm_it = hm.begin(); hm_it != hm.end(); ++hm_it)
{ {
std::vector <std::string> v = hm_it->second; std::vector <std::string> v = hm_it.second;
Date hDate (hm_it->first); Date hDate (hm_it.first);
std::string d = hDate.toString (format); std::string d = hDate.toString (format);
for (size_t i = 0; i < v.size(); i++) for (size_t i = 0; i < v.size(); i++)
{ {
@ -535,12 +529,11 @@ std::string CmdCalendar::renderMonths (
// colorize holidays // colorize holidays
if (context.config.get ("calendar.holidays") != "none") if (context.config.get ("calendar.holidays") != "none")
{ {
Config::const_iterator hol; for (auto& hol : context.config)
for (hol = context.config.begin (); hol != context.config.end (); ++hol) if (hol.first.substr (0, 8) == "holiday.")
if (hol->first.substr (0, 8) == "holiday.") if (hol.first.substr (hol.first.size () - 4) == "date")
if (hol->first.substr (hol->first.size () - 4) == "date")
{ {
std::string value = hol->second; std::string value = hol.second;
Date holDate (value.c_str (), context.config.get ("dateformat.holiday")); Date holDate (value.c_str (), context.config.get ("dateformat.holiday"));
if (holDate.day () == d && if (holDate.day () == d &&
holDate.month () == months[mpl] && holDate.month () == months[mpl] &&
@ -559,21 +552,20 @@ std::string CmdCalendar::renderMonths (
if (context.config.get ("calendar.details") != "none") if (context.config.get ("calendar.details") != "none")
{ {
context.config.set ("due", 0); context.config.set ("due", 0);
std::vector <Task>::iterator task; for (auto& task : all)
for (task = all.begin (); task != all.end (); ++task)
{ {
if (task->getStatus () == Task::pending && if (task.getStatus () == Task::pending &&
!task->hasTag ("nocal") && !task.hasTag ("nocal") &&
task->has ("due")) task.has ("due"))
{ {
std::string due = task->get ("due"); std::string due = task.get ("due");
Date duedmy (strtol (due.c_str(), NULL, 10)); Date duedmy (strtol (due.c_str(), NULL, 10));
if (duedmy.day () == d && if (duedmy.day () == d &&
duedmy.month () == months[mpl] && duedmy.month () == months[mpl] &&
duedmy.year () == years[mpl]) duedmy.year () == years[mpl])
{ {
switch (task->getDateState ("due")) switch (task.getDateState ("due"))
{ {
case Task::dateNotDue: case Task::dateNotDue:
break; break;

View file

@ -55,9 +55,8 @@ int CmdColor::execute (std::string& output)
// Get the non-attribute, non-fancy command line arguments. // Get the non-attribute, non-fancy command line arguments.
bool legend = false; bool legend = false;
std::vector <std::string> words = context.cli.getWords (); std::vector <std::string> words = context.cli.getWords ();
std::vector <std::string>::iterator word; for (auto& word : words)
for (word = words.begin (); word != words.end (); ++word) if (closeEnough ("legend", word))
if (closeEnough ("legend", *word))
legend = true; legend = true;
std::stringstream out; std::stringstream out;
@ -74,19 +73,18 @@ int CmdColor::execute (std::string& output)
view.add (Column::factory ("string", STRING_CMD_COLOR_COLOR)); view.add (Column::factory ("string", STRING_CMD_COLOR_COLOR));
view.add (Column::factory ("string", STRING_CMD_COLOR_DEFINITION)); view.add (Column::factory ("string", STRING_CMD_COLOR_DEFINITION));
Config::const_iterator item; for (auto& item : context.config)
for (item = context.config.begin (); item != context.config.end (); ++item)
{ {
// Skip items with 'color' in their name, that are not referring to // Skip items with 'color' in their name, that are not referring to
// actual colors. // actual colors.
if (item->first != "_forcecolor" && if (item.first != "_forcecolor" &&
item->first != "color" && item.first != "color" &&
item->first.find ("color") == 0) item.first.find ("color") == 0)
{ {
Color color (context.config.get (item->first)); Color color (context.config.get (item.first));
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, item->first, color); view.set (row, 0, item.first, color);
view.set (row, 1, item->second, color); view.set (row, 1, item.second, color);
} }
} }
@ -106,7 +104,7 @@ int CmdColor::execute (std::string& output)
Color six ("red on color173"); Color six ("red on color173");
std::string swatch; std::string swatch;
for (word = words.begin (); word != words.end (); ++word) for (auto word = words.begin (); word != words.end (); ++word)
{ {
if (word != words.begin ()) if (word != words.begin ())
swatch += " "; swatch += " ";

View file

@ -57,9 +57,8 @@ int CmdColumns::execute (std::string& output)
// Include all columns in the table. // Include all columns in the table.
std::vector <std::string> names; std::vector <std::string> names;
std::map <std::string, Column*>::const_iterator col; for (auto& col : context.columns)
for (col = context.columns.begin (); col != context.columns.end (); ++col) names.push_back (col.first);
names.push_back (col->first);
std::sort (names.begin (), names.end ()); std::sort (names.begin (), names.end ());
@ -77,19 +76,18 @@ int CmdColumns::execute (std::string& output)
formats.colorOdd (alternate); formats.colorOdd (alternate);
formats.intraColorOdd (alternate); formats.intraColorOdd (alternate);
std::vector <std::string>::iterator name; for (auto& name : names)
for (name = names.begin (); name != names.end (); ++name)
{ {
if (words.size () == 0 || if (words.size () == 0 ||
find (*name, words[0], false) != std::string::npos) find (name, words[0], false) != std::string::npos)
{ {
const std::vector <std::string> styles = context.columns[*name]->styles (); const std::vector <std::string> styles = context.columns[name]->styles ();
const std::vector <std::string> examples = context.columns[*name]->examples (); const std::vector <std::string> examples = context.columns[name]->examples ();
for (unsigned int i = 0; i < styles.size (); ++i) for (unsigned int i = 0; i < styles.size (); ++i)
{ {
int row = formats.addRow (); int row = formats.addRow ();
formats.set (row, 0, i == 0 ? *name : ""); formats.set (row, 0, i == 0 ? name : "");
formats.set (row, 1, styles[i] + (i == 0 ? "*" : "")); formats.set (row, 1, styles[i] + (i == 0 ? "*" : ""));
formats.set (row, 2, i < examples.size () ? examples[i] : ""); formats.set (row, 2, i < examples.size () ? examples[i] : "");
} }
@ -120,16 +118,14 @@ int CmdCompletionColumns::execute (std::string& output)
{ {
// Include all columns. // Include all columns.
std::vector <std::string> names; std::vector <std::string> names;
std::map <std::string, Column*>::const_iterator col; for (auto& col : context.columns)
for (col = context.columns.begin (); col != context.columns.end (); ++col) names.push_back (col.first);
names.push_back (col->first);
std::sort (names.begin (), names.end ()); std::sort (names.begin (), names.end ());
// Render only the column names. // Render only the column names.
std::vector <std::string>::iterator name; for (auto& name : names)
for (name = names.begin (); name != names.end (); ++name) output += name + "\n";
output += *name + "\n";
return 0; return 0;
} }

View file

@ -51,21 +51,15 @@ int CmdCompletionCommands::execute (std::string& output)
// Get a list of all commands. // Get a list of all commands.
std::vector <std::string> commands; std::vector <std::string> commands;
std::map <std::string, Command*>::iterator command; for (auto& command : context.commands)
for (command = context.commands.begin (); commands.push_back (command.first);
command != context.commands.end ();
++command)
{
commands.push_back (command->first);
}
// Sort alphabetically. // Sort alphabetically.
std::sort (commands.begin (), commands.end ()); std::sort (commands.begin (), commands.end ());
std::stringstream out; std::stringstream out;
std::vector <std::string>::iterator c; for (auto& c : commands)
for (c = commands.begin (); c != commands.end (); ++c) out << c << "\n";
out << *c << "\n";
output = out.str (); output = out.str ();
return 0; return 0;
@ -87,21 +81,15 @@ int CmdZshCommands::execute (std::string& output)
// Get a list of all commands. // Get a list of all commands.
std::vector <std::string> commands; std::vector <std::string> commands;
std::map <std::string, Command*>::iterator command; for (auto& command : context.commands)
for (command = context.commands.begin (); commands.push_back (command.first);
command != context.commands.end ();
++command)
{
commands.push_back (command->first);
}
// Sort alphabetically. // Sort alphabetically.
std::sort (commands.begin (), commands.end ()); std::sort (commands.begin (), commands.end ());
std::stringstream out; std::stringstream out;
std::vector <std::string>::iterator c; for (auto& c : commands)
for (c = commands.begin (); c != commands.end (); ++c) out << c << ":" << context.commands[c]->description () << "\n";
out << *c << ":" << context.commands[*c]->description () << "\n";
output = out.str (); output = out.str ();
return 0; return 0;

View file

@ -56,12 +56,11 @@ bool CmdConfig::setConfigVariable (std::string name, std::string value, bool con
bool found = false; bool found = false;
bool change = false; bool change = false;
std::vector <std::string>::iterator line; for (auto& line : contents)
for (line = contents.begin (); line != contents.end (); ++line)
{ {
// If there is a comment on the line, it must follow the pattern. // If there is a comment on the line, it must follow the pattern.
std::string::size_type comment = line->find ("#"); std::string::size_type comment = line.find ("#");
std::string::size_type pos = line->find (name + "="); std::string::size_type pos = line.find (name + "=");
if (pos != std::string::npos && if (pos != std::string::npos &&
(comment == std::string::npos || (comment == std::string::npos ||
@ -72,9 +71,9 @@ bool CmdConfig::setConfigVariable (std::string name, std::string value, bool con
confirm (format (STRING_CMD_CONFIG_CONFIRM, name, context.config.get (name), value))) confirm (format (STRING_CMD_CONFIG_CONFIRM, name, context.config.get (name), value)))
{ {
if (comment != std::string::npos) if (comment != std::string::npos)
*line = name + "=" + json::encode (value) + " " + line->substr (comment); line = name + "=" + json::encode (value) + " " + line.substr (comment);
else else
*line = name + "=" + json::encode (value); line = name + "=" + json::encode (value);
change = true; change = true;
} }
@ -106,8 +105,7 @@ int CmdConfig::unsetConfigVariable (std::string name, bool confirmation /* = fal
bool found = false; bool found = false;
bool change = false; bool change = false;
std::vector <std::string>::iterator line; for (auto line = contents.begin (); line != contents.end (); )
for (line = contents.begin (); line != contents.end (); )
{ {
bool lineDeleted = false; bool lineDeleted = false;
@ -243,9 +241,8 @@ int CmdCompletionConfig::execute (std::string& output)
context.config.all (configs); context.config.all (configs);
std::sort (configs.begin (), configs.end ()); std::sort (configs.begin (), configs.end ());
std::vector <std::string>::iterator config; for (auto& config : configs)
for (config = configs.begin (); config != configs.end (); ++config) output += config + "\n";
output += *config + "\n";
return 0; return 0;
} }

View file

@ -109,10 +109,9 @@ std::vector <std::string> CmdContext::getContexts ()
{ {
std::vector <std::string> contexts; std::vector <std::string> contexts;
Config::const_iterator name; for (auto& name : context.config)
for (name = context.config.begin (); name != context.config.end (); ++name) if (name.first.substr (0, 8) == "context.")
if (name->first.substr (0, 8) == "context.") contexts.push_back (name.first.substr (8));
contexts.push_back (name->first.substr (8));
return contexts; return contexts;
} }
@ -140,7 +139,7 @@ int CmdContext::defineContext (std::vector <std::string>& words, std::stringstre
// Check if the value is a proper filter by filtering current pending.data // Check if the value is a proper filter by filtering current pending.data
Filter filter; Filter filter;
std::vector <Task> filtered; std::vector <Task> filtered;
const std::vector <Task>& pending = context.tdb2.pending.get_tasks (); auto pending = context.tdb2.pending.get_tasks ();
try try
{ {
@ -246,13 +245,12 @@ int CmdContext::listContexts (std::vector <std::string>& words, std::stringstrea
Color label (context.config.get ("color.label")); Color label (context.config.get ("color.label"));
view.colorHeader (label); view.colorHeader (label);
std::vector <std::string>::iterator userContext; for (auto& userContext : contexts)
for (userContext = contexts.begin (); userContext != contexts.end (); ++userContext)
{ {
std::string definition = context.config.get ("context." + *userContext); std::string definition = context.config.get ("context." + userContext);
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, *userContext); view.set (row, 0, userContext);
view.set (row, 1, definition); view.set (row, 1, definition);
} }
@ -369,9 +367,8 @@ int CmdCompletionContext::execute (std::string& output)
{ {
std::vector <std::string> userContexts = CmdContext::getContexts (); std::vector <std::string> userContexts = CmdContext::getContexts ();
std::vector <std::string>::iterator userContext; for (auto& userContext : userContexts)
for (userContext = userContexts.begin (); userContext != userContexts.end (); ++userContext) output += userContext + "\n";
output += *userContext + "\n";
return 0; return 0;
} }

View file

@ -55,9 +55,8 @@ int CmdCount::execute (std::string& output)
// Find number of matching tasks. Skip recurring parent tasks. // Find number of matching tasks. Skip recurring parent tasks.
int count = 0; int count = 0;
std::vector <Task>::iterator it; for (auto& task : filtered)
for (it = filtered.begin (); it != filtered.end (); ++it) if (task.getStatus () != Task::recurring)
if (it->getStatus () != Task::recurring)
++count; ++count;
output = format (count) + "\n"; output = format (count) + "\n";

View file

@ -118,13 +118,12 @@ int CmdCustom::execute (std::string& output)
std::vector <std::string> sortColumns; std::vector <std::string> sortColumns;
// Add the break columns, if any. // Add the break columns, if any.
std::vector <std::string>::iterator so; for (auto& so : sortOrder)
for (so = sortOrder.begin (); so != sortOrder.end (); ++so)
{ {
std::string name; std::string name;
bool ascending; bool ascending;
bool breakIndicator; bool breakIndicator;
context.decomposeSortField (*so, name, ascending, breakIndicator); context.decomposeSortField (so, name, ascending, breakIndicator);
if (breakIndicator) if (breakIndicator)
view.addBreak (name); view.addBreak (name);
@ -211,17 +210,15 @@ int CmdCustom::execute (std::string& output)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CmdCustom::validateReportColumns (std::vector <std::string>& columns) void CmdCustom::validateReportColumns (std::vector <std::string>& columns)
{ {
std::vector <std::string>::iterator i; for (auto& col : columns)
for (i = columns.begin (); i != columns.end (); ++i) legacyColumnMap (col);
legacyColumnMap (*i);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CmdCustom::validateSortColumns (std::vector <std::string>& columns) void CmdCustom::validateSortColumns (std::vector <std::string>& columns)
{ {
std::vector <std::string>::iterator i; for (auto& col : columns)
for (i = columns.begin (); i != columns.end (); ++i) legacySortColumnMap (col);
legacySortColumnMap (*i);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -66,66 +66,64 @@ int CmdDelete::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
if (task->getStatus () != Task::deleted) if (task.getStatus () != Task::deleted)
{ {
// Delete the specified task. // Delete the specified task.
std::string question; std::string question;
if (task->id) if (task.id)
question = format (STRING_CMD_DELETE_CONFIRM, question = format (STRING_CMD_DELETE_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
else else
question = format (STRING_CMD_DELETE_CONFIRM, question = format (STRING_CMD_DELETE_CONFIRM,
task->get ("uuid"), task.get ("uuid"),
task->get ("description")); task.get ("description"));
task->modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task->setStatus (Task::deleted); task.setStatus (Task::deleted);
if (! task->has ("end")) if (! task.has ("end"))
task->setAsNow ("end"); task.setAsNow ("end");
if (permission (*task, question, filtered.size ())) if (permission (task, question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (task);
++count; ++count;
context.tdb2.modify (*task); context.tdb2.modify (task);
feedback_affected (STRING_CMD_DELETE_TASK, *task); feedback_affected (STRING_CMD_DELETE_TASK, task);
feedback_unblocked (*task); feedback_unblocked (task);
dependencyChainOnComplete (*task); dependencyChainOnComplete (task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task); projectChanges[task.get ("project")] = onProjectChange (task);
// Delete siblings. // Delete siblings.
if (task->has ("parent")) if (task.has ("parent"))
{ {
if ((context.config.get ("recurrence.confirmation") == "prompt" if ((context.config.get ("recurrence.confirmation") == "prompt"
&& confirm (STRING_CMD_DELETE_CONFIRM_R)) || && confirm (STRING_CMD_DELETE_CONFIRM_R)) ||
context.config.getBoolean ("recurrence.confirmation")) context.config.getBoolean ("recurrence.confirmation"))
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (task);
std::vector <Task>::iterator sibling; for (auto& sibling : siblings)
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
sibling->modify (Task::modAnnotate); sibling.modify (Task::modAnnotate);
sibling->setStatus (Task::deleted); sibling.setStatus (Task::deleted);
if (! sibling->has ("end")) if (! sibling.has ("end"))
sibling->setAsNow ("end"); sibling.setAsNow ("end");
updateRecurrenceMask (*sibling); updateRecurrenceMask (sibling);
context.tdb2.modify (*sibling); context.tdb2.modify (sibling);
feedback_affected (STRING_CMD_DELETE_TASK_R, *sibling); feedback_affected (STRING_CMD_DELETE_TASK_R, sibling);
feedback_unblocked (*sibling); feedback_unblocked (sibling);
++count; ++count;
} }
// Delete the parent // Delete the parent
Task parent; Task parent;
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task.get ("parent"), parent);
parent.setStatus (Task::deleted); parent.setStatus (Task::deleted);
if (! parent.has ("end")) if (! parent.has ("end"))
parent.setAsNow ("end"); parent.setAsNow ("end");
@ -137,23 +135,22 @@ int CmdDelete::execute (std::string& output)
// Task potentially has child tasks - optionally delete them. // Task potentially has child tasks - optionally delete them.
else else
{ {
std::vector <Task> children = context.tdb2.children (*task); std::vector <Task> children = context.tdb2.children (task);
if (children.size () && if (children.size () &&
(context.config.getBoolean ("recurrence.confirmation") || (context.config.getBoolean ("recurrence.confirmation") ||
confirm (STRING_CMD_DELETE_CONFIRM_R))) confirm (STRING_CMD_DELETE_CONFIRM_R)))
{ {
std::vector <Task>::iterator child; for (auto& child : children)
for (child = children.begin (); child != children.end (); ++child)
{ {
child->modify (Task::modAnnotate); child.modify (Task::modAnnotate);
child->setStatus (Task::deleted); child.setStatus (Task::deleted);
if (! child->has ("end")) if (! child.has ("end"))
child->setAsNow ("end"); child.setAsNow ("end");
updateRecurrenceMask (*child); updateRecurrenceMask (child);
context.tdb2.modify (*child); context.tdb2.modify (child);
feedback_affected (STRING_CMD_DELETE_TASK_R, *child); feedback_affected (STRING_CMD_DELETE_TASK_R, child);
feedback_unblocked (*child); feedback_unblocked (child);
++count; ++count;
} }
} }
@ -170,18 +167,17 @@ int CmdDelete::execute (std::string& output)
else else
{ {
std::cout << format (STRING_CMD_DELETE_NOT_DEL, std::cout << format (STRING_CMD_DELETE_NOT_DEL,
task->id, task.id,
task->get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;
} }
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_DELETE_1 : STRING_CMD_DELETE_N, count); feedback_affected (count == 1 ? STRING_CMD_DELETE_1 : STRING_CMD_DELETE_N, count);
return rc; return rc;

View file

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

View file

@ -305,13 +305,12 @@ int CmdDiagnostics::execute (std::string& output)
std::vector <std::string> hooks = context.hooks.list (); std::vector <std::string> hooks = context.hooks.list ();
if (hooks.size ()) if (hooks.size ())
{ {
std::vector <std::string>::iterator h; for (auto& hook : hooks)
for (h = hooks.begin (); h != hooks.end (); ++h)
{ {
Path p (*h); Path p (hook);
std::string name = p.name (); std::string name = p.name ();
out << " " out << " "
<< *h << hook
<< (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC)) << (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC))
<< (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") << (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "")
<< ((name.substr (0, 6) == "on-add" || << ((name.substr (0, 6) == "on-add" ||
@ -345,10 +344,9 @@ int CmdDiagnostics::execute (std::string& output)
std::map <std::string, int> seen; std::map <std::string, int> seen;
std::vector <std::string> dups; std::vector <std::string> dups;
std::string uuid; std::string uuid;
std::vector <Task>::iterator i; for (auto& i : all)
for (i = all.begin (); i != all.end (); ++i)
{ {
uuid = i->get ("uuid"); uuid = i.get ("uuid");
if (seen.find (uuid) != seen.end ()) if (seen.find (uuid) != seen.end ())
dups.push_back (uuid); dups.push_back (uuid);
else else
@ -361,9 +359,8 @@ int CmdDiagnostics::execute (std::string& output)
if (dups.size ()) if (dups.size ())
{ {
std::vector <std::string>::iterator d; for (auto& d : dups)
for (d = dups.begin (); d != dups.end (); ++d) out << " " << format (STRING_CMD_DIAG_UUID_DUP, d) << "\n";
out << " " << format (STRING_CMD_DIAG_UUID_DUP, *d) << "\n";
} }
else else
{ {

View file

@ -66,44 +66,43 @@ int CmdDone::execute (std::string& output)
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
bool nagged = false; bool nagged = false;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
if (task->getStatus () == Task::pending || if (task.getStatus () == Task::pending ||
task->getStatus () == Task::waiting) task.getStatus () == Task::waiting)
{ {
// Complete the specified task. // Complete the specified task.
std::string question = format (STRING_CMD_DONE_CONFIRM, std::string question = format (STRING_CMD_DONE_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task->setStatus (Task::completed); task.setStatus (Task::completed);
if (! task->has ("end")) if (! task.has ("end"))
task->setAsNow ("end"); task.setAsNow ("end");
// Stop the task, if started. // Stop the task, if started.
if (task->has ("start")) if (task.has ("start"))
{ {
task->remove ("start"); task.remove ("start");
if (context.config.getBoolean ("journal.time")) if (context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.stop.annotation")); task.addAnnotation (context.config.get ("journal.time.stop.annotation"));
} }
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (task);
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_DONE_TASK, *task); feedback_affected (STRING_CMD_DONE_TASK, task);
feedback_unblocked (*task); feedback_unblocked (task);
if (!nagged) if (!nagged)
nagged = nag (*task); nagged = nag (task);
dependencyChainOnComplete (*task); dependencyChainOnComplete (task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task); projectChanges[task.get ("project")] = onProjectChange (task);
} }
else else
{ {
@ -116,18 +115,17 @@ int CmdDone::execute (std::string& output)
else else
{ {
std::cout << format (STRING_CMD_DONE_NOTPEND, std::cout << format (STRING_CMD_DONE_NOTPEND,
task->id, task.id,
task->get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;
} }
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_DONE_1 : STRING_CMD_DONE_N, count); feedback_affected (count == 1 ? STRING_CMD_DONE_1 : STRING_CMD_DONE_N, count);
return rc; return rc;

View file

@ -65,11 +65,10 @@ int CmdDuplicate::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
// Duplicate the specified task. // Duplicate the specified task.
Task dup (*task); Task dup (task);
dup.id = 0; // Reset, and TDB2::add will set. dup.id = 0; // Reset, and TDB2::add will set.
dup.set ("uuid", uuid ()); // Needs a new UUID. dup.set ("uuid", uuid ()); // Needs a new UUID.
dup.remove ("start"); // Does not inherit start date. dup.remove ("start"); // Does not inherit start date.
@ -83,7 +82,7 @@ int CmdDuplicate::execute (std::string& output)
dup.remove ("recur"); dup.remove ("recur");
dup.remove ("until"); dup.remove ("until");
dup.remove ("imask"); dup.remove ("imask");
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task->id) std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.id)
<< "\n"; << "\n";
} }
@ -91,7 +90,7 @@ int CmdDuplicate::execute (std::string& output)
else if (dup.getStatus () == Task::recurring) else if (dup.getStatus () == Task::recurring)
{ {
dup.remove ("mask"); dup.remove ("mask");
std::cout << format (STRING_CMD_DUPLICATE_REC, task->id) std::cout << format (STRING_CMD_DUPLICATE_REC, task.id)
<< "\n"; << "\n";
} }
@ -102,13 +101,13 @@ int CmdDuplicate::execute (std::string& output)
if (permission (dup, if (permission (dup,
format (STRING_CMD_DUPLICATE_CONFIRM, format (STRING_CMD_DUPLICATE_CONFIRM,
task->id, task.id,
task->get ("description")), task.get ("description")),
filtered.size ())) filtered.size ()))
{ {
context.tdb2.add (dup); context.tdb2.add (dup);
++count; ++count;
feedback_affected (STRING_CMD_DUPLICATE_TASK, *task); feedback_affected (STRING_CMD_DUPLICATE_TASK, task);
if (context.verbose ("new-id")) if (context.verbose ("new-id"))
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.id) + "\n"; std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.id) + "\n";
@ -116,7 +115,7 @@ int CmdDuplicate::execute (std::string& output)
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.get ("uuid")) + "\n"; std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.get ("uuid")) + "\n";
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task); projectChanges[task.get ("project")] = onProjectChange (task);
} }
else else
{ {
@ -128,10 +127,9 @@ int CmdDuplicate::execute (std::string& output)
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_DUPLICATE_1 : STRING_CMD_DUPLICATE_N, count); feedback_affected (count == 1 ? STRING_CMD_DUPLICATE_1 : STRING_CMD_DUPLICATE_N, count);
return rc; return rc;

View file

@ -66,10 +66,9 @@ int CmdEdit::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
// Find number of matching tasks. // Find number of matching tasks.
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) if (editFile (task))
if (editFile (*task)) context.tdb2.modify (task);
context.tdb2.modify (*task);
return 0; return 0;
} }
@ -236,12 +235,11 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task.getAnnotations (annotations); task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator anno; for (auto& anno : annotations)
for (anno = annotations.begin (); anno != annotations.end (); ++anno)
{ {
Date dt (strtol (anno->first.substr (11).c_str (), NULL, 10)); Date dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
before << " Annotation: " << dt.toString (dateformat) before << " Annotation: " << dt.toString (dateformat)
<< " -- " << anno->second << "\n"; << " -- " << anno.second << "\n";
} }
Date now; Date now;
@ -272,30 +270,28 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
// UDAs // UDAs
std::vector <std::string> udas; std::vector <std::string> udas;
std::map <std::string, Column*>::iterator col; for (auto& col : context.columns)
for (col = context.columns.begin (); col != context.columns.end (); ++col) if (context.config.get ("uda." + col.first + ".type") != "")
if (context.config.get ("uda." + col->first + ".type") != "") udas.push_back (col.first);
udas.push_back (col->first);
if (udas.size ()) if (udas.size ())
{ {
before << "# " << STRING_EDIT_UDA_SEP << "\n"; before << "# " << STRING_EDIT_UDA_SEP << "\n";
std::sort (udas.begin (), udas.end ()); std::sort (udas.begin (), udas.end ());
std::vector <std::string>::iterator uda; for (auto& uda : udas)
for (uda = udas.begin (); uda != udas.end (); ++uda)
{ {
int pad = 13 - uda->length (); int pad = 13 - uda.length ();
std::string padding = ""; std::string padding = "";
if (pad > 0) if (pad > 0)
padding = std::string (pad, ' '); padding = std::string (pad, ' ');
std::string type = context.config.get ("uda." + *uda + ".type"); std::string type = context.config.get ("uda." + uda + ".type");
if (type == "string" || type == "numeric") if (type == "string" || type == "numeric")
before << " UDA " << *uda << ": " << padding << task.get (*uda) << "\n"; before << " UDA " << uda << ": " << padding << task.get (uda) << "\n";
else if (type == "date") else if (type == "date")
before << " UDA " << *uda << ": " << padding << formatDate (task, *uda, dateformat) << "\n"; before << " UDA " << uda << ": " << padding << formatDate (task, uda, dateformat) << "\n";
else if (type == "duration") else if (type == "duration")
before << " UDA " << *uda << ": " << padding << formatDuration (task, *uda) << "\n"; before << " UDA " << uda << ": " << padding << formatDuration (task, uda) << "\n";
} }
} }
@ -307,15 +303,14 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
{ {
before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n"; before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n";
std::sort (orphans.begin (), orphans.end ()); std::sort (orphans.begin (), orphans.end ());
std::vector <std::string>::iterator orphan; for (auto& orphan : orphans)
for (orphan = orphans.begin (); orphan != orphans.end (); ++orphan)
{ {
int pad = 6 - orphan->length (); int pad = 6 - orphan.length ();
std::string padding = ""; std::string padding = "";
if (pad > 0) if (pad > 0)
padding = std::string (pad, ' '); padding = std::string (pad, ' ');
before << " UDA Orphan " << *orphan << ": " << padding << task.get (*orphan) << "\n"; before << " UDA Orphan " << orphan << ": " << padding << task.get (orphan) << "\n";
} }
} }
@ -657,35 +652,33 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
split (dependencies, value, ","); split (dependencies, value, ",");
task.remove ("depends"); task.remove ("depends");
std::vector <std::string>::iterator dep; for (auto& dep : dependencies)
for (dep = dependencies.begin (); dep != dependencies.end (); ++dep)
{ {
if (dep->length () >= 7) if (dep.length () >= 7)
task.addDependency (*dep); task.addDependency (dep);
else else
task.addDependency ((int) strtol (dep->c_str (), NULL, 10)); task.addDependency ((int) strtol (dep.c_str (), NULL, 10));
} }
// UDAs // UDAs
std::map <std::string, Column*>::iterator col; for (auto& col : context.columns)
for (col = context.columns.begin (); col != context.columns.end (); ++col)
{ {
std::string type = context.config.get ("uda." + col->first + ".type"); std::string type = context.config.get ("uda." + col.first + ".type");
if (type != "") if (type != "")
{ {
std::string value = findValue (after, "\n UDA " + col->first + ":"); std::string value = findValue (after, "\n UDA " + col.first + ":");
if ((task.get (col->first) != value) && (type != "date" || if ((task.get (col.first) != value) && (type != "date" ||
(task.get (col->first) != Date (value, dateformat).toEpochString ())) && (task.get (col.first) != Date (value, dateformat).toEpochString ())) &&
(type != "duration" || (type != "duration" ||
(task.get (col->first) != (std::string) Duration (value) ))) (task.get (col.first) != (std::string) Duration (value))))
{ {
if (value != "") if (value != "")
{ {
context.footnote (format (STRING_EDIT_UDA_MOD, col->first)); context.footnote (format (STRING_EDIT_UDA_MOD, col.first));
if (type == "string") if (type == "string")
{ {
task.set (col->first, value); task.set (col.first, value);
} }
else if (type == "numeric") else if (type == "numeric")
{ {
@ -693,25 +686,25 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
double d; double d;
if (n.getNumber (d) && if (n.getNumber (d) &&
n.depleted ()) n.depleted ())
task.set (col->first, value); task.set (col.first, value);
else else
throw format (STRING_UDA_NUMERIC, value); throw format (STRING_UDA_NUMERIC, value);
} }
else if (type == "date") else if (type == "date")
{ {
Date d (value, dateformat); Date d (value, dateformat);
task.set (col->first, d.toEpochString ()); task.set (col.first, d.toEpochString ());
} }
else if (type == "duration") else if (type == "duration")
{ {
Duration d (value); Duration d (value);
task.set (col->first, (time_t) d); task.set (col.first, (time_t) d);
} }
} }
else else
{ {
context.footnote (format (STRING_EDIT_UDA_DEL, col->first)); context.footnote (format (STRING_EDIT_UDA_DEL, col.first));
task.remove (col->first); task.remove (col.first);
} }
} }
} }
@ -719,14 +712,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
// UDA orphans // UDA orphans
std::vector <std::string> orphanValues = findValues (after, "\n UDA Orphan "); std::vector <std::string> orphanValues = findValues (after, "\n UDA Orphan ");
std::vector <std::string>::iterator orphan; for (auto& orphan : orphanValues)
for (orphan = orphanValues.begin (); orphan != orphanValues.end (); ++orphan)
{ {
std::string::size_type colon = orphan->find (':'); std::string::size_type colon = orphan.find (':');
if (colon != std::string::npos) if (colon != std::string::npos)
{ {
std::string name = trim (orphan->substr (0, colon), "\t "); std::string name = trim (orphan.substr (0, colon), "\t ");
std::string value = trim (orphan->substr (colon + 1), "\t "); std::string value = trim (orphan.substr (colon + 1), "\t ");
if (value != "") if (value != "")
task.set (name, value); task.set (name, value);

View file

@ -70,8 +70,7 @@ int CmdExport::execute (std::string& output)
output += "[\n"; output += "[\n";
int counter = 0; int counter = 0;
std::vector <Task>::iterator task; for (auto task = filtered.begin (); task != filtered.end (); ++task)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
if (task != filtered.begin ()) if (task != filtered.begin ())
{ {

View file

@ -55,12 +55,11 @@ int CmdGet::execute (std::string& output)
bool found = false; bool found = false;
std::vector <std::string> results; std::vector <std::string> results;
std::vector <std::string>::iterator word; for (auto& word : words)
for (word = words.begin (); word != words.end (); ++word)
{ {
Task t; Task t;
Variant result; Variant result;
if (context.dom.get (*word, t, result)) if (context.dom.get (word, t, result))
{ {
results.push_back ((std::string) result); results.push_back ((std::string) result);
found = true; found = true;

View file

@ -62,33 +62,31 @@ int CmdHelp::execute (std::string& output)
// Obsolete method of getting a list of all commands. // Obsolete method of getting a list of all commands.
std::vector <std::string> all; std::vector <std::string> all;
std::map <std::string, Command*>::iterator i; for (auto& cmd : context.commands)
for (i = context.commands.begin (); i != context.commands.end (); ++i) all.push_back (cmd.first);
all.push_back (i->first);
// Sort alphabetically by usage. // Sort alphabetically by usage.
std::sort (all.begin (), all.end ()); std::sort (all.begin (), all.end ());
// Add the regular commands. // Add the regular commands.
std::vector <std::string>::iterator name; for (auto& name : all)
for (name = all.begin (); name != all.end (); ++name)
{ {
if ((*name)[0] != '_') if (name[0] != '_')
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 1, context.commands[*name]->usage ()); view.set (row, 1, context.commands[name]->usage ());
view.set (row, 2, context.commands[*name]->description ()); view.set (row, 2, context.commands[name]->description ());
} }
} }
// Add the helper commands. // Add the helper commands.
for (name = all.begin (); name != all.end (); ++name) for (auto& name : all)
{ {
if ((*name)[0] == '_') if (name[0] == '_')
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 1, context.commands[*name]->usage ()); view.set (row, 1, context.commands[name]->usage ());
view.set (row, 2, context.commands[*name]->description ()); view.set (row, 2, context.commands[name]->description ());
} }
} }
@ -96,14 +94,13 @@ int CmdHelp::execute (std::string& output)
row = view.addRow (); row = view.addRow ();
view.set (row, 1, " "); view.set (row, 1, " ");
std::map <std::string, std::string>::iterator alias; for (auto& alias : context.config)
for (alias = context.config.begin (); alias != context.config.end (); ++alias)
{ {
if (alias->first.substr (0, 6) == "alias.") if (alias.first.substr (0, 6) == "alias.")
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 1, alias->first.substr (6)); view.set (row, 1, alias.first.substr (6));
view.set (row, 2, format (STRING_CMD_HELP_ALIASED, alias->second)); view.set (row, 2, format (STRING_CMD_HELP_ALIASED, alias.second));
} }
} }

View file

@ -62,14 +62,13 @@ int CmdHistoryMonthly::execute (std::string& output)
std::vector <Task> filtered; std::vector <Task> filtered;
filter.subset (filtered); filter.subset (filtered);
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Date entry (task->get_date ("entry")); Date entry (task.get_date ("entry"));
Date end; Date end;
if (task->has ("end")) if (task.has ("end"))
end = Date (task->get_date ("end")); end = Date (task.get_date ("end"));
time_t epoch = entry.startOfMonth ().toEpoch (); time_t epoch = entry.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -78,7 +77,7 @@ int CmdHistoryMonthly::execute (std::string& output)
++addedGroup[epoch]; ++addedGroup[epoch];
// All deleted tasks have an end date. // All deleted tasks have an end date.
if (task->getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
epoch = end.startOfMonth ().toEpoch (); epoch = end.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -86,7 +85,7 @@ int CmdHistoryMonthly::execute (std::string& output)
} }
// All completed tasks have an end date. // All completed tasks have an end date.
else if (task->getStatus () == Task::completed) else if (task.getStatus () == Task::completed)
{ {
epoch = end.startOfMonth ().toEpoch (); epoch = end.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -113,16 +112,15 @@ int CmdHistoryMonthly::execute (std::string& output)
int priorYear = 0; int priorYear = 0;
int row = 0; int row = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
row = view.addRow (); row = view.addRow ();
totalAdded += addedGroup [i->first]; totalAdded += addedGroup [i.first];
totalCompleted += completedGroup [i->first]; totalCompleted += completedGroup [i.first];
totalDeleted += deletedGroup [i->first]; totalDeleted += deletedGroup [i.first];
Date dt (i->first); Date dt (i.first);
int m, d, y; int m, d, y;
dt.toMDY (m, d, y); dt.toMDY (m, d, y);
@ -135,22 +133,22 @@ int CmdHistoryMonthly::execute (std::string& output)
int net = 0; int net = 0;
if (addedGroup.find (i->first) != addedGroup.end ()) if (addedGroup.find (i.first) != addedGroup.end ())
{ {
view.set (row, 2, addedGroup[i->first]); view.set (row, 2, addedGroup[i.first]);
net +=addedGroup[i->first]; net +=addedGroup[i.first];
} }
if (completedGroup.find (i->first) != completedGroup.end ()) if (completedGroup.find (i.first) != completedGroup.end ())
{ {
view.set (row, 3, completedGroup[i->first]); view.set (row, 3, completedGroup[i.first]);
net -= completedGroup[i->first]; net -= completedGroup[i.first];
} }
if (deletedGroup.find (i->first) != deletedGroup.end ()) if (deletedGroup.find (i.first) != deletedGroup.end ())
{ {
view.set (row, 4, deletedGroup[i->first]); view.set (row, 4, deletedGroup[i.first]);
net -= deletedGroup[i->first]; net -= deletedGroup[i.first];
} }
Color net_color; Color net_color;
@ -219,14 +217,13 @@ int CmdHistoryAnnual::execute (std::string& output)
std::vector <Task> filtered; std::vector <Task> filtered;
filter.subset (filtered); filter.subset (filtered);
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Date entry (task->get_date ("entry")); Date entry (task.get_date ("entry"));
Date end; Date end;
if (task->has ("end")) if (task.has ("end"))
end = Date (task->get_date ("end")); end = Date (task.get_date ("end"));
time_t epoch = entry.startOfYear ().toEpoch (); time_t epoch = entry.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -235,7 +232,7 @@ int CmdHistoryAnnual::execute (std::string& output)
++addedGroup[epoch]; ++addedGroup[epoch];
// All deleted tasks have an end date. // All deleted tasks have an end date.
if (task->getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
epoch = end.startOfYear ().toEpoch (); epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -243,7 +240,7 @@ int CmdHistoryAnnual::execute (std::string& output)
} }
// All completed tasks have an end date. // All completed tasks have an end date.
else if (task->getStatus () == Task::completed) else if (task.getStatus () == Task::completed)
{ {
epoch = end.startOfYear ().toEpoch (); epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -269,16 +266,15 @@ int CmdHistoryAnnual::execute (std::string& output)
int priorYear = 0; int priorYear = 0;
int row = 0; int row = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
row = view.addRow (); row = view.addRow ();
totalAdded += addedGroup [i->first]; totalAdded += addedGroup [i.first];
totalCompleted += completedGroup [i->first]; totalCompleted += completedGroup [i.first];
totalDeleted += deletedGroup [i->first]; totalDeleted += deletedGroup [i.first];
Date dt (i->first); Date dt (i.first);
int m, d, y; int m, d, y;
dt.toMDY (m, d, y); dt.toMDY (m, d, y);
@ -290,22 +286,22 @@ int CmdHistoryAnnual::execute (std::string& output)
int net = 0; int net = 0;
if (addedGroup.find (i->first) != addedGroup.end ()) if (addedGroup.find (i.first) != addedGroup.end ())
{ {
view.set (row, 1, addedGroup[i->first]); view.set (row, 1, addedGroup[i.first]);
net +=addedGroup[i->first]; net +=addedGroup[i.first];
} }
if (completedGroup.find (i->first) != completedGroup.end ()) if (completedGroup.find (i.first) != completedGroup.end ())
{ {
view.set (row, 2, completedGroup[i->first]); view.set (row, 2, completedGroup[i.first]);
net -= completedGroup[i->first]; net -= completedGroup[i.first];
} }
if (deletedGroup.find (i->first) != deletedGroup.end ()) if (deletedGroup.find (i.first) != deletedGroup.end ())
{ {
view.set (row, 3, deletedGroup[i->first]); view.set (row, 3, deletedGroup[i.first]);
net -= deletedGroup[i->first]; net -= deletedGroup[i.first];
} }
Color net_color; Color net_color;
@ -373,14 +369,13 @@ int CmdGHistoryMonthly::execute (std::string& output)
std::vector <Task> filtered; std::vector <Task> filtered;
filter.subset (filtered); filter.subset (filtered);
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Date entry (task->get_date ("entry")); Date entry (task.get_date ("entry"));
Date end; Date end;
if (task->has ("end")) if (task.has ("end"))
end = Date (task->get_date ("end")); end = Date (task.get_date ("end"));
time_t epoch = entry.startOfMonth ().toEpoch (); time_t epoch = entry.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -389,7 +384,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
++addedGroup[epoch]; ++addedGroup[epoch];
// All deleted tasks have an end date. // All deleted tasks have an end date.
if (task->getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
epoch = end.startOfMonth ().toEpoch (); epoch = end.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -397,7 +392,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
} }
// All completed tasks have an end date. // All completed tasks have an end date.
else if (task->getStatus () == Task::completed) else if (task.getStatus () == Task::completed)
{ {
epoch = end.startOfMonth ().toEpoch (); epoch = end.startOfMonth ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -424,14 +419,13 @@ int CmdGHistoryMonthly::execute (std::string& output)
// Determine the longest line, and the longest "added" line. // Determine the longest line, and the longest "added" line.
int maxAddedLine = 0; int maxAddedLine = 0;
int maxRemovedLine = 0; int maxRemovedLine = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine) if (completedGroup[i.first] + deletedGroup[i.first] > maxRemovedLine)
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first]; maxRemovedLine = completedGroup[i.first] + deletedGroup[i.first];
if (addedGroup[i->first] > maxAddedLine) if (addedGroup[i.first] > maxAddedLine)
maxAddedLine = addedGroup[i->first]; maxAddedLine = addedGroup[i.first];
} }
int maxLine = maxAddedLine + maxRemovedLine; int maxLine = maxAddedLine + maxRemovedLine;
@ -445,16 +439,15 @@ int CmdGHistoryMonthly::execute (std::string& output)
int priorYear = 0; int priorYear = 0;
int row = 0; int row = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
row = view.addRow (); row = view.addRow ();
totalAdded += addedGroup[i->first]; totalAdded += addedGroup[i.first];
totalCompleted += completedGroup[i->first]; totalCompleted += completedGroup[i.first];
totalDeleted += deletedGroup[i->first]; totalDeleted += deletedGroup[i.first];
Date dt (i->first); Date dt (i.first);
int m, d, y; int m, d, y;
dt.toMDY (m, d, y); dt.toMDY (m, d, y);
@ -465,33 +458,33 @@ int CmdGHistoryMonthly::execute (std::string& output)
} }
view.set (row, 1, Date::monthName(m)); view.set (row, 1, Date::monthName(m));
unsigned int addedBar = (widthOfBar * addedGroup[i->first]) / maxLine; unsigned int addedBar = (widthOfBar * addedGroup[i.first]) / maxLine;
unsigned int completedBar = (widthOfBar * completedGroup[i->first]) / maxLine; unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
std::string bar = ""; std::string bar = "";
if (context.color ()) if (context.color ())
{ {
std::string aBar = ""; std::string aBar = "";
if (addedGroup[i->first]) if (addedGroup[i.first])
{ {
aBar = format (addedGroup[i->first]); aBar = format (addedGroup[i.first]);
while (aBar.length () < addedBar) while (aBar.length () < addedBar)
aBar = " " + aBar; aBar = " " + aBar;
} }
std::string cBar = ""; std::string cBar = "";
if (completedGroup[i->first]) if (completedGroup[i.first])
{ {
cBar = format (completedGroup[i->first]); cBar = format (completedGroup[i.first]);
while (cBar.length () < completedBar) while (cBar.length () < completedBar)
cBar = " " + cBar; cBar = " " + cBar;
} }
std::string dBar = ""; std::string dBar = "";
if (deletedGroup[i->first]) if (deletedGroup[i.first])
{ {
dBar = format (deletedGroup[i->first]); dBar = format (deletedGroup[i.first]);
while (dBar.length () < deletedBar) while (dBar.length () < deletedBar)
dBar = " " + dBar; dBar = " " + dBar;
} }
@ -569,14 +562,13 @@ int CmdGHistoryAnnual::execute (std::string& output)
std::vector <Task> filtered; std::vector <Task> filtered;
filter.subset (filtered); filter.subset (filtered);
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Date entry (task->get_date ("entry")); Date entry (task.get_date ("entry"));
Date end; Date end;
if (task->has ("end")) if (task.has ("end"))
end = Date (task->get_date ("end")); end = Date (task.get_date ("end"));
time_t epoch = entry.startOfYear ().toEpoch (); time_t epoch = entry.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -585,7 +577,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
++addedGroup[epoch]; ++addedGroup[epoch];
// All deleted tasks have an end date. // All deleted tasks have an end date.
if (task->getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
epoch = end.startOfYear ().toEpoch (); epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -593,7 +585,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
} }
// All completed tasks have an end date. // All completed tasks have an end date.
else if (task->getStatus () == Task::completed) else if (task.getStatus () == Task::completed)
{ {
epoch = end.startOfYear ().toEpoch (); epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0; groups[epoch] = 0;
@ -619,14 +611,13 @@ int CmdGHistoryAnnual::execute (std::string& output)
// Determine the longest line, and the longest "added" line. // Determine the longest line, and the longest "added" line.
int maxAddedLine = 0; int maxAddedLine = 0;
int maxRemovedLine = 0; int maxRemovedLine = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine) if (completedGroup[i.first] + deletedGroup[i.first] > maxRemovedLine)
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first]; maxRemovedLine = completedGroup[i.first] + deletedGroup[i.first];
if (addedGroup[i->first] > maxAddedLine) if (addedGroup[i.first] > maxAddedLine)
maxAddedLine = addedGroup[i->first]; maxAddedLine = addedGroup[i.first];
} }
int maxLine = maxAddedLine + maxRemovedLine; int maxLine = maxAddedLine + maxRemovedLine;
@ -640,16 +631,15 @@ int CmdGHistoryAnnual::execute (std::string& output)
int priorYear = 0; int priorYear = 0;
int row = 0; int row = 0;
std::map <time_t, int>::iterator i; for (auto& i : groups)
for (i = groups.begin (); i != groups.end (); ++i)
{ {
row = view.addRow (); row = view.addRow ();
totalAdded += addedGroup[i->first]; totalAdded += addedGroup[i.first];
totalCompleted += completedGroup[i->first]; totalCompleted += completedGroup[i.first];
totalDeleted += deletedGroup[i->first]; totalDeleted += deletedGroup[i.first];
Date dt (i->first); Date dt (i.first);
int m, d, y; int m, d, y;
dt.toMDY (m, d, y); dt.toMDY (m, d, y);
@ -659,33 +649,33 @@ int CmdGHistoryAnnual::execute (std::string& output)
priorYear = y; priorYear = y;
} }
unsigned int addedBar = (widthOfBar * addedGroup[i->first]) / maxLine; unsigned int addedBar = (widthOfBar * addedGroup[i.first]) / maxLine;
unsigned int completedBar = (widthOfBar * completedGroup[i->first]) / maxLine; unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
std::string bar = ""; std::string bar = "";
if (context.color ()) if (context.color ())
{ {
std::string aBar = ""; std::string aBar = "";
if (addedGroup[i->first]) if (addedGroup[i.first])
{ {
aBar = format (addedGroup[i->first]); aBar = format (addedGroup[i.first]);
while (aBar.length () < addedBar) while (aBar.length () < addedBar)
aBar = " " + aBar; aBar = " " + aBar;
} }
std::string cBar = ""; std::string cBar = "";
if (completedGroup[i->first]) if (completedGroup[i.first])
{ {
cBar = format (completedGroup[i->first]); cBar = format (completedGroup[i.first]);
while (cBar.length () < completedBar) while (cBar.length () < completedBar)
cBar = " " + cBar; cBar = " " + cBar;
} }
std::string dBar = ""; std::string dBar = "";
if (deletedGroup[i->first]) if (deletedGroup[i.first])
{ {
dBar = format (deletedGroup[i->first]); dBar = format (deletedGroup[i.first]);
while (dBar.length () < deletedBar) while (dBar.length () < deletedBar)
dBar = " " + dBar; dBar = " " + dBar;
} }

View file

@ -59,10 +59,9 @@ int CmdIDs::execute (std::string& output)
// Find number of matching tasks. // Find number of matching tasks.
std::vector <int> ids; std::vector <int> ids;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) if (task.id)
if (task->id) ids.push_back (task.id);
ids.push_back (task->id);
std::sort (ids.begin (), ids.end ()); std::sort (ids.begin (), ids.end ());
output = compressIds (ids) + "\n"; output = compressIds (ids) + "\n";
@ -146,11 +145,10 @@ int CmdCompletionIds::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
std::vector <int> ids; std::vector <int> ids;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) if (task.getStatus () != Task::deleted &&
if (task->getStatus () != Task::deleted && task.getStatus () != Task::completed)
task->getStatus () != Task::completed) ids.push_back (task.id);
ids.push_back (task->id);
std::sort (ids.begin (), ids.end ()); std::sort (ids.begin (), ids.end ());
join (output, "\n", ids); join (output, "\n", ids);
@ -180,13 +178,12 @@ int CmdZshCompletionIds::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
std::stringstream out; std::stringstream out;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) if (task.getStatus () != Task::deleted &&
if (task->getStatus () != Task::deleted && task.getStatus () != Task::completed)
task->getStatus () != Task::completed) out << task.id
out << task->id
<< ":" << ":"
<< str_replace(task->get ("description"), ":", zshColonReplacement) << str_replace(task.get ("description"), ":", zshColonReplacement)
<< "\n"; << "\n";
output = out.str (); output = out.str ();
@ -215,9 +212,8 @@ int CmdUUIDs::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
std::vector <std::string> uuids; std::vector <std::string> uuids;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) uuids.push_back (task.get ("uuid"));
uuids.push_back (task->get ("uuid"));
std::sort (uuids.begin (), uuids.end ()); std::sort (uuids.begin (), uuids.end ());
join (output, ",", uuids); join (output, ",", uuids);
@ -247,9 +243,8 @@ int CmdCompletionUuids::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
std::vector <std::string> uuids; std::vector <std::string> uuids;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) uuids.push_back (task.get ("uuid"));
uuids.push_back (task->get ("uuid"));
std::sort (uuids.begin (), uuids.end ()); std::sort (uuids.begin (), uuids.end ());
join (output, "\n", uuids); join (output, "\n", uuids);
@ -279,11 +274,10 @@ int CmdZshCompletionUuids::execute (std::string& output)
filter.subset (filtered); filter.subset (filtered);
std::stringstream out; std::stringstream out;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) out << task.get ("uuid")
out << task->get ("uuid")
<< ":" << ":"
<< str_replace (task->get ("description"), ":", zshColonReplacement) << str_replace (task.get ("description"), ":", zshColonReplacement)
<< "\n"; << "\n";
output = out.str (); output = out.str ();

View file

@ -58,35 +58,34 @@ int CmdImport::execute (std::string& output)
if (! words.size ()) if (! words.size ())
throw std::string (STRING_CMD_IMPORT_NOFILE); throw std::string (STRING_CMD_IMPORT_NOFILE);
std::vector <std::string>::iterator word; for (auto& word : words)
for (word = words.begin (); word != words.end (); ++word)
{ {
File incoming (*word); File incoming (word);
if (! incoming.exists ()) if (! incoming.exists ())
throw format (STRING_CMD_IMPORT_MISSING, *word); throw format (STRING_CMD_IMPORT_MISSING, word);
std::cout << format (STRING_CMD_IMPORT_FILE, *word) << "\n"; std::cout << format (STRING_CMD_IMPORT_FILE, word) << "\n";
// Load the file. // Load the file.
std::vector <std::string> lines; std::vector <std::string> lines;
incoming.read (lines); incoming.read (lines);
std::vector <std::string>::iterator line; for (auto& line : lines)
for (line = lines.begin (); line != lines.end (); ++line)
{ {
std::string object = trimLeft ( std::string object = trimLeft (
trimRight ( trimRight (
trim (*line), trim (line),
"]"), "]"),
"["); "[");
// Skip blanks. May be caused by the trim calls above. // Skip blanks. May be caused by the trim calls above.
if (! object.length ()) if (! object.length ())
continue; continue;
// Parse the whole thing. // Parse the whole thing.
Task task (object); Task task (object);
context.tdb2.add (task); context.tdb2.add (task);
++count; ++count;
std::cout << " " std::cout << " "
<< task.get ("uuid") << task.get ("uuid")

View file

@ -89,8 +89,7 @@ int CmdInfo::execute (std::string& output)
// Render each task. // Render each task.
std::stringstream out; std::stringstream out;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
ViewText view; ViewText view;
view.width (context.getWidth ()); view.width (context.getWidth ());
@ -113,25 +112,24 @@ int CmdInfo::execute (std::string& output)
// id // id
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_ID); view.set (row, 0, STRING_COLUMN_LABEL_ID);
view.set (row, 1, (task->id ? format (task->id) : "-")); view.set (row, 1, (task.id ? format (task.id) : "-"));
std::string status = ucFirst (Task::statusToText (task->getStatus ())); // L10N safe ucFirst. std::string status = ucFirst (Task::statusToText (task.getStatus ())); // L10N safe ucFirst.
// description // description
Color c; Color c;
autoColorize (*task, c); autoColorize (task, c);
std::string description = task->get ("description"); std::string description = task.get ("description");
int indent = context.config.getInteger ("indent.annotation"); int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task->getAnnotations (annotations); task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator ann; for (auto& anno : annotations)
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
description += "\n" description += "\n"
+ std::string (indent, ' ') + std::string (indent, ' ')
+ Date (ann->first.substr (11)).toString (dateformatanno) + Date (anno.first.substr (11)).toString (dateformatanno)
+ " " + " "
+ ann->second; + anno.second;
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_DESC); view.set (row, 0, STRING_COLUMN_LABEL_DESC);
@ -143,23 +141,22 @@ int CmdInfo::execute (std::string& output)
view.set (row, 1, status); view.set (row, 1, status);
// project // project
if (task->has ("project")) if (task.has ("project"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_PROJECT); view.set (row, 0, STRING_COLUMN_LABEL_PROJECT);
view.set (row, 1, task->get ("project")); view.set (row, 1, task.get ("project"));
} }
// dependencies: blocked // dependencies: blocked
{ {
std::vector <Task> blocked; std::vector <Task> blocked;
dependencyGetBlocking (*task, blocked); dependencyGetBlocking (task, blocked);
if (blocked.size ()) if (blocked.size ())
{ {
std::stringstream message; std::stringstream message;
std::vector <Task>::const_iterator it; for (auto& block : blocked)
for (it = blocked.begin (); it != blocked.end (); ++it) message << block.id << " " << block.get ("description") << "\n";
message << it->id << " " << it->get ("description") << "\n";
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_BLOCKED); view.set (row, 0, STRING_CMD_INFO_BLOCKED);
@ -170,13 +167,12 @@ int CmdInfo::execute (std::string& output)
// dependencies: blocking // dependencies: blocking
{ {
std::vector <Task> blocking; std::vector <Task> blocking;
dependencyGetBlocked (*task, blocking); dependencyGetBlocked (task, blocking);
if (blocking.size ()) if (blocking.size ())
{ {
std::stringstream message; std::stringstream message;
std::vector <Task>::const_iterator it; for (auto& block : blocking)
for (it = blocking.begin (); it != blocking.end (); ++it) message << block.id << " " << block.get ("description") << "\n";
message << it->id << " " << it->get ("description") << "\n";
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_BLOCKING); view.set (row, 0, STRING_CMD_INFO_BLOCKING);
@ -185,45 +181,45 @@ int CmdInfo::execute (std::string& output)
} }
// recur // recur
if (task->has ("recur")) if (task.has ("recur"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_RECUR_L); view.set (row, 0, STRING_COLUMN_LABEL_RECUR_L);
view.set (row, 1, task->get ("recur")); view.set (row, 1, task.get ("recur"));
} }
// parent // parent
if (task->has ("parent")) if (task.has ("parent"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_PARENT); view.set (row, 0, STRING_COLUMN_LABEL_PARENT);
view.set (row, 1, task->get ("parent")); view.set (row, 1, task.get ("parent"));
} }
// mask // mask
if (task->has ("mask")) if (task.has ("mask"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_MASK); view.set (row, 0, STRING_COLUMN_LABEL_MASK);
view.set (row, 1, task->get ("mask")); view.set (row, 1, task.get ("mask"));
} }
// imask // imask
if (task->has ("imask")) if (task.has ("imask"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_MASK_IDX); view.set (row, 0, STRING_COLUMN_LABEL_MASK_IDX);
view.set (row, 1, task->get ("imask")); view.set (row, 1, task.get ("imask"));
} }
// entry // entry
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_ENTERED); view.set (row, 0, STRING_COLUMN_LABEL_ENTERED);
Date dt (task->get_date ("entry")); Date dt (task.get_date ("entry"));
std::string entry = dt.toString (dateformat); std::string entry = dt.toString (dateformat);
std::string age; std::string age;
std::string created = task->get ("entry"); std::string created = task.get ("entry");
if (created.length ()) if (created.length ())
{ {
Date dt (strtol (created.c_str (), NULL, 10)); Date dt (strtol (created.c_str (), NULL, 10));
@ -233,67 +229,67 @@ int CmdInfo::execute (std::string& output)
view.set (row, 1, entry + " (" + age + ")"); view.set (row, 1, entry + " (" + age + ")");
// wait // wait
if (task->has ("wait")) if (task.has ("wait"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_WAITING); view.set (row, 0, STRING_COLUMN_LABEL_WAITING);
view.set (row, 1, Date (task->get_date ("wait")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("wait")).toString (dateformat));
} }
// scheduled // scheduled
if (task->has ("scheduled")) if (task.has ("scheduled"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_SCHED); view.set (row, 0, STRING_COLUMN_LABEL_SCHED);
view.set (row, 1, Date (task->get_date ("scheduled")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("scheduled")).toString (dateformat));
} }
// start // start
if (task->has ("start")) if (task.has ("start"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_START); view.set (row, 0, STRING_COLUMN_LABEL_START);
view.set (row, 1, Date (task->get_date ("start")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("start")).toString (dateformat));
} }
// due (colored) // due (colored)
if (task->has ("due")) if (task.has ("due"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_DUE); view.set (row, 0, STRING_COLUMN_LABEL_DUE);
view.set (row, 1, Date (task->get_date ("due")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("due")).toString (dateformat));
} }
// end // end
if (task->has ("end")) if (task.has ("end"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_END); view.set (row, 0, STRING_COLUMN_LABEL_END);
view.set (row, 1, Date (task->get_date ("end")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("end")).toString (dateformat));
} }
// until // until
if (task->has ("until")) if (task.has ("until"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_UNTIL); view.set (row, 0, STRING_CMD_INFO_UNTIL);
view.set (row, 1, Date (task->get_date ("until")).toString (dateformat)); view.set (row, 1, Date (task.get_date ("until")).toString (dateformat));
} }
// modified // modified
if (task->has ("modified")) if (task.has ("modified"))
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_MODIFIED); view.set (row, 0, STRING_CMD_INFO_MODIFIED);
Date mod (task->get_date ("modified")); Date mod (task.get_date ("modified"));
std::string age = Duration (now - mod).format (); std::string age = Duration (now - mod).format ();
view.set (row, 1, mod.toString (dateformat) + " (" + age + ")"); view.set (row, 1, mod.toString (dateformat) + " (" + age + ")");
} }
// tags ... // tags ...
std::vector <std::string> tags; std::vector <std::string> tags;
task->getTags (tags); task.getTags (tags);
if (tags.size ()) if (tags.size ())
{ {
std::string allTags; std::string allTags;
@ -308,30 +304,30 @@ int CmdInfo::execute (std::string& output)
{ {
// Note: This list must match that in Task::hasTag. // Note: This list must match that in Task::hasTag.
std::string virtualTags = ""; std::string virtualTags = "";
if (task->hasTag ("ACTIVE")) virtualTags += "ACTIVE "; if (task.hasTag ("ACTIVE")) virtualTags += "ACTIVE ";
if (task->hasTag ("ANNOTATED")) virtualTags += "ANNOTATED "; if (task.hasTag ("ANNOTATED")) virtualTags += "ANNOTATED ";
if (task->hasTag ("BLOCKED")) virtualTags += "BLOCKED "; if (task.hasTag ("BLOCKED")) virtualTags += "BLOCKED ";
if (task->hasTag ("BLOCKING")) virtualTags += "BLOCKING "; if (task.hasTag ("BLOCKING")) virtualTags += "BLOCKING ";
if (task->hasTag ("CHILD")) virtualTags += "CHILD "; if (task.hasTag ("CHILD")) virtualTags += "CHILD ";
if (task->hasTag ("COMPLETED")) virtualTags += "COMPLETED "; if (task.hasTag ("COMPLETED")) virtualTags += "COMPLETED ";
if (task->hasTag ("DELETED")) virtualTags += "DELETED "; if (task.hasTag ("DELETED")) virtualTags += "DELETED ";
if (task->hasTag ("DUE")) virtualTags += "DUE "; if (task.hasTag ("DUE")) virtualTags += "DUE ";
if (task->hasTag ("DUETODAY")) virtualTags += "DUETODAY "; if (task.hasTag ("DUETODAY")) virtualTags += "DUETODAY ";
if (task->hasTag ("MONTH")) virtualTags += "MONTH "; if (task.hasTag ("MONTH")) virtualTags += "MONTH ";
if (task->hasTag ("OVERDUE")) virtualTags += "OVERDUE "; if (task.hasTag ("OVERDUE")) virtualTags += "OVERDUE ";
if (task->hasTag ("PARENT")) virtualTags += "PARENT "; if (task.hasTag ("PARENT")) virtualTags += "PARENT ";
if (task->hasTag ("PENDING")) virtualTags += "PENDING "; if (task.hasTag ("PENDING")) virtualTags += "PENDING ";
if (task->hasTag ("READY")) virtualTags += "READY "; if (task.hasTag ("READY")) virtualTags += "READY ";
if (task->hasTag ("SCHEDULED")) virtualTags += "SCHEDULED "; if (task.hasTag ("SCHEDULED")) virtualTags += "SCHEDULED ";
if (task->hasTag ("TAGGED")) virtualTags += "TAGGED "; if (task.hasTag ("TAGGED")) virtualTags += "TAGGED ";
if (task->hasTag ("TODAY")) virtualTags += "TODAY "; if (task.hasTag ("TODAY")) virtualTags += "TODAY ";
if (task->hasTag ("TOMORROW")) virtualTags += "TOMORROW "; if (task.hasTag ("TOMORROW")) virtualTags += "TOMORROW ";
if (task->hasTag ("UNBLOCKED")) virtualTags += "UNBLOCKED "; if (task.hasTag ("UNBLOCKED")) virtualTags += "UNBLOCKED ";
if (task->hasTag ("UNTIL")) virtualTags += "UNTIL "; if (task.hasTag ("UNTIL")) virtualTags += "UNTIL ";
if (task->hasTag ("WAITING")) virtualTags += "WAITING "; if (task.hasTag ("WAITING")) virtualTags += "WAITING ";
if (task->hasTag ("WEEK")) virtualTags += "WEEK "; if (task.hasTag ("WEEK")) virtualTags += "WEEK ";
if (task->hasTag ("YEAR")) virtualTags += "YEAR "; if (task.hasTag ("YEAR")) virtualTags += "YEAR ";
if (task->hasTag ("YESTERDAY")) virtualTags += "YESTERDAY "; if (task.hasTag ("YESTERDAY")) virtualTags += "YESTERDAY ";
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_VIRTUAL_TAGS); view.set (row, 0, STRING_CMD_INFO_VIRTUAL_TAGS);
@ -341,27 +337,26 @@ int CmdInfo::execute (std::string& output)
// uuid // uuid
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_UUID); view.set (row, 0, STRING_COLUMN_LABEL_UUID);
std::string uuid = task->get ("uuid"); std::string uuid = task.get ("uuid");
view.set (row, 1, uuid); view.set (row, 1, uuid);
// Task::urgency // Task::urgency
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_URGENCY); view.set (row, 0, STRING_COLUMN_LABEL_URGENCY);
view.set (row, 1, format (task->urgency (), 4, 4)); view.set (row, 1, format (task.urgency (), 4, 4));
// Show any UDAs // Show any UDAs
std::vector <std::string> all = task->all (); std::vector <std::string> all = task.all ();
std::vector <std::string>::iterator att;
std::string type; std::string type;
for (att = all.begin (); att != all.end (); ++att) for (auto& att: all)
{ {
type = context.config.get ("uda." + *att + ".type"); type = context.config.get ("uda." + att + ".type");
if (type != "") if (type != "")
{ {
Column* col = context.columns[*att]; Column* col = context.columns[att];
if (col) if (col)
{ {
std::string value = task->get (*att); std::string value = task.get (att);
if (value != "") if (value != "")
{ {
row = view.addRow (); row = view.addRow ();
@ -380,20 +375,20 @@ int CmdInfo::execute (std::string& output)
// Show any orphaned UDAs, which are identified by not being represented in // Show any orphaned UDAs, which are identified by not being represented in
// the context.columns map. // the context.columns map.
for (att = all.begin (); att != all.end (); ++att) for (auto& att : all)
{ {
if (att->substr (0, 11) != "annotation_" && if (att.substr (0, 11) != "annotation_" &&
context.columns.find (*att) == context.columns.end ()) context.columns.find (att) == context.columns.end ())
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, "[" + *att); view.set (row, 0, "[" + att);
view.set (row, 1, task->get (*att) + "]"); view.set (row, 1, task.get (att) + "]");
} }
} }
// Create a second table, containing urgency details, if necessary. // Create a second table, containing urgency details, if necessary.
ViewText urgencyDetails; ViewText urgencyDetails;
if (task->urgency () != 0.0) if (task.urgency () != 0.0)
{ {
if (context.color ()) if (context.color ())
{ {
@ -413,74 +408,73 @@ int CmdInfo::execute (std::string& output)
urgencyDetails.add (Column::factory ("string", "")); // = urgencyDetails.add (Column::factory ("string", "")); // =
urgencyDetails.add (Column::factory ("string", "")); // Result urgencyDetails.add (Column::factory ("string", "")); // Result
urgencyTerm (urgencyDetails, "project", task->urgency_project (), Task::urgencyProjectCoefficient); urgencyTerm (urgencyDetails, "project", task.urgency_project (), Task::urgencyProjectCoefficient);
urgencyTerm (urgencyDetails, "active", task->urgency_active (), Task::urgencyActiveCoefficient); urgencyTerm (urgencyDetails, "active", task.urgency_active (), Task::urgencyActiveCoefficient);
urgencyTerm (urgencyDetails, "scheduled", task->urgency_scheduled (), Task::urgencyScheduledCoefficient); urgencyTerm (urgencyDetails, "scheduled", task.urgency_scheduled (), Task::urgencyScheduledCoefficient);
urgencyTerm (urgencyDetails, "waiting", task->urgency_waiting (), Task::urgencyWaitingCoefficient); urgencyTerm (urgencyDetails, "waiting", task.urgency_waiting (), Task::urgencyWaitingCoefficient);
urgencyTerm (urgencyDetails, "blocked", task->urgency_blocked (), Task::urgencyBlockedCoefficient); urgencyTerm (urgencyDetails, "blocked", task.urgency_blocked (), Task::urgencyBlockedCoefficient);
urgencyTerm (urgencyDetails, "blocking", task->urgency_blocking (), Task::urgencyBlockingCoefficient); urgencyTerm (urgencyDetails, "blocking", task.urgency_blocking (), Task::urgencyBlockingCoefficient);
urgencyTerm (urgencyDetails, "annotations", task->urgency_annotations (), Task::urgencyAnnotationsCoefficient); urgencyTerm (urgencyDetails, "annotations", task.urgency_annotations (), Task::urgencyAnnotationsCoefficient);
urgencyTerm (urgencyDetails, "tags", task->urgency_tags (), Task::urgencyTagsCoefficient); urgencyTerm (urgencyDetails, "tags", task.urgency_tags (), Task::urgencyTagsCoefficient);
urgencyTerm (urgencyDetails, "next", task->urgency_next (), Task::urgencyNextCoefficient); urgencyTerm (urgencyDetails, "next", task.urgency_next (), Task::urgencyNextCoefficient);
urgencyTerm (urgencyDetails, "due", task->urgency_due (), Task::urgencyDueCoefficient); urgencyTerm (urgencyDetails, "due", task.urgency_due (), Task::urgencyDueCoefficient);
urgencyTerm (urgencyDetails, "age", task->urgency_age (), Task::urgencyAgeCoefficient); urgencyTerm (urgencyDetails, "age", task.urgency_age (), Task::urgencyAgeCoefficient);
// Tag, Project- and UDA-specific coefficients. // Tag, Project- and UDA-specific coefficients.
std::map <std::string, float>::iterator var; for (auto& var : Task::coefficients)
for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var)
{ {
if (var->first.substr (0, 13) == "urgency.user.") if (var.first.substr (0, 13) == "urgency.user.")
{ {
// urgency.user.project.<project>.coefficient // urgency.user.project.<project>.coefficient
std::string::size_type end = std::string::npos; std::string::size_type end = std::string::npos;
if (var->first.substr (13, 8) == "project." && if (var.first.substr (13, 8) == "project." &&
(end = var->first.find (".coefficient")) != std::string::npos) (end = var.first.find (".coefficient")) != std::string::npos)
{ {
std::string project = var->first.substr (21, end - 21); std::string project = var.first.substr (21, end - 21);
if (task->get ("project").find (project) == 0) if (task.get ("project").find (project) == 0)
urgencyTerm (urgencyDetails, "PROJECT " + project, 1.0, var->second); urgencyTerm (urgencyDetails, "PROJECT " + project, 1.0, var.second);
} }
// urgency.user.tag.<tag>.coefficient // urgency.user.tag.<tag>.coefficient
if (var->first.substr (13, 4) == "tag." && if (var.first.substr (13, 4) == "tag." &&
(end = var->first.find (".coefficient")) != std::string::npos) (end = var.first.find (".coefficient")) != std::string::npos)
{ {
std::string name = var->first.substr (17, end - 17); std::string name = var.first.substr (17, end - 17);
if (task->hasTag (name)) if (task.hasTag (name))
urgencyTerm (urgencyDetails, "TAG " + name, 1.0, var->second); urgencyTerm (urgencyDetails, "TAG " + name, 1.0, var.second);
} }
// urgency.user.keyword.<keyword>.coefficient // urgency.user.keyword.<keyword>.coefficient
if (var->first.substr (13, 8) == "keyword." && if (var.first.substr (13, 8) == "keyword." &&
(end = var->first.find (".coefficient")) != std::string::npos) (end = var.first.find (".coefficient")) != std::string::npos)
{ {
std::string keyword = var->first.substr (21, end - 21); std::string keyword = var.first.substr (21, end - 21);
if (task->get ("description").find (keyword) != std::string::npos) if (task.get ("description").find (keyword) != std::string::npos)
urgencyTerm (urgencyDetails, "KEYWORD " + keyword, 1.0, var->second); urgencyTerm (urgencyDetails, "KEYWORD " + keyword, 1.0, var.second);
} }
} }
// urgency.uda.<name>.coefficient // urgency.uda.<name>.coefficient
else if (var->first.substr (0, 12) == "urgency.uda.") else if (var.first.substr (0, 12) == "urgency.uda.")
{ {
// urgency.uda.<name>.coefficient // urgency.uda.<name>.coefficient
// urgency.uda.<name>.<value>.coefficient // urgency.uda.<name>.<value>.coefficient
std::string::size_type end = var->first.find (".coefficient"); std::string::size_type end = var.first.find (".coefficient");
if (end != std::string::npos) if (end != std::string::npos)
{ {
const std::string uda = var->first.substr (12, end - 12); const std::string uda = var.first.substr (12, end - 12);
std::string::size_type dot = uda.find ("."); std::string::size_type dot = uda.find (".");
if (dot == std::string::npos) if (dot == std::string::npos)
{ {
// urgency.uda.<name>.coefficient // urgency.uda.<name>.coefficient
if (task->has (uda)) if (task.has (uda))
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var->second); urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var.second);
} }
else else
{ {
// urgency.uda.<name>.<value>.coefficient // urgency.uda.<name>.<value>.coefficient
if (task->get (uda.substr(0, dot)) == uda.substr(dot+1)) if (task.get (uda.substr(0, dot)) == uda.substr(dot+1))
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var->second); urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var.second);
} }
} }
} }
@ -489,7 +483,7 @@ int CmdInfo::execute (std::string& output)
row = urgencyDetails.addRow (); row = urgencyDetails.addRow ();
urgencyDetails.set (row, 5, rightJustify ("------", 6)); urgencyDetails.set (row, 5, rightJustify ("------", 6));
row = urgencyDetails.addRow (); row = urgencyDetails.addRow ();
urgencyDetails.set (row, 5, rightJustify (format (task->urgency (), 4, 4), 6)); urgencyDetails.set (row, 5, rightJustify (format (task.urgency (), 4, 4), 6));
} }
// Create a third table, containing undo log change details. // Create a third table, containing undo log change details.

View file

@ -67,104 +67,101 @@ int CmdModify::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
task->modify (Task::modReplace); task.modify (Task::modReplace);
if (taskDiff (before, *task)) if (taskDiff (before, task))
{ {
// Perform some logical consistency checks. // Perform some logical consistency checks.
if (task->has ("recur") && if (task.has ("recur") &&
!task->has ("due") && !task.has ("due") &&
!before.has ("due")) !before.has ("due"))
throw std::string (STRING_CMD_MODIFY_NO_DUE); throw std::string (STRING_CMD_MODIFY_NO_DUE);
if (before.has ("recur") && if (before.has ("recur") &&
before.has ("due") && before.has ("due") &&
(!task->has ("due") || (!task.has ("due") ||
task->get ("due") == "")) task.get ("due") == ""))
throw std::string (STRING_CMD_MODIFY_REM_DUE); throw std::string (STRING_CMD_MODIFY_REM_DUE);
if (before.has ("recur") && if (before.has ("recur") &&
(!task->has ("recur") || (!task.has ("recur") ||
task->get ("recur") == "")) task.get ("recur") == ""))
throw std::string (STRING_CMD_MODIFY_REC_ALWAYS); throw std::string (STRING_CMD_MODIFY_REC_ALWAYS);
// Delete the specified task. // Delete the specified task.
std::string question; std::string question;
if (task->id != 0) if (task.id != 0)
question = format (STRING_CMD_MODIFY_CONFIRM, question = format (STRING_CMD_MODIFY_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
else else
question = format (STRING_CMD_MODIFY_CONFIRM, question = format (STRING_CMD_MODIFY_CONFIRM,
task->get ("uuid"), task.get ("uuid"),
task->get ("description")); task.get ("description"));
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (task);
dependencyChainOnModify (before, *task); dependencyChainOnModify (before, task);
++count; ++count;
feedback_affected (STRING_CMD_MODIFY_TASK, *task); feedback_affected (STRING_CMD_MODIFY_TASK, task);
feedback_unblocked (*task); feedback_unblocked (task);
context.tdb2.modify (*task); context.tdb2.modify (task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (before, *task); projectChanges[task.get ("project")] = onProjectChange (before, task);
// Task potentially has siblings - modify them. // Task potentially has siblings - modify them.
if (task->has ("parent")) if (task.has ("parent"))
{ {
if ((context.config.get ("recurrence.confirmation") == "prompt" if ((context.config.get ("recurrence.confirmation") == "prompt"
&& confirm (STRING_CMD_MODIFY_RECUR)) || && confirm (STRING_CMD_MODIFY_RECUR)) ||
context.config.getBoolean ("recurrence.confirmation")) context.config.getBoolean ("recurrence.confirmation"))
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (task);
std::vector <Task>::iterator sibling; for (auto& sibling : siblings)
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
Task alternate (*sibling); Task alternate (sibling);
sibling->modify (Task::modReplace); sibling.modify (Task::modReplace);
updateRecurrenceMask (*sibling); updateRecurrenceMask (sibling);
dependencyChainOnModify (alternate, *sibling); dependencyChainOnModify (alternate, sibling);
++count; ++count;
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling); feedback_affected (STRING_CMD_MODIFY_TASK_R, sibling);
feedback_unblocked (*sibling); feedback_unblocked (sibling);
context.tdb2.modify (*sibling); context.tdb2.modify (sibling);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[sibling->get ("project")] = onProjectChange (alternate, *sibling); projectChanges[sibling.get ("project")] = onProjectChange (alternate, sibling);
} }
// Modify the parent // Modify the parent
Task parent; Task parent;
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task.get ("parent"), parent);
parent.modify (Task::modReplace); parent.modify (Task::modReplace);
context.tdb2.modify (parent); context.tdb2.modify (parent);
} }
} }
// Task potentially has child tasks - modify them. // Task potentially has child tasks - modify them.
else if (task->get ("status") == "recurring") else if (task.get ("status") == "recurring")
{ {
std::vector <Task> children = context.tdb2.children (*task); std::vector <Task> children = context.tdb2.children (task);
if (children.size () && if (children.size () &&
(! context.config.getBoolean ("recurrence.confirmation") || (! context.config.getBoolean ("recurrence.confirmation") ||
confirm (STRING_CMD_MODIFY_RECUR))) confirm (STRING_CMD_MODIFY_RECUR)))
{ {
std::vector <Task>::iterator child; for (auto& child : children)
for (child = children.begin (); child != children.end (); ++child)
{ {
Task alternate (*child); Task alternate (child);
child->modify (Task::modReplace); child.modify (Task::modReplace);
updateRecurrenceMask (*child); updateRecurrenceMask (child);
context.tdb2.modify (*child); context.tdb2.modify (child);
dependencyChainOnModify (alternate, *child); dependencyChainOnModify (alternate, child);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[child->get ("project")] = onProjectChange (alternate, *child); projectChanges[child.get ("project")] = onProjectChange (alternate, child);
++count; ++count;
feedback_affected (STRING_CMD_MODIFY_TASK_R, *child); feedback_affected (STRING_CMD_MODIFY_TASK_R, child);
} }
} }
} }
@ -180,10 +177,9 @@ int CmdModify::execute (std::string& output)
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_MODIFY_1 : STRING_CMD_MODIFY_N, count); feedback_affected (count == 1 ? STRING_CMD_MODIFY_1 : STRING_CMD_MODIFY_N, count);
return rc; return rc;

View file

@ -67,46 +67,44 @@ int CmdPrepend::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
Task before (*task); Task before (task);
// Prepend to the specified task. // Prepend to the specified task.
std::string question = format (STRING_CMD_PREPEND_CONFIRM, std::string question = format (STRING_CMD_PREPEND_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modPrepend, true); task.modify (Task::modPrepend, true);
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_PREPEND_TASK, *task); feedback_affected (STRING_CMD_PREPEND_TASK, task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false); projectChanges[task.get ("project")] = onProjectChange (task, false);
// Prepend to siblings. // Prepend to siblings.
if (task->has ("parent")) if (task.has ("parent"))
{ {
if ((context.config.get ("recurrence.confirmation") == "prompt" if ((context.config.get ("recurrence.confirmation") == "prompt"
&& confirm (STRING_CMD_PREPEND_CONFIRM_R)) || && confirm (STRING_CMD_PREPEND_CONFIRM_R)) ||
context.config.getBoolean ("recurrence.confirmation")) context.config.getBoolean ("recurrence.confirmation"))
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (task);
std::vector <Task>::iterator sibling; for (auto& sibling : siblings)
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
sibling->modify (Task::modPrepend, true); sibling.modify (Task::modPrepend, true);
context.tdb2.modify (*sibling); context.tdb2.modify (sibling);
++count; ++count;
feedback_affected (STRING_CMD_PREPEND_TASK_R, *sibling); feedback_affected (STRING_CMD_PREPEND_TASK_R, sibling);
} }
// Prepend to the parent // Prepend to the parent
Task parent; Task parent;
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task.get ("parent"), parent);
parent.modify (Task::modPrepend, true); parent.modify (Task::modPrepend, true);
context.tdb2.modify (parent); context.tdb2.modify (parent);
} }
@ -122,10 +120,9 @@ int CmdPrepend::execute (std::string& output)
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_PREPEND_1 : STRING_CMD_PREPEND_N, count); feedback_affected (count == 1 ? STRING_CMD_PREPEND_1 : STRING_CMD_PREPEND_N, count);
return rc; return rc;

View file

@ -58,15 +58,11 @@ int CmdProjects::execute (std::string& output)
// Get all the tasks. // Get all the tasks.
handleRecurrence (); handleRecurrence ();
std::vector <Task> tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
if (context.config.getBoolean ("list.all.projects")) if (context.config.getBoolean ("list.all.projects"))
{ for (auto& task : context.tdb2.completed.get_tasks ())
std::vector <Task> extra = context.tdb2.completed.get_tasks (); tasks.push_back (task);
std::vector <Task>::iterator task;
for (task = extra.begin (); task != extra.end (); ++task)
tasks.push_back (*task);
}
// Apply the filter. // Apply the filter.
Filter filter; Filter filter;
@ -82,10 +78,9 @@ int CmdProjects::execute (std::string& output)
std::map <std::string, int> unique; std::map <std::string, int> unique;
bool no_project = false; bool no_project = false;
std::string project; std::string project;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
if (task->getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
--quantity; --quantity;
continue; continue;
@ -93,14 +88,13 @@ int CmdProjects::execute (std::string& output)
// Increase the count for the project the task belongs to and all // Increase the count for the project the task belongs to and all
// its super-projects // its super-projects
project = task->get ("project"); project = task.get ("project");
std::vector <std::string> projects = extractParents (project); std::vector <std::string> projects = extractParents (project);
projects.push_back (project); projects.push_back (project);
std::vector <std::string>::const_iterator parent; for (auto& parent : projects)
for (parent = projects.begin (); parent != projects.end (); ++parent) unique[parent] += 1;
unique[*parent] += 1;
if (project == "") if (project == "")
no_project = true; no_project = true;
@ -118,27 +112,24 @@ int CmdProjects::execute (std::string& output)
view.colorHeader (label); view.colorHeader (label);
std::vector <std::string> processed; std::vector <std::string> processed;
std::map <std::string, int>::iterator project; for (auto& project : unique)
for (project = unique.begin (); project != unique.end (); ++project)
{ {
const std::vector <std::string> parents = extractParents (project->first); const std::vector <std::string> parents = extractParents (project.first);
std::vector <std::string>::const_iterator parent; for (auto& parent : parents)
for (parent = parents.begin (); parent != parents.end (); parent++)
{ {
if (std::find (processed.begin (), processed.end (), *parent) if (std::find (processed.begin (), processed.end (), parent) == processed.end ())
== processed.end ())
{ {
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, indentProject (*parent)); view.set (row, 0, indentProject (parent));
processed.push_back (*parent); processed.push_back (parent);
} }
} }
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, (project->first == "" view.set (row, 0, (project.first == ""
? STRING_CMD_PROJECTS_NONE ? STRING_CMD_PROJECTS_NONE
: indentProject (project->first, " ", '.'))); : indentProject (project.first, " ", '.')));
view.set (row, 1, project->second); view.set (row, 1, project.second);
processed.push_back (project->first); processed.push_back (project.first);
} }
int number_projects = unique.size (); int number_projects = unique.size ();
@ -182,15 +173,11 @@ int CmdCompletionProjects::execute (std::string& output)
{ {
// Get all the tasks. // Get all the tasks.
handleRecurrence (); handleRecurrence ();
std::vector <Task> tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
if (context.config.getBoolean ("list.all.projects")) if (context.config.getBoolean ("list.all.projects"))
{ for (auto& task : context.tdb2.completed.get_tasks ())
std::vector <Task> extra = context.tdb2.completed.get_tasks (); tasks.push_back (task);
std::vector <Task>::iterator task;
for (task = extra.begin (); task != extra.end (); ++task)
tasks.push_back (*task);
}
// Apply the filter. // Apply the filter.
Filter filter; Filter filter;
@ -200,14 +187,12 @@ int CmdCompletionProjects::execute (std::string& output)
// Scan all the tasks for their project name, building a map using project // Scan all the tasks for their project name, building a map using project
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) unique[task.get ("project")] = 0;
unique[task->get ("project")] = 0;
std::map <std::string, int>::iterator project; for (auto& project : unique)
for (project = unique.begin (); project != unique.end (); ++project) if (project.first.length ())
if (project->first.length ()) output += project.first + "\n";
output += project->first + "\n";
return 0; return 0;
} }

View file

@ -51,12 +51,11 @@ int CmdReports::execute (std::string& output)
std::vector <std::string> reports; std::vector <std::string> reports;
// Add custom reports. // Add custom reports.
Config::const_iterator i; for (auto& i : context.config)
for (i = context.config.begin (); i != context.config.end (); ++i)
{ {
if (i->first.substr (0, 7) == "report.") if (i.first.substr (0, 7) == "report.")
{ {
std::string report = i->first.substr (7); std::string report = i.first.substr (7);
std::string::size_type columns = report.find (".columns"); std::string::size_type columns = report.find (".columns");
if (columns != std::string::npos) if (columns != std::string::npos)
reports.push_back (report.substr (0, columns)); reports.push_back (report.substr (0, columns));
@ -96,12 +95,11 @@ int CmdReports::execute (std::string& output)
view.intraColorOdd (alternate); view.intraColorOdd (alternate);
} }
std::vector <std::string>::iterator report; for (auto& report : reports)
for (report = reports.begin (); report != reports.end (); ++report)
{ {
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, *report); view.set (row, 0, report);
view.set (row, 1, context.commands[*report]->description ()); view.set (row, 1, context.commands[report]->description ());
} }
out << optionalBlankLine () out << optionalBlankLine ()

View file

@ -213,33 +213,32 @@ int CmdShow::execute (std::string& output)
recognized += "_forcecolor "; recognized += "_forcecolor ";
std::vector <std::string> unrecognized; std::vector <std::string> unrecognized;
Config::const_iterator i; for (auto& i : context.config)
for (i = context.config.begin (); i != context.config.end (); ++i)
{ {
// Disallow partial matches by tacking a leading and trailing space on each // Disallow partial matches by tacking a leading and trailing space on each
// variable name. // variable name.
std::string pattern = " " + i->first + " "; std::string pattern = " " + i.first + " ";
if (recognized.find (pattern) == std::string::npos) if (recognized.find (pattern) == std::string::npos)
{ {
// These are special configuration variables, because their name is // These are special configuration variables, because their name is
// dynamic. // dynamic.
if (i->first.substr (0, 14) != "color.keyword." && if (i.first.substr (0, 14) != "color.keyword." &&
i->first.substr (0, 14) != "color.project." && i.first.substr (0, 14) != "color.project." &&
i->first.substr (0, 10) != "color.tag." && i.first.substr (0, 10) != "color.tag." &&
i->first.substr (0, 10) != "color.uda." && i.first.substr (0, 10) != "color.uda." &&
i->first.substr (0, 8) != "context." && i.first.substr (0, 8) != "context." &&
i->first.substr (0, 8) != "holiday." && i.first.substr (0, 8) != "holiday." &&
i->first.substr (0, 7) != "report." && i.first.substr (0, 7) != "report." &&
i->first.substr (0, 6) != "alias." && i.first.substr (0, 6) != "alias." &&
i->first.substr (0, 5) != "hook." && i.first.substr (0, 5) != "hook." &&
i->first.substr (0, 4) != "uda." && i.first.substr (0, 4) != "uda." &&
i->first.substr (0, 8) != "default." && i.first.substr (0, 8) != "default." &&
i->first.substr (0, 21) != "urgency.user.project." && i.first.substr (0, 21) != "urgency.user.project." &&
i->first.substr (0, 17) != "urgency.user.tag." && i.first.substr (0, 17) != "urgency.user.tag." &&
i->first.substr (0, 21) != "urgency.user.keyword." && i.first.substr (0, 21) != "urgency.user.keyword." &&
i->first.substr (0, 12) != "urgency.uda.") i.first.substr (0, 12) != "urgency.uda.")
{ {
unrecognized.push_back (i->first); unrecognized.push_back (i.first);
} }
} }
} }
@ -249,9 +248,9 @@ int CmdShow::execute (std::string& output)
Config default_config; Config default_config;
default_config.setDefaults (); default_config.setDefaults ();
for (i = context.config.begin (); i != context.config.end (); ++i) for (auto& i : context.config)
if (i->second != default_config.get (i->first)) if (i.second != default_config.get (i.first))
default_values.push_back (i->first); default_values.push_back (i.first);
// Create output view. // Create output view.
ViewText view; ViewText view;
@ -278,35 +277,35 @@ int CmdShow::execute (std::string& output)
section = ""; section = "";
std::string::size_type loc; std::string::size_type loc;
for (i = context.config.begin (); i != context.config.end (); ++i) for (auto& i : context.config)
{ {
loc = i->first.find (section, 0); loc = i.first.find (section, 0);
if (loc != std::string::npos) if (loc != std::string::npos)
{ {
// Look for unrecognized. // Look for unrecognized.
Color color; Color color;
if (std::find (unrecognized.begin (), unrecognized.end (), i->first) != unrecognized.end ()) if (std::find (unrecognized.begin (), unrecognized.end (), i.first) != unrecognized.end ())
{ {
issue_error = true; issue_error = true;
color = error; color = error;
} }
else if (std::find (default_values.begin (), default_values.end (), i->first) != default_values.end ()) else if (std::find (default_values.begin (), default_values.end (), i.first) != default_values.end ())
{ {
issue_warning = true; issue_warning = true;
color = warning; color = warning;
} }
std::string value = i->second; std::string value = i.second;
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, i->first, color); view.set (row, 0, i.first, color);
view.set (row, 1, value, color); view.set (row, 1, value, color);
if (default_config[i->first] != value && if (default_config[i.first] != value &&
default_config[i->first] != "") default_config[i.first] != "")
{ {
row = view.addRow (); row = view.addRow ();
view.set (row, 0, std::string (" ") + STRING_CMD_SHOW_CONF_DEFAULT, color); view.set (row, 0, std::string (" ") + STRING_CMD_SHOW_CONF_DEFAULT, color);
view.set (row, 1, default_config[i->first], color); view.set (row, 1, default_config[i.first], color);
} }
} }
} }
@ -331,9 +330,8 @@ int CmdShow::execute (std::string& output)
{ {
out << STRING_CMD_SHOW_UNREC << "\n"; out << STRING_CMD_SHOW_UNREC << "\n";
std::vector <std::string>::iterator i; for (auto& i : unrecognized)
for (i = unrecognized.begin (); i != unrecognized.end (); ++i) out << " " << i << "\n";
out << " " << *i << "\n";
if (context.color ()) if (context.color ())
out << "\n" << format (STRING_CMD_SHOW_DIFFER_COLOR, error.colorize ("color")); out << "\n" << format (STRING_CMD_SHOW_DIFFER_COLOR, error.colorize ("color"));
@ -408,10 +406,9 @@ int CmdShowRaw::execute (std::string& output)
std::sort (all.begin (), all.end ()); std::sort (all.begin (), all.end ());
// Display them all. // Display them all.
std::vector <std::string>::iterator i;
std::stringstream out; std::stringstream out;
for (i = all.begin (); i != all.end (); ++i) for (auto& i : all)
out << *i << '=' << context.config.get (*i) << "\n"; out << i << '=' << context.config.get (i) << "\n";
output = out.str (); output = out.str ();
return 0; return 0;

View file

@ -66,34 +66,33 @@ int CmdStart::execute (std::string& output)
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
bool nagged = false; bool nagged = false;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
if (! task->has ("start")) if (! task.has ("start"))
{ {
Task before (*task); Task before (task);
// Start the specified task. // Start the specified task.
std::string question = format (STRING_CMD_START_CONFIRM, std::string question = format (STRING_CMD_START_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task->setAsNow ("start"); task.setAsNow ("start");
if (context.config.getBoolean ("journal.time")) if (context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.start.annotation")); task.addAnnotation (context.config.get ("journal.time.start.annotation"));
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (task);
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_START_TASK, *task); feedback_affected (STRING_CMD_START_TASK, task);
if (!nagged) if (!nagged)
nagged = nag (*task); nagged = nag (task);
dependencyChainOnStart (*task); dependencyChainOnStart (task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false); projectChanges[task.get ("project")] = onProjectChange (task, false);
} }
else else
{ {
@ -106,18 +105,17 @@ int CmdStart::execute (std::string& output)
else else
{ {
std::cout << format (STRING_CMD_START_ALREADY, std::cout << format (STRING_CMD_START_ALREADY,
task->id, task.id,
task->get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;
} }
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_START_1 : STRING_CMD_START_N, count); feedback_affected (count == 1 ? STRING_CMD_START_1 : STRING_CMD_START_N, count);
return rc; return rc;

View file

@ -67,16 +67,15 @@ int CmdStats::execute (std::string& output)
// Count the undo transactions. // Count the undo transactions.
std::vector <std::string> undoTxns = context.tdb2.undo.get_lines (); std::vector <std::string> undoTxns = context.tdb2.undo.get_lines ();
int undoCount = 0; int undoCount = 0;
std::vector <std::string>::iterator tx; for (auto& tx : undoTxns)
for (tx = undoTxns.begin (); tx != undoTxns.end (); ++tx) if (tx == "---")
if (*tx == "---")
++undoCount; ++undoCount;
// Count the backlog transactions. // Count the backlog transactions.
std::vector <std::string> backlogTxns = context.tdb2.backlog.get_lines (); std::vector <std::string> backlogTxns = context.tdb2.backlog.get_lines ();
int backlogCount = 0; int backlogCount = 0;
for (tx = backlogTxns.begin (); tx != backlogTxns.end (); ++tx) for (auto& tx : backlogTxns)
if ((*tx)[0] == '{') if (tx[0] == '{')
++backlogCount; ++backlogCount;
// Get all the tasks. // Get all the tasks.
@ -103,12 +102,11 @@ int CmdStats::execute (std::string& output)
std::map <std::string, int> allTags; std::map <std::string, int> allTags;
std::map <std::string, int> allProjects; std::map <std::string, int> allProjects;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
++totalT; ++totalT;
Task::status status = task->getStatus (); Task::status status = task.getStatus ();
switch (status) switch (status)
{ {
case Task::deleted: ++deletedT; break; case Task::deleted: ++deletedT; break;
@ -118,37 +116,37 @@ int CmdStats::execute (std::string& output)
case Task::waiting: ++waitingT; break; case Task::waiting: ++waitingT; break;
} }
if (task->is_blocked) ++blockedT; if (task.is_blocked) ++blockedT;
if (task->is_blocking) ++blockingT; if (task.is_blocking) ++blockingT;
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
if (entry < earliest) earliest = entry; if (entry < earliest) earliest = entry;
if (entry > latest) latest = entry; if (entry > latest) latest = entry;
if (status == Task::completed) if (status == Task::completed)
{ {
time_t end = strtol (task->get ("end").c_str (), NULL, 10); time_t end = strtol (task.get ("end").c_str (), NULL, 10);
daysPending += (end - entry) / 86400.0; daysPending += (end - entry) / 86400.0;
} }
if (status == Task::pending) if (status == Task::pending)
daysPending += (now.toEpoch () - entry) / 86400.0; daysPending += (now.toEpoch () - entry) / 86400.0;
descLength += task->get ("description").length (); descLength += task.get ("description").length ();
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task->getAnnotations (annotations); task.getAnnotations (annotations);
annotationsT += annotations.size (); annotationsT += annotations.size ();
std::vector <std::string> tags; std::vector <std::string> tags;
task->getTags (tags); task.getTags (tags);
if (tags.size ()) ++taggedT; if (tags.size ())
++taggedT;
std::vector <std::string>::iterator t; for (auto& tag : tags)
for (t = tags.begin (); t != tags.end (); ++t) allTags[tag] = 0;
allTags[*t] = 0;
std::string project = task->get ("project"); std::string project = task.get ("project");
if (project != "") if (project != "")
allProjects[project] = 0; allProjects[project] = 0;
} }

View file

@ -64,33 +64,32 @@ int CmdStop::execute (std::string& output)
// Accumulated project change notifications. // Accumulated project change notifications.
std::map <std::string, std::string> projectChanges; std::map <std::string, std::string> projectChanges;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
if (task->has ("start")) if (task.has ("start"))
{ {
Task before (*task); Task before (task);
// Stop the specified task. // Stop the specified task.
std::string question = format (STRING_CMD_STOP_CONFIRM, std::string question = format (STRING_CMD_STOP_CONFIRM,
task->id, task.id,
task->get ("description")); task.get ("description"));
task->modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task->remove ("start"); task.remove ("start");
if (context.config.getBoolean ("journal.time")) if (context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.stop.annotation")); task.addAnnotation (context.config.get ("journal.time.stop.annotation"));
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (task);
context.tdb2.modify (*task); context.tdb2.modify (task);
++count; ++count;
feedback_affected (STRING_CMD_STOP_TASK, *task); feedback_affected (STRING_CMD_STOP_TASK, task);
dependencyChainOnStart (*task); dependencyChainOnStart (task);
if (context.verbose ("project")) if (context.verbose ("project"))
projectChanges[task->get ("project")] = onProjectChange (*task, false); projectChanges[task.get ("project")] = onProjectChange (task, false);
} }
else else
{ {
@ -103,18 +102,17 @@ int CmdStop::execute (std::string& output)
else else
{ {
std::cout << format (STRING_CMD_STOP_ALREADY, std::cout << format (STRING_CMD_STOP_ALREADY,
task->id, task.id,
task->get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;
} }
} }
// Now list the project changes. // Now list the project changes.
std::map <std::string, std::string>::iterator i; for (auto& change : projectChanges)
for (i = projectChanges.begin (); i != projectChanges.end (); ++i) if (change.first != "")
if (i->first != "") context.footnote (change.second);
context.footnote (i->second);
feedback_affected (count == 1 ? STRING_CMD_STOP_1 : STRING_CMD_STOP_N, count); feedback_affected (count == 1 ? STRING_CMD_STOP_1 : STRING_CMD_STOP_N, count);
return rc; return rc;

View file

@ -67,10 +67,9 @@ int CmdSummary::execute (std::string& output)
// Generate unique list of project names from all pending tasks. // Generate unique list of project names from all pending tasks.
std::map <std::string, bool> allProjects; std::map <std::string, bool> allProjects;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task) if (showAllProjects || task.getStatus () == Task::pending)
if (showAllProjects || task->getStatus () == Task::pending) allProjects[task.get ("project")] = false;
allProjects[task->get ("project")] = false;
// Initialize counts, sum. // Initialize counts, sum.
std::map <std::string, int> countPending; std::map <std::string, int> countPending;
@ -80,46 +79,48 @@ int CmdSummary::execute (std::string& output)
time_t now = time (NULL); time_t now = time (NULL);
// Initialize counters. // Initialize counters.
std::map <std::string, bool>::iterator project; for (auto& project : allProjects)
for (project = allProjects.begin (); project != allProjects.end (); ++project)
{ {
countPending [project->first] = 0; countPending [project.first] = 0;
countCompleted [project->first] = 0; countCompleted [project.first] = 0;
sumEntry [project->first] = 0.0; sumEntry [project.first] = 0.0;
counter [project->first] = 0; counter [project.first] = 0;
} }
// Count the various tasks. // Count the various tasks.
for (task = filtered.begin (); task != filtered.end (); ++task) for (auto& task : filtered)
{ {
std::string project = task->get ("project"); std::string project = task.get ("project");
std::vector <std::string> projects = extractParents (project); std::vector <std::string> projects = extractParents (project);
projects.push_back (project); projects.push_back (project);
std::vector <std::string>::const_iterator parent; for (auto& parent : projects)
for (parent = projects.begin (); parent != projects.end (); ++parent) ++counter[parent];
++counter[*parent];
if (task->getStatus () == Task::pending || if (task.getStatus () == Task::pending ||
task->getStatus () == Task::waiting) task.getStatus () == Task::waiting)
for (parent = projects.begin (); parent != projects.end (); ++parent)
{ {
++countPending[*parent]; for (auto& parent : projects)
{
++countPending[parent];
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
if (entry) if (entry)
sumEntry[*parent] = sumEntry[*parent] + (double) (now - entry); sumEntry[parent] = sumEntry[parent] + (double) (now - entry);
}
} }
else if (task->getStatus () == Task::completed) else if (task.getStatus () == Task::completed)
for (parent = projects.begin (); parent != projects.end (); ++parent)
{ {
++countCompleted[*parent]; for (auto& parent : projects)
{
++countCompleted[parent];
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
time_t end = strtol (task->get ("end").c_str (), NULL, 10); time_t end = strtol (task.get ("end").c_str (), NULL, 10);
if (entry && end) if (entry && end)
sumEntry[*parent] = sumEntry[*parent] + (double) (end - entry); sumEntry[parent] = sumEntry[parent] + (double) (end - entry);
}
} }
} }
@ -140,35 +141,33 @@ int CmdSummary::execute (std::string& output)
int barWidth = 30; int barWidth = 30;
std::vector <std::string> processed; std::vector <std::string> processed;
std::map <std::string, bool>::iterator i; for (auto& i : allProjects)
for (i = allProjects.begin (); i != allProjects.end (); ++i)
{ {
if (showAllProjects || countPending[i->first] > 0) if (showAllProjects || countPending[i.first] > 0)
{ {
const std::vector <std::string> parents = extractParents (i->first); const std::vector <std::string> parents = extractParents (i.first);
std::vector <std::string>::const_iterator parent; for (auto& parent : parents)
for (parent = parents.begin (); parent != parents.end (); parent++)
{ {
if (std::find (processed.begin (), processed.end (), *parent) if (std::find (processed.begin (), processed.end (), parent)
== processed.end ()) == processed.end ())
{ {
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, indentProject (*parent)); view.set (row, 0, indentProject (parent));
processed.push_back (*parent); processed.push_back (parent);
} }
} }
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, (i->first == "" view.set (row, 0, (i.first == ""
? STRING_CMD_SUMMARY_NONE ? STRING_CMD_SUMMARY_NONE
: indentProject (i->first, " ", '.'))); : indentProject (i.first, " ", '.')));
view.set (row, 1, countPending[i->first]); view.set (row, 1, countPending[i.first]);
if (counter[i->first]) if (counter[i.first])
view.set (row, 2, Duration ((int) (sumEntry[i->first] / (double)counter[i->first])).format ()); view.set (row, 2, Duration ((int) (sumEntry[i.first] / (double)counter[i.first])).format ());
int c = countCompleted[i->first]; int c = countCompleted[i.first];
int p = countPending[i->first]; int p = countPending[i.first];
int completedBar = 0; int completedBar = 0;
if (c + p) if (c + p)
completedBar = (c * barWidth) / (c + p); completedBar = (c * barWidth) / (c + p);
@ -191,7 +190,7 @@ int CmdSummary::execute (std::string& output)
if (c + p) if (c + p)
sprintf (percent, "%d%%", 100 * c / (c + p)); sprintf (percent, "%d%%", 100 * c / (c + p));
view.set (row, 3, percent); view.set (row, 3, percent);
processed.push_back (i->first); processed.push_back (i.first);
} }
} }

View file

@ -57,10 +57,9 @@ int CmdSync::execute (std::string& output)
// Loog for the 'init' keyword to indicate one-time pending.data upload. // Loog for the 'init' keyword to indicate one-time pending.data upload.
bool first_time_init = false; bool first_time_init = false;
std::vector <std::string> words = context.cli.getWords (); std::vector <std::string> words = context.cli.getWords ();
std::vector <std::string>::iterator word; for (auto& word : words)
for (word = words.begin (); word != words.end (); ++word)
{ {
if (closeEnough ("initialize", *word, 4)) if (closeEnough ("initialize", word, 4))
{ {
if (!context.config.getBoolean ("confirmation") || if (!context.config.getBoolean ("confirmation") ||
confirm (STRING_CMD_SYNC_INIT)) confirm (STRING_CMD_SYNC_INIT))
@ -125,24 +124,22 @@ int CmdSync::execute (std::string& output)
// deltas is meaningless. // deltas is meaningless.
context.tdb2.backlog._file.truncate (); context.tdb2.backlog._file.truncate ();
std::vector <Task> pending = context.tdb2.pending.get_tasks (); auto pending = context.tdb2.pending.get_tasks ();
std::vector <Task>::iterator i; for (auto& i : pending)
for (i = pending.begin (); i != pending.end (); ++i)
{ {
payload += i->composeJSON () + "\n"; payload += i.composeJSON () + "\n";
++upload_count; ++upload_count;
} }
} }
else else
{ {
std::vector <std::string> lines = context.tdb2.backlog.get_lines (); std::vector <std::string> lines = context.tdb2.backlog.get_lines ();
std::vector <std::string>::iterator i; for (auto& i : lines)
for (i = lines.begin (); i != lines.end (); ++i)
{ {
if ((*i)[0] == '{') if (i[0] == '{')
++upload_count; ++upload_count;
payload += *i + "\n"; payload += i + "\n";
} }
} }
@ -190,14 +187,13 @@ int CmdSync::execute (std::string& output)
context.tdb2.all_tasks (); context.tdb2.all_tasks ();
std::string sync_key = ""; std::string sync_key = "";
std::vector <std::string>::iterator line; for (auto& line : lines)
for (line = lines.begin (); line != lines.end (); ++line)
{ {
if ((*line)[0] == '{') if (line[0] == '{')
{ {
++download_count; ++download_count;
Task from_server (*line); Task from_server (line);
std::string uuid = from_server.get ("uuid"); std::string uuid = from_server.get ("uuid");
// Is it a new task from the server, or an update to an existing one? // Is it a new task from the server, or an update to an existing one?
@ -225,9 +221,9 @@ int CmdSync::execute (std::string& output)
context.tdb2.add (from_server, false); context.tdb2.add (from_server, false);
} }
} }
else if (*line != "") else if (line != "")
{ {
sync_key = *line; sync_key = line;
context.debug ("Sync key " + sync_key); context.debug ("Sync key " + sync_key);
} }

View file

@ -54,15 +54,11 @@ int CmdTags::execute (std::string& output)
std::stringstream out; std::stringstream out;
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
if (context.config.getBoolean ("list.all.tags")) if (context.config.getBoolean ("list.all.tags"))
{ for (auto& task : context.tdb2.completed.get_tasks ())
std::vector <Task> extra = context.tdb2.completed.get_tasks (); tasks.push_back (task);
std::vector <Task>::iterator task;
for (task = extra.begin (); task != extra.end (); ++task)
tasks.push_back (*task);
}
int quantity = tasks.size (); int quantity = tasks.size ();
@ -74,18 +70,16 @@ int CmdTags::execute (std::string& output)
// Scan all the tasks for their project name, building a map using project // Scan all the tasks for their project name, building a map using project
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
task->getTags (tags); task.getTags (tags);
std::vector <std::string>::iterator tag; for (auto& tag : tags)
for (tag = tags.begin (); tag != tags.end (); ++tag) if (unique.find (tag) != unique.end ())
if (unique.find (*tag) != unique.end ()) unique[tag]++;
unique[*tag]++;
else else
unique[*tag] = 1; unique[tag] = 1;
} }
if (unique.size ()) if (unique.size ())
@ -101,19 +95,18 @@ int CmdTags::execute (std::string& output)
Color bold ("bold"); Color bold ("bold");
bool special = false; bool special = false;
std::map <std::string, int>::iterator i; for (auto& i : unique)
for (i = unique.begin (); i != unique.end (); ++i)
{ {
// Highlight the special tags. // Highlight the special tags.
special = (context.color () && special = (context.color () &&
(i->first == "nocolor" || (i.first == "nocolor" ||
i->first == "nonag" || i.first == "nonag" ||
i->first == "nocal" || i.first == "nocal" ||
i->first == "next")) ? true : false; i.first == "next")) ? true : false;
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, i->first, special ? bold : Color ()); view.set (row, 0, i.first, special ? bold : Color ());
view.set (row, 1, i->second, special ? bold : Color ()); view.set (row, 1, i.second, special ? bold : Color ());
} }
out << optionalBlankLine () out << optionalBlankLine ()
@ -156,15 +149,11 @@ CmdCompletionTags::CmdCompletionTags ()
int CmdCompletionTags::execute (std::string& output) int CmdCompletionTags::execute (std::string& output)
{ {
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
if (context.config.getBoolean ("complete.all.tags")) if (context.config.getBoolean ("complete.all.tags"))
{ for (auto& task : context.tdb2.completed.get_tasks ())
std::vector <Task> extra = context.tdb2.completed.get_tasks (); tasks.push_back (task);
std::vector <Task>::iterator task;
for (task = extra.begin (); task != extra.end (); ++task)
tasks.push_back (*task);
}
// Apply filter. // Apply filter.
Filter filter; Filter filter;
@ -174,15 +163,13 @@ int CmdCompletionTags::execute (std::string& output)
// Scan all the tasks for their tags, building a map using tag // Scan all the tasks for their tags, building a map using tag
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
task->getTags (tags); task.getTags (tags);
std::vector <std::string>::iterator tag; for (auto& tag : tags)
for (tag = tags.begin (); tag != tags.end (); ++tag) unique[tag] = 0;
unique[*tag] = 0;
} }
// add built-in tags to map // add built-in tags to map
@ -192,9 +179,8 @@ int CmdCompletionTags::execute (std::string& output)
unique["next"] = 0; unique["next"] = 0;
std::stringstream out; std::stringstream out;
std::map <std::string, int>::iterator it; for (auto& it : unique)
for (it = unique.begin (); it != unique.end (); ++it) out << it.first << "\n";
out << it->first << "\n";
output = out.str (); output = out.str ();
return 0; return 0;

View file

@ -102,43 +102,41 @@ int CmdTimesheet::execute (std::string& output)
Color label (context.config.get ("color.label")); Color label (context.config.get ("color.label"));
completed.colorHeader (label); completed.colorHeader (label);
std::vector <Task>::iterator task; for (auto& task : all)
for (task = all.begin (); task != all.end (); ++task)
{ {
// If task completed within range. // If task completed within range.
if (task->getStatus () == Task::completed) if (task.getStatus () == Task::completed)
{ {
Date compDate (task->get_date ("end")); Date compDate (task.get_date ("end"));
if (compDate >= start && compDate < end) if (compDate >= start && compDate < end)
{ {
Color c; Color c;
if (context.color ()) if (context.color ())
autoColorize (*task, c); autoColorize (task, c);
int row = completed.addRow (); int row = completed.addRow ();
std::string format = context.config.get ("dateformat.report"); std::string format = context.config.get ("dateformat.report");
if (format == "") if (format == "")
format = context.config.get ("dateformat"); format = context.config.get ("dateformat");
completed.set (row, 1, task->get ("project"), c); completed.set (row, 1, task.get ("project"), c);
if(task->has ("due")) if(task.has ("due"))
{ {
Date dt (task->get_date ("due")); Date dt (task.get_date ("due"));
completed.set (row, 2, dt.toString (format)); completed.set (row, 2, dt.toString (format));
} }
std::string description = task->get ("description"); std::string description = task.get ("description");
int indent = context.config.getInteger ("indent.annotation"); int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task->getAnnotations (annotations); task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator ann; for (auto& ann : annotations)
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
description += "\n" description += "\n"
+ std::string (indent, ' ') + std::string (indent, ' ')
+ Date (ann->first.substr (11)).toString (context.config.get ("dateformat")) + Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ " " + " "
+ ann->second; + ann.second;
completed.set (row, 3, description, c); completed.set (row, 3, description, c);
} }
@ -160,43 +158,42 @@ int CmdTimesheet::execute (std::string& output)
started.add (Column::factory ("string", STRING_COLUMN_LABEL_DESC)); started.add (Column::factory ("string", STRING_COLUMN_LABEL_DESC));
started.colorHeader (label); started.colorHeader (label);
for (task = all.begin (); task != all.end (); ++task) for (auto& task : all)
{ {
// If task started within range, but not completed withing range. // If task started within range, but not completed withing range.
if (task->getStatus () == Task::pending && if (task.getStatus () == Task::pending &&
task->has ("start")) task.has ("start"))
{ {
Date startDate (task->get_date ("start")); Date startDate (task.get_date ("start"));
if (startDate >= start && startDate < end) if (startDate >= start && startDate < end)
{ {
Color c; Color c;
if (context.color ()) if (context.color ())
autoColorize (*task, c); autoColorize (task, c);
int row = started.addRow (); int row = started.addRow ();
std::string format = context.config.get ("dateformat.report"); std::string format = context.config.get ("dateformat.report");
if (format == "") if (format == "")
format = context.config.get ("dateformat"); format = context.config.get ("dateformat");
started.set (row, 1, task->get ("project"), c); started.set (row, 1, task.get ("project"), c);
if(task->has ("due")) if (task.has ("due"))
{ {
Date dt (task->get_date ("due")); Date dt (task.get_date ("due"));
started.set (row, 2, dt.toString (format)); started.set (row, 2, dt.toString (format));
} }
std::string description = task->get ("description"); std::string description = task.get ("description");
int indent = context.config.getInteger ("indent.annotation"); int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task->getAnnotations (annotations); task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator ann; for (auto& ann : annotations)
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
description += "\n" description += "\n"
+ std::string (indent, ' ') + std::string (indent, ' ')
+ Date (ann->first.substr (11)).toString (context.config.get ("dateformat")) + Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ " " + " "
+ ann->second; + ann.second;
started.set (row, 3, description, c); started.set (row, 3, description, c);
} }

View file

@ -55,15 +55,14 @@ int CmdUDAs::execute (std::string& output)
std::stringstream out; std::stringstream out;
std::vector <std::string> udas; std::vector <std::string> udas;
Config::const_iterator name; for (auto& name : context.config)
for (name = context.config.begin (); name != context.config.end (); ++name)
{ {
if (name->first.substr (0, 4) == "uda." && if (name.first.substr (0, 4) == "uda." &&
name->first.find (".type") != std::string::npos) name.first.find (".type") != std::string::npos)
{ {
std::string::size_type period = name->first.find ('.', 4); std::string::size_type period = name.first.find ('.', 4);
if (period != std::string::npos) if (period != std::string::npos)
udas.push_back (name->first.substr (4, period - 4)); udas.push_back (name.first.substr (4, period - 4));
} }
} }
@ -90,25 +89,23 @@ int CmdUDAs::execute (std::string& output)
Color label (context.config.get ("color.label")); Color label (context.config.get ("color.label"));
view.colorHeader (label); view.colorHeader (label);
std::vector <std::string>::iterator uda; for (auto& uda : udas)
for (uda = udas.begin (); uda != udas.end (); ++uda)
{ {
std::string type = context.config.get ("uda." + *uda + ".type"); std::string type = context.config.get ("uda." + uda + ".type");
std::string label = context.config.get ("uda." + *uda + ".label"); std::string label = context.config.get ("uda." + uda + ".label");
std::string values = context.config.get ("uda." + *uda + ".values"); std::string values = context.config.get ("uda." + uda + ".values");
std::string defval = context.config.get ("uda." + *uda + ".default"); std::string defval = context.config.get ("uda." + uda + ".default");
if (label == "") if (label == "")
label = *uda; label = uda;
// Count UDA usage by UDA. // Count UDA usage by UDA.
int count = 0; int count = 0;
std::vector <Task>::iterator i; for (auto& i : filtered)
for (i = filtered.begin (); i != filtered.end (); ++i) if (i.has (uda))
if (i->has (*uda))
++count; ++count;
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, *uda); view.set (row, 0, uda);
view.set (row, 1, type); view.set (row, 1, type);
view.set (row, 2, label); view.set (row, 2, label);
view.set (row, 3, values); view.set (row, 3, values);
@ -132,14 +129,12 @@ int CmdUDAs::execute (std::string& output)
// Orphans are task attributes that are not represented in context.columns. // Orphans are task attributes that are not represented in context.columns.
std::map <std::string, int> orphans; std::map <std::string, int> orphans;
std::vector <Task>::iterator i; for (auto& i : filtered)
for (i = filtered.begin (); i != filtered.end (); ++i)
{ {
std::map <std::string, std::string>::iterator att; for (auto& att : i)
for (att = i->begin (); att != i->end (); ++att) if (att.first.substr (0, 11) != "annotation_" &&
if (att->first.substr (0, 11) != "annotation_" && context.columns.find (att.first) == context.columns.end ())
context.columns.find (att->first) == context.columns.end ()) orphans[att.first]++;
orphans[att->first]++;
} }
if (orphans.size ()) if (orphans.size ())
@ -153,12 +148,11 @@ int CmdUDAs::execute (std::string& output)
Color label (context.config.get ("color.label")); Color label (context.config.get ("color.label"));
orphanView.colorHeader (label); orphanView.colorHeader (label);
std::map <std::string, int>::iterator o; for (auto& o : orphans)
for (o = orphans.begin (); o != orphans.end (); ++o)
{ {
int row = orphanView.addRow (); int row = orphanView.addRow ();
orphanView.set (row, 0, o->first); orphanView.set (row, 0, o.first);
orphanView.set (row, 1, o->second); orphanView.set (row, 1, o.second);
} }
out << optionalBlankLine () out << optionalBlankLine ()
@ -188,15 +182,14 @@ CmdCompletionUDAs::CmdCompletionUDAs ()
int CmdCompletionUDAs::execute (std::string& output) int CmdCompletionUDAs::execute (std::string& output)
{ {
std::vector <std::string> udas; std::vector <std::string> udas;
Config::const_iterator name; for (auto& name : context.config)
for (name = context.config.begin (); name != context.config.end (); ++name)
{ {
if (name->first.substr (0, 4) == "uda." && if (name.first.substr (0, 4) == "uda." &&
name->first.find (".type") != std::string::npos) name.first.find (".type") != std::string::npos)
{ {
std::string::size_type period = name->first.find ('.', 4); std::string::size_type period = name.first.find ('.', 4);
if (period != std::string::npos) if (period != std::string::npos)
udas.push_back (name->first.substr (4, period - 4)); udas.push_back (name.first.substr (4, period - 4));
} }
} }

View file

@ -45,9 +45,8 @@ CmdUndo::CmdUndo ()
int CmdUndo::execute (std::string& output) int CmdUndo::execute (std::string& output)
{ {
// Detect attempts to modify the task. // Detect attempts to modify the task.
std::vector <A>::iterator a; for (auto& a : context.cli._args)
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a) if (a.hasTag ("MODIFICATION"))
if (a->hasTag ("MODIFICATION"))
throw std::string (STRING_CMD_UNDO_MODS); throw std::string (STRING_CMD_UNDO_MODS);
context.tdb2.revert (); context.tdb2.revert ();

View file

@ -62,20 +62,19 @@ int CmdUrgency::execute (std::string& output)
// Display urgency for the selected tasks. // Display urgency for the selected tasks.
std::stringstream out; std::stringstream out;
std::vector <Task>::iterator task; for (auto& task : filtered)
for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
if (task->id) if (task.id)
{ {
out << format (STRING_CMD_URGENCY_RESULT, out << format (STRING_CMD_URGENCY_RESULT,
task->id, task->urgency ()) task.id, task.urgency ())
<< "\n"; << "\n";
} }
else else
{ {
out << format (STRING_CMD_URGENCY_RESULT, out << format (STRING_CMD_URGENCY_RESULT,
task->get ("uuid"), task.get ("uuid"),
task->urgency ()) task.urgency ())
<< "\n"; << "\n";
} }
} }