C++11: Cleaned up program framework with range-based for

This commit is contained in:
Paul Beckingham 2015-05-11 17:50:53 -04:00
parent 5a57dfd70d
commit e74c6963a9
28 changed files with 937 additions and 1221 deletions

File diff suppressed because it is too large Load diff

View file

@ -119,10 +119,9 @@ Color::Color (const std::string& spec)
bool bg = false;
int index;
std::string word;
std::vector <std::string>::iterator it;
for (it = words.begin (); it != words.end (); ++it)
for (auto& it : words)
{
word = lowerCase (trim (*it));
word = lowerCase (trim (it));
if (word == "bold") fg_value |= _COLOR_BOLD;
else if (word == "bright") bg_value |= _COLOR_BRIGHT;
@ -154,7 +153,7 @@ Color::Color (const std::string& spec)
{
index = atoi (word.substr (4).c_str ());
if (index < 0 || index > 23)
throw format (STRING_COLOR_UNRECOGNIZED, *it);
throw format (STRING_COLOR_UNRECOGNIZED, it);
if (bg)
{
@ -176,7 +175,7 @@ Color::Color (const std::string& spec)
index = atoi (word.substr (3).c_str ());
if (word.length () != 6 ||
index < 0 || index > 555)
throw format (STRING_COLOR_UNRECOGNIZED, *it);
throw format (STRING_COLOR_UNRECOGNIZED, it);
int r = atoi (word.substr (3, 1).c_str ());
int g = atoi (word.substr (4, 1).c_str ());
@ -184,7 +183,7 @@ Color::Color (const std::string& spec)
if (r < 0 || r > 5 ||
g < 0 || g > 5 ||
b < 0 || b > 5)
throw format (STRING_COLOR_UNRECOGNIZED, *it);
throw format (STRING_COLOR_UNRECOGNIZED, it);
index = 16 + r*36 + g*6 + b;
@ -207,7 +206,7 @@ Color::Color (const std::string& spec)
{
index = atoi (word.substr (5).c_str ());
if (index < 0 || index > 255)
throw format (STRING_COLOR_UNRECOGNIZED, *it);
throw format (STRING_COLOR_UNRECOGNIZED, it);
upgrade ();
@ -225,7 +224,7 @@ Color::Color (const std::string& spec)
}
}
else if (word != "")
throw format (STRING_COLOR_UNRECOGNIZED, *it);
throw format (STRING_COLOR_UNRECOGNIZED, it);
}
// Now combine the fg and bg into a single color.

View file

@ -528,11 +528,8 @@ void Config::parse (const std::string& input, int nest /* = 1 */)
split (lines, input, "\n");
// Parse each line.
std::vector <std::string>::iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
for (auto& line : lines)
{
std::string line = *it;
// Remove comments.
std::string::size_type pound = line.find ("#"); // no i18n
if (pound != std::string::npos)
@ -714,9 +711,8 @@ void Config::set (const std::string& key, const std::string& value)
// Provide a vector of all configuration keys.
void Config::all (std::vector<std::string>& items) const
{
std::map <std::string, std::string>::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
items.push_back (it->first);
for (auto& it : *this)
items.push_back (it.first);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -84,13 +84,11 @@ Context::Context ()
////////////////////////////////////////////////////////////////////////////////
Context::~Context ()
{
std::map<std::string, Command*>::iterator com;
for (com = commands.begin (); com != commands.end (); ++com)
delete com->second;
for (auto& com : commands)
delete com.second;
std::map<std::string, Column*>::iterator col;
for (col = columns.begin (); col != columns.end (); ++col)
delete col->second;
for (auto& col : columns)
delete col.second;
}
////////////////////////////////////////////////////////////////////////////////
@ -156,14 +154,13 @@ int Context::initialize (int argc, const char** argv)
////////////////////////////////////////////////////////////////////////////
Command::factory (commands);
std::map <std::string, Command*>::iterator cmd;
for (cmd = commands.begin (); cmd != commands.end (); ++cmd)
for (auto& cmd : commands)
{
cli.entity ("cmd", cmd->first);
cli.entity ((cmd->second->read_only () ? "readcmd" : "writecmd"), cmd->first);
cli.entity ("cmd", cmd.first);
cli.entity ((cmd.second->read_only () ? "readcmd" : "writecmd"), cmd.first);
if (cmd->first[0] == '_')
cli.entity ("helper", cmd->first);
if (cmd.first[0] == '_')
cli.entity ("helper", cmd.first);
}
////////////////////////////////////////////////////////////////////////////
@ -173,9 +170,8 @@ int Context::initialize (int argc, const char** argv)
////////////////////////////////////////////////////////////////////////////
Column::factory (columns);
std::map <std::string, Column*>::iterator col;
for (col = columns.begin (); col != columns.end (); ++col)
cli.entity ("attribute", col->first);
for (auto& col : columns)
cli.entity ("attribute", col.first);
cli.entity ("pseudo", "limit");
@ -188,15 +184,11 @@ int Context::initialize (int argc, const char** argv)
for (unsigned int i = 0; i < NUM_MODIFIER_NAMES; ++i)
cli.entity ("modifier", modifierNames[i]);
std::vector <std::string> operators;
Eval::getOperators (operators);
std::vector <std::string>::iterator op;
for (op = operators.begin (); op != operators.end (); ++op)
cli.entity ("operator", *op);
for (auto& op : Eval::getOperators ())
cli.entity ("operator", op);
Eval::getBinaryOperators (operators);
for (op = operators.begin (); op != operators.end (); ++op)
cli.entity ("binary_operator", *op);
for (auto& op : Eval::getBinaryOperators ())
cli.entity ("binary_operator", op);
////////////////////////////////////////////////////////////////////////////
//
@ -223,21 +215,20 @@ int Context::initialize (int argc, const char** argv)
bool foundDefault = false;
bool foundAssumed = false;
std::string combined;
std::vector <A>::const_iterator a;
for (a = cli._args.begin (); a != cli._args.end (); ++a)
for (auto& a : cli._args)
{
if (combined.length ())
combined += ' ';
if (a->attribute ("canonical") != "")
combined += a->attribute ("canonical");
if (a.attribute ("canonical") != "")
combined += a.attribute ("canonical");
else
combined += a->attribute ("raw");
combined += a.attribute ("raw");
if (a->hasTag ("DEFAULT"))
if (a.hasTag ("DEFAULT"))
foundDefault = true;
if (a->hasTag ("ASSUMED"))
if (a.hasTag ("ASSUMED"))
foundAssumed = true;
}
@ -280,44 +271,40 @@ int Context::initialize (int argc, const char** argv)
// Dump all debug messages, controlled by rc.debug.
if (config.getBoolean ("debug"))
{
std::vector <std::string>::iterator d;
for (d = debugMessages.begin (); d != debugMessages.end (); ++d)
for (auto& d : debugMessages)
if (color ())
std::cerr << colorizeDebug (*d) << "\n";
std::cerr << colorizeDebug (d) << "\n";
else
std::cerr << *d << "\n";
std::cerr << d << "\n";
}
// Dump all headers, controlled by 'header' verbosity token.
if (verbose ("header"))
{
std::vector <std::string>::iterator h;
for (h = headers.begin (); h != headers.end (); ++h)
for (auto& h : headers)
if (color ())
std::cerr << colorizeHeader (*h) << "\n";
std::cerr << colorizeHeader (h) << "\n";
else
std::cerr << *h << "\n";
std::cerr << h << "\n";
}
// Dump all footnotes, controlled by 'footnote' verbosity token.
if (verbose ("footnote"))
{
std::vector <std::string>::iterator f;
for (f = footnotes.begin (); f != footnotes.end (); ++f)
for (auto& f : footnotes)
if (color ())
std::cerr << colorizeFootnote (*f) << "\n";
std::cerr << colorizeFootnote (f) << "\n";
else
std::cerr << *f << "\n";
std::cerr << f << "\n";
}
// Dump all errors, non-maskable.
// Colorized as footnotes.
std::vector <std::string>::iterator e;
for (e = errors.begin (); e != errors.end (); ++e)
for (auto& e : errors)
if (color ())
std::cerr << colorizeFootnote (*e) << "\n";
std::cerr << colorizeFootnote (e) << "\n";
else
std::cerr << *e << "\n";
std::cerr << e << "\n";
}
timer_init.stop ();
@ -390,23 +377,21 @@ int Context::run ()
// Dump all debug messages, controlled by rc.debug.
if (config.getBoolean ("debug"))
{
std::vector <std::string>::iterator d;
for (d = debugMessages.begin (); d != debugMessages.end (); ++d)
for (auto& d : debugMessages)
if (color ())
std::cerr << colorizeDebug (*d) << "\n";
std::cerr << colorizeDebug (d) << "\n";
else
std::cerr << *d << "\n";
std::cerr << d << "\n";
}
// Dump all headers, controlled by 'header' verbosity token.
if (verbose ("header"))
{
std::vector <std::string>::iterator h;
for (h = headers.begin (); h != headers.end (); ++h)
for (auto& h : headers)
if (color ())
std::cerr << colorizeHeader (*h) << "\n";
std::cerr << colorizeHeader (h) << "\n";
else
std::cerr << *h << "\n";
std::cerr << h << "\n";
}
// Dump the report output.
@ -415,22 +400,20 @@ int Context::run ()
// Dump all footnotes, controlled by 'footnote' verbosity token.
if (verbose ("footnote"))
{
std::vector <std::string>::iterator f;
for (f = footnotes.begin (); f != footnotes.end (); ++f)
for (auto& f : footnotes)
if (color ())
std::cerr << colorizeFootnote (*f) << "\n";
std::cerr << colorizeFootnote (f) << "\n";
else
std::cerr << *f << "\n";
std::cerr << f << "\n";
}
// Dump all errors, non-maskable.
// Colorized as footnotes.
std::vector <std::string>::iterator e;
for (e = errors.begin (); e != errors.end (); ++e)
for (auto& e : errors)
if (color ())
std::cerr << colorizeError (*e) << "\n";
std::cerr << colorizeError (e) << "\n";
else
std::cerr << *e << "\n";
std::cerr << e << "\n";
return rc;
}
@ -581,9 +564,8 @@ bool Context::verbose (const std::string& token)
const std::vector <std::string> Context::getColumns () const
{
std::vector <std::string> output;
std::map <std::string, Column*>::const_iterator i;
for (i = columns.begin (); i != columns.end (); ++i)
output.push_back (i->first);
for (auto& col : columns)
output.push_back (col.first);
return output;
}
@ -592,9 +574,8 @@ const std::vector <std::string> Context::getColumns () const
const std::vector <std::string> Context::getCommands () const
{
std::vector <std::string> output;
std::map <std::string, Command*>::const_iterator i;
for (i = commands.begin (); i != commands.end (); ++i)
output.push_back (i->first);
for (auto& cmd : commands)
output.push_back (cmd.first);
return output;
}
@ -640,24 +621,22 @@ void Context::staticInitialization ()
Lexer::dateFormat = Variant::dateFormat = config.get ("dateformat");
Lexer::isoEnabled = Variant::isoEnabled = config.getBoolean ("date.iso");
Config::const_iterator rc;
for (rc = config.begin (); rc != config.end (); ++rc)
for (auto& rc : config)
{
if (rc->first.substr (0, 4) == "uda." &&
rc->first.substr (rc->first.length () - 7, 7) == ".values")
if (rc.first.substr (0, 4) == "uda." &&
rc.first.substr (rc.first.length () - 7, 7) == ".values")
{
std::string name = rc->first.substr (4, rc->first.length () - 7 - 4);
std::string name = rc.first.substr (4, rc.first.length () - 7 - 4);
std::vector <std::string> values;
split (values, rc->second, ',');
split (values, rc.second, ',');
for (auto r = values.rbegin(); r != values.rend (); ++r)
Task::customOrder[name].push_back (*r);
}
}
std::map <std::string, Column*>::iterator i;
for (i = columns.begin (); i != columns.end (); ++i)
Task::attributes[i->first] = i->second->type ();
for (auto& col : columns)
Task::attributes[col.first] = col.second->type ();
Task::urgencyProjectCoefficient = config.getReal ("urgency.project.coefficient");
Task::urgencyActiveCoefficient = config.getReal ("urgency.active.coefficient");
@ -676,11 +655,10 @@ void Context::staticInitialization ()
// Tag- and project-specific coefficients.
std::vector <std::string> all;
config.all (all);
std::vector <std::string>::iterator var;
for (var = all.begin (); var != all.end (); ++var)
if (var->substr (0, 13) == "urgency.user." ||
var->substr (0, 12) == "urgency.uda.")
Task::coefficients[*var] = config.getReal (*var);
for (auto& var : all)
if (var.substr (0, 13) == "urgency.user." ||
var.substr (0, 12) == "urgency.uda.")
Task::coefficients[var] = config.getReal (var);
}
////////////////////////////////////////////////////////////////////////////////
@ -745,16 +723,14 @@ void Context::clear ()
tdb2.clear ();
// Eliminate the command objects.
std::map <std::string, Command*>::iterator com;
for (com = commands.begin (); com != commands.end (); ++com)
delete com->second;
for (auto& cmd : commands)
delete cmd.second;
commands.clear ();
// Eliminate the column objects.
std::map <std::string, Column*>::iterator col;
for (col = columns.begin (); col != columns.end (); ++col)
delete col->second;
for (auto& col : columns)
delete col.second;
columns.clear ();
clearMessages ();
@ -770,8 +746,7 @@ void Context::updateXtermTitle ()
std::string command = cli.getCommand ();
std::string title;
std::vector <A>::const_iterator a;
for (a = cli._args.begin (); a != cli._args.end (); ++a)
for (auto a = cli._args.begin (); a != cli._args.end (); ++a)
{
if (a != cli._args.begin ())
title += ' ';
@ -799,10 +774,9 @@ void Context::updateVerbosity ()
////////////////////////////////////////////////////////////////////////////////
void Context::loadAliases ()
{
std::map <std::string, std::string>::iterator i;
for (i = config.begin (); i != config.end (); ++i)
if (i->first.substr (0, 6) == "alias.")
cli.alias (i->first.substr (6), i->second);
for (auto& i : config)
if (i.first.substr (0, 6) == "alias.")
cli.alias (i.first.substr (6), i.second);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -88,7 +88,7 @@ bool DOM::get (const std::string& name, Variant& value)
name.substr (0, 3) == "rc.")
{
std::string key = name.substr (3);
std::map <std::string, std::string>::iterator c = context.config.find (key);
auto c = context.config.find (key);
if (c != context.config.end ())
{
value = Variant (c->second);
@ -376,8 +376,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
int count = 0;
// Count off the 'a'th annotation.
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); ++i)
for (auto& i : annos)
{
if (++count == a)
{
@ -385,12 +384,12 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
{
// annotation_1234567890
// 0 ^11
value = Variant ((time_t) strtol (i->first.substr (11).c_str (), NULL, 10), Variant::type_date);
value = Variant ((time_t) strtol (i.first.substr (11).c_str (), NULL, 10), Variant::type_date);
return true;
}
else if (elements[3] == "description")
{
value = Variant (i->second);
value = Variant (i.second);
return true;
}
}
@ -405,8 +404,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
int count = 0;
// Count off the 'a'th annotation.
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); ++i)
for (auto& i : annos)
{
if (++count == a)
{
@ -419,7 +417,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
// <annotations>.<N>.entry.hour
// <annotations>.<N>.entry.minute
// <annotations>.<N>.entry.second
Date date (i->first.substr (11));
Date date (i.first.substr (11));
if (elements[4] == "year") { value = Variant (static_cast<int> (date.year ())); return true; }
else if (elements[4] == "month") { value = Variant (static_cast<int> (date.month ())); return true; }
else if (elements[4] == "day") { value = Variant (static_cast<int> (date.day ())); return true; }

View file

@ -536,10 +536,9 @@ int Date::length (const std::string& format)
{
int total = 0;
std::string::const_iterator i;
for (i = format.begin (); i != format.end (); ++i)
for (auto& i : format)
{
switch (*i)
switch (i)
{
case 'm':
case 'M':
@ -563,7 +562,7 @@ int Date::length (const std::string& format)
case 'B': total += 10; break;
// Calculate the width, don't assume a single character width.
default: total += mk_wcwidth (*i); break;
default: total += mk_wcwidth (i); break;
}
}

View file

@ -217,21 +217,25 @@ void Eval::debug (bool value)
////////////////////////////////////////////////////////////////////////////////
// Static.
void Eval::getOperators (std::vector <std::string>& all)
std::vector <std::string> Eval::getOperators ()
{
all.clear ();
std::vector <std::string> all;
for (unsigned int i = 0; i < NUM_OPERATORS; ++i)
all.push_back (operators[i].op);
return all;
}
////////////////////////////////////////////////////////////////////////////////
// Static.
void Eval::getBinaryOperators (std::vector <std::string>& all)
std::vector <std::string> Eval::getBinaryOperators ()
{
all.clear ();
std::vector <std::string> all;
for (unsigned int i = 0; i < NUM_OPERATORS; ++i)
if (operators[i].type == 'b')
all.push_back (operators[i].op);
return all;
}
////////////////////////////////////////////////////////////////////////////////
@ -245,12 +249,11 @@ void Eval::evaluatePostfixStack (
// This is stack used by the postfix evaluator.
std::vector <Variant> values;
std::vector <std::pair <std::string, Lexer::Type>>::const_iterator token;
for (token = tokens.begin (); token != tokens.end (); ++token)
for (auto& token : tokens)
{
// Unary operators.
if (token->second == Lexer::Type::op &&
token->first == "!")
if (token.second == Lexer::Type::op &&
token.first == "!")
{
if (values.size () < 1)
throw std::string (STRING_EVAL_NO_EVAL);
@ -260,10 +263,10 @@ void Eval::evaluatePostfixStack (
Variant result = ! right;
values.push_back (result);
if (_debug)
context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token->first, (std::string) right, (std::string) result));
context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result));
}
else if (token->second == Lexer::Type::op &&
token->first == "_neg_")
else if (token.second == Lexer::Type::op &&
token.first == "_neg_")
{
if (values.size () < 1)
throw std::string (STRING_EVAL_NO_EVAL);
@ -276,18 +279,18 @@ void Eval::evaluatePostfixStack (
values.push_back (result);
if (_debug)
context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token->first, (std::string) right, (std::string) result));
context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result));
}
else if (token->second == Lexer::Type::op &&
token->first == "_pos_")
else if (token.second == Lexer::Type::op &&
token.first == "_pos_")
{
// The _pos_ operator is a NOP.
if (_debug)
context.debug (format ("[{1}] eval op {2} NOP", values.size (), token->first));
context.debug (format ("[{1}] eval op {2} NOP", values.size (), token.first));
}
// Binary operators.
else if (token->second == Lexer::Type::op)
else if (token.second == Lexer::Type::op)
{
if (values.size () < 2)
throw std::string (STRING_EVAL_NO_EVAL);
@ -300,46 +303,46 @@ void Eval::evaluatePostfixStack (
// Ordering these by anticipation frequency of use is a good idea.
Variant result;
if (token->first == "and") result = left && right;
else if (token->first == "or") result = left || right;
else if (token->first == "&&") result = left && right;
else if (token->first == "||") result = left || right;
else if (token->first == "<") result = left < right;
else if (token->first == "<=") result = left <= right;
else if (token->first == ">") result = left > right;
else if (token->first == ">=") result = left >= right;
else if (token->first == "==") result = left.operator== (right);
else if (token->first == "!==") result = left.operator!= (right);
else if (token->first == "=") result = left.operator_partial (right);
else if (token->first == "!=") result = left.operator_nopartial (right);
else if (token->first == "+") result = left + right;
else if (token->first == "-") result = left - right;
else if (token->first == "*") result = left * right;
else if (token->first == "/") result = left / right;
else if (token->first == "^") result = left ^ right;
else if (token->first == "%") result = left % right;
else if (token->first == "xor") result = left.operator_xor (right);
else if (token->first == "~") result = left.operator_match (right, contextTask);
else if (token->first == "!~") result = left.operator_nomatch (right, contextTask);
else if (token->first == "_hastag_") result = left.operator_hastag (right, contextTask);
else if (token->first == "_notag_") result = left.operator_notag (right, contextTask);
if (token.first == "and") result = left && right;
else if (token.first == "or") result = left || right;
else if (token.first == "&&") result = left && right;
else if (token.first == "||") result = left || right;
else if (token.first == "<") result = left < right;
else if (token.first == "<=") result = left <= right;
else if (token.first == ">") result = left > right;
else if (token.first == ">=") result = left >= right;
else if (token.first == "==") result = left.operator== (right);
else if (token.first == "!==") result = left.operator!= (right);
else if (token.first == "=") result = left.operator_partial (right);
else if (token.first == "!=") result = left.operator_nopartial (right);
else if (token.first == "+") result = left + right;
else if (token.first == "-") result = left - right;
else if (token.first == "*") result = left * right;
else if (token.first == "/") result = left / right;
else if (token.first == "^") result = left ^ right;
else if (token.first == "%") result = left % right;
else if (token.first == "xor") result = left.operator_xor (right);
else if (token.first == "~") result = left.operator_match (right, contextTask);
else if (token.first == "!~") result = left.operator_nomatch (right, contextTask);
else if (token.first == "_hastag_") result = left.operator_hastag (right, contextTask);
else if (token.first == "_notag_") result = left.operator_notag (right, contextTask);
else
throw format (STRING_EVAL_UNSUPPORTED, token->first);
throw format (STRING_EVAL_UNSUPPORTED, token.first);
values.push_back (result);
if (_debug)
context.debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", (std::string) left, token->first, (std::string) right, (std::string) result));
context.debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", (std::string) left, token.first, (std::string) right, (std::string) result));
}
// Literals and identifiers.
else
{
Variant v (token->first);
switch (token->second)
Variant v (token.first);
switch (token.second)
{
case Lexer::Type::number:
if (Lexer::isAllDigits (token->first))
if (Lexer::isAllDigits (token.first))
{
v.cast (Variant::type_integer);
if (_debug)
@ -362,13 +365,12 @@ void Eval::evaluatePostfixStack (
case Lexer::Type::identifier:
{
bool found = false;
std::vector <bool (*)(const std::string&, Variant&)>::const_iterator source;
for (source = _sources.begin (); source != _sources.end (); ++source)
for (auto source = _sources.begin (); source != _sources.end (); ++source)
{
if ((*source) (token->first, v))
if ((*source) (token.first, v))
{
if (_debug)
context.debug (format ("Eval identifier source '{1}' → ↑'{2}'", token->first, (std::string) v));
context.debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, (std::string) v));
found = true;
break;
}
@ -379,7 +381,7 @@ void Eval::evaluatePostfixStack (
{
v.cast (Variant::type_string);
if (_debug)
context.debug (format ("Eval identifier source failed '{1}'", token->first));
context.debug (format ("Eval identifier source failed '{1}'", token.first));
}
}
break;
@ -707,8 +709,7 @@ bool Eval::parsePrimitive (
else
{
bool found = false;
std::vector <bool (*)(const std::string&, Variant&)>::const_iterator source;
for (source = _sources.begin (); source != _sources.end (); ++source)
for (auto source = _sources.begin (); source != _sources.end (); ++source)
{
Variant v;
if ((*source) (infix[i].first, v))
@ -784,16 +785,15 @@ void Eval::infixToPostfix (
unsigned int precedence;
char associativity;
std::vector <std::pair <std::string, Lexer::Type>>::iterator token;
for (token = infix.begin (); token != infix.end (); ++token)
for (auto& token : infix)
{
if (token->second == Lexer::Type::op &&
token->first == "(")
if (token.second == Lexer::Type::op &&
token.first == "(")
{
op_stack.push_back (*token);
op_stack.push_back (token);
}
else if (token->second == Lexer::Type::op &&
token->first == ")")
else if (token.second == Lexer::Type::op &&
token.first == ")")
{
while (op_stack.size () &&
op_stack.back ().first != "(")
@ -807,8 +807,8 @@ void Eval::infixToPostfix (
else
throw std::string ("Mismatched parentheses in expression");
}
else if (token->second == Lexer::Type::op &&
identifyOperator (token->first, type, precedence, associativity))
else if (token.second == Lexer::Type::op &&
identifyOperator (token.first, type, precedence, associativity))
{
char type2;
unsigned int precedence2;
@ -822,11 +822,11 @@ void Eval::infixToPostfix (
op_stack.pop_back ();
}
op_stack.push_back (*token);
op_stack.push_back (token);
}
else
{
postfix.push_back (*token);
postfix.push_back (token);
}
}
@ -880,8 +880,7 @@ std::string Eval::dump (
color_map[Lexer::Type::duration] = Color ("rgb531 on gray6");
std::string output;
std::vector <std::pair <std::string, Lexer::Type>>::const_iterator i;
for (i = tokens.begin (); i != tokens.end (); ++i)
for (auto i = tokens.begin (); i != tokens.end (); ++i)
{
if (i != tokens.begin ())
output += ' ';

View file

@ -49,8 +49,8 @@ public:
void ambiguity (bool);
void debug (bool);
static void getOperators (std::vector <std::string>&);
static void getBinaryOperators (std::vector <std::string>&);
static std::vector <std::string> getOperators ();
static std::vector <std::string> getBinaryOperators ();
private:
void evaluatePostfixStack (const std::vector <std::pair <std::string, Lexer::Type>>&, Variant&) const;

View file

@ -244,9 +244,8 @@ void File::write (const std::vector <std::string>& lines)
if (_fh)
{
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
fputs (it->c_str (), _fh);
for (auto& line : lines)
fputs (line.c_str (), _fh);
}
}
@ -274,9 +273,8 @@ void File::append (const std::vector <std::string>& lines)
if (_fh)
{
fseek (_fh, 0, SEEK_END);
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
fputs (((*it) + "\n").c_str (), _fh);
for (auto& line : lines)
fputs ((line + "\n").c_str (), _fh);
}
}
@ -458,10 +456,9 @@ bool File::write (
std::ios_base::out | std::ios_base::trunc);
if (out.good ())
{
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
for (auto& line : lines)
{
out << *it;
out << line;
if (addNewlines)
out << "\n";
@ -499,10 +496,9 @@ bool File::append (
std::ios_base::out | std::ios_base::app);
if (out.good ())
{
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
for (auto& line : lines)
{
out << *it;
out << line;
if (addNewlines)
out << "\n";

View file

@ -89,16 +89,15 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
eval.compileExpression (filterExpr);
eval.debug (false);
std::vector <Task>::const_iterator task;
for (task = input.begin (); task != input.end (); ++task)
for (auto& task : input)
{
// Set up context for any DOM references.
contextTask = *task;
contextTask = task;
Variant var;
eval.evaluateCompiledExpression (var);
if (var.get_bool ())
output.push_back (*task);
output.push_back (task);
}
}
else
@ -123,7 +122,7 @@ void Filter::subset (std::vector <Task>& output, bool applyContext /* = true */)
if (filterExpr.length ())
{
context.timer_filter.stop ();
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
auto pending = context.tdb2.pending.get_tasks ();
context.timer_filter.start ();
_startCount = (int) pending.size ();
@ -139,58 +138,53 @@ void Filter::subset (std::vector <Task>& output, bool applyContext /* = true */)
eval.debug (false);
output.clear ();
std::vector <Task>::const_iterator task;
for (task = pending.begin (); task != pending.end (); ++task)
for (auto& task : pending)
{
// Set up context for any DOM references.
contextTask = *task;
contextTask = task;
Variant var;
eval.debug (context.config.getInteger ("debug.parser") >= 2 ? true : false);
eval.evaluateCompiledExpression (var);
eval.debug (false);
if (var.get_bool ())
output.push_back (*task);
output.push_back (task);
}
shortcut = pendingOnly ();
if (! shortcut)
{
context.timer_filter.stop ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks ();
auto completed = context.tdb2.completed.get_tasks ();
context.timer_filter.start ();
_startCount += (int) completed.size ();
for (task = completed.begin (); task != completed.end (); ++task)
for (auto& task : completed)
{
// Set up context for any DOM references.
contextTask = *task;
contextTask = task;
Variant var;
eval.debug (context.config.getInteger ("debug.parser") >= 2 ? true : false);
eval.evaluateCompiledExpression (var);
eval.debug (false);
if (var.get_bool ())
output.push_back (*task);
output.push_back (task);
}
}
}
else
{
safety ();
context.timer_filter.stop ();
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks ();
for (auto& task : context.tdb2.pending.get_tasks ())
output.push_back (task);
for (auto& task : context.tdb2.completed.get_tasks ())
output.push_back (task);
context.timer_filter.start ();
std::vector <Task>::const_iterator task;
for (task = pending.begin (); task != pending.end (); ++task)
output.push_back (*task);
for (task = completed.begin (); task != completed.end (); ++task)
output.push_back (*task);
}
_endCount = (int) output.size ();
@ -218,19 +212,18 @@ bool Filter::pendingOnly ()
int countXor = 0;
int countNot = 0;
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
for (auto& a : context.cli._args)
{
if (a->hasTag ("FILTER"))
if (a.hasTag ("FILTER"))
{
if (a->hasTag ("ID")) ++countId;
if (a->hasTag ("OP") && a->attribute ("raw") == "or") ++countOr;
if (a->hasTag ("OP") && a->attribute ("raw") == "xor") ++countXor;
if (a->hasTag ("OP") && a->attribute ("raw") == "not") ++countNot;
if (a->hasTag ("ATTRIBUTE") && a->attribute ("name") == "status") ++countStatus;
if ( a->attribute ("raw") == "pending") ++countPending;
if ( a->attribute ("raw") == "waiting") ++countWaiting;
if ( a->attribute ("raw") == "recurring") ++countRecurring;
if (a.hasTag ("ID")) ++countId;
if (a.hasTag ("OP") && a.attribute ("raw") == "or") ++countOr;
if (a.hasTag ("OP") && a.attribute ("raw") == "xor") ++countXor;
if (a.hasTag ("OP") && a.attribute ("raw") == "not") ++countNot;
if (a.hasTag ("ATTRIBUTE") && a.attribute ("name") == "status") ++countStatus;
if ( a.attribute ("raw") == "pending") ++countPending;
if ( a.attribute ("raw") == "waiting") ++countWaiting;
if ( a.attribute ("raw") == "recurring") ++countRecurring;
}
}
@ -258,12 +251,11 @@ bool Filter::pendingOnly ()
// all tasks to be modified. This is usually not intended.
void Filter::safety ()
{
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
for (auto& a : context.cli._args)
{
if (a->hasTag ("CMD"))
if (a.hasTag ("CMD"))
{
if (a->hasTag ("WRITECMD"))
if (a.hasTag ("WRITECMD"))
{
if (context.cli.getFilter () == "")
{

View file

@ -73,18 +73,17 @@ void Hooks::initialize ()
if (_debug >= 1)
{
std::vector <std::string>::iterator i;
for (i = _scripts.begin (); i != _scripts.end (); ++i)
for (auto& i : _scripts)
{
Path p (*i);
Path p (i);
std::string name = p.name ();
if (name.substr (0, 6) == "on-add" ||
name.substr (0, 9) == "on-modify" ||
name.substr (0, 9) == "on-launch" ||
name.substr (0, 7) == "on-exit")
context.debug ("Found hook script " + *i);
context.debug ("Found hook script " + i);
else
context.debug ("Found misnamed hook script " + *i);
context.debug ("Found misnamed hook script " + i);
}
}
}
@ -124,12 +123,11 @@ void Hooks::onLaunch ()
std::vector <std::string> matchingScripts = scripts ("on-launch");
if (matchingScripts.size ())
{
std::vector <std::string>::iterator script;
for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script)
for (auto& script : matchingScripts)
{
std::vector <std::string> input;
std::vector <std::string> output;
int status = callHookScript (*script, input, output);
int status = callHookScript (script, input, output);
std::vector <std::string> outputJSON;
std::vector <std::string> outputFeedback;
@ -139,17 +137,14 @@ void Hooks::onLaunch ()
if (status == 0)
{
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.footnote (*message);
for (auto& message : outputFeedback)
context.footnote (message);
}
else
{
assertFeedback (outputFeedback);
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.error (*message);
for (auto& message : outputFeedback)
context.error (message);
throw 0; // This is how hooks silently terminate processing.
}
@ -187,16 +182,14 @@ void Hooks::onExit ()
// Convert to a vector of strings.
std::vector <std::string> input;
std::vector <Task>::const_iterator t;
for (t = tasks.begin (); t != tasks.end (); ++t)
input.push_back (t->composeJSON ());
for (auto& t : tasks)
input.push_back (t.composeJSON ());
// Call the hook scripts, with the invariant input.
std::vector <std::string>::iterator script;
for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script)
for (auto& script : matchingScripts)
{
std::vector <std::string> output;
int status = callHookScript (*script, input, output);
int status = callHookScript (script, input, output);
std::vector <std::string> outputJSON;
std::vector <std::string> outputFeedback;
@ -206,17 +199,14 @@ void Hooks::onExit ()
if (status == 0)
{
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.footnote (*message);
for (auto& message : outputFeedback)
context.footnote (message);
}
else
{
assertFeedback (outputFeedback);
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.error (*message);
for (auto& message : outputFeedback)
context.error (message);
throw 0; // This is how hooks silently terminate processing.
}
@ -253,11 +243,10 @@ void Hooks::onAdd (Task& task)
input.push_back (task.composeJSON ());
// Call the hook scripts.
std::vector <std::string>::iterator script;
for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script)
for (auto& script : matchingScripts)
{
std::vector <std::string> output;
int status = callHookScript (*script, input, output);
int status = callHookScript (script, input, output);
std::vector <std::string> outputJSON;
std::vector <std::string> outputFeedback;
@ -272,17 +261,14 @@ void Hooks::onAdd (Task& task)
// Propagate forward to the next script.
input[0] = outputJSON[0];
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.footnote (*message);
for (auto& message : outputFeedback)
context.footnote (message);
}
else
{
assertFeedback (outputFeedback);
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.error (*message);
for (auto& message : outputFeedback)
context.error (message);
throw 0; // This is how hooks silently terminate processing.
}
@ -324,11 +310,10 @@ void Hooks::onModify (const Task& before, Task& after)
input.push_back (after.composeJSON ()); // [line 1] modified
// Call the hook scripts.
std::vector <std::string>::iterator script;
for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script)
for (auto& script : matchingScripts)
{
std::vector <std::string> output;
int status = callHookScript (*script, input, output);
int status = callHookScript (script, input, output);
std::vector <std::string> outputJSON;
std::vector <std::string> outputFeedback;
@ -343,17 +328,14 @@ void Hooks::onModify (const Task& before, Task& after)
// Propagate accepted changes forward to the next script.
input[1] = outputJSON[0];
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.footnote (*message);
for (auto& message : outputFeedback)
context.footnote (message);
}
else
{
assertFeedback (outputFeedback);
std::vector <std::string>::iterator message;
for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message)
context.error (*message);
for (auto& message : outputFeedback)
context.error (message);
throw 0; // This is how hooks silently terminate processing.
}
@ -375,14 +357,13 @@ std::vector <std::string> Hooks::list ()
std::vector <std::string> Hooks::scripts (const std::string& event)
{
std::vector <std::string> matching;
std::vector <std::string>::iterator i;
for (i = _scripts.begin (); i != _scripts.end (); ++i)
for (auto& i : _scripts)
{
if (i->find ("/" + event) != std::string::npos)
if (i.find ("/" + event) != std::string::npos)
{
File script (*i);
File script (i);
if (script.executable ())
matching.push_back (*i);
matching.push_back (i);
}
}
@ -395,13 +376,12 @@ void Hooks::separateOutput (
std::vector <std::string>& json,
std::vector <std::string>& feedback) const
{
std::vector <std::string>::const_iterator i;
for (i = output.begin (); i != output.end (); ++i)
for (auto& i : output)
{
if (isJSON (*i))
json.push_back (*i);
if (isJSON (i))
json.push_back (i);
else
feedback.push_back (*i);
feedback.push_back (i);
}
}
@ -416,12 +396,11 @@ bool Hooks::isJSON (const std::string& input) const
////////////////////////////////////////////////////////////////////////////////
void Hooks::assertValidJSON (const std::vector <std::string>& input) const
{
std::vector <std::string>::const_iterator i;
for (i = input.begin (); i != input.end (); i++)
for (auto& i : input)
{
if (i->length () < 3 ||
(*i)[0] != '{' ||
(*i)[i->length () - 1] != '}')
if (i.length () < 3 ||
i[0] != '{' ||
i[i.length () - 1] != '}')
{
context.error (STRING_HOOK_ERROR_OBJECT);
throw 0;
@ -429,7 +408,7 @@ void Hooks::assertValidJSON (const std::vector <std::string>& input) const
try
{
json::value* root = json::parse (*i);
json::value* root = json::parse (i);
if (root->type () != json::j_object)
{
context.error (STRING_HOOK_ERROR_OBJECT);
@ -451,7 +430,7 @@ void Hooks::assertValidJSON (const std::vector <std::string>& input) const
catch (const std::string& e)
{
context.error (format (STRING_HOOK_ERROR_SYNTAX, *i));
context.error (format (STRING_HOOK_ERROR_SYNTAX, i));
if (_debug)
context.error (STRING_HOOK_ERROR_JSON + e);
throw 0;
@ -459,7 +438,7 @@ void Hooks::assertValidJSON (const std::vector <std::string>& input) const
catch (...)
{
context.error (STRING_HOOK_ERROR_NOPARSE + *i);
context.error (STRING_HOOK_ERROR_NOPARSE + i);
throw 0;
}
}
@ -480,13 +459,12 @@ void Hooks::assertSameTask (const std::vector <std::string>& input, const Task&
{
std::string uuid = task.get ("uuid");
std::vector <std::string>::const_iterator i;
for (i = input.begin (); i != input.end (); i++)
for (auto& i : input)
{
json::object* root_obj = (json::object*)json::parse (*i);
json::object* root_obj = (json::object*)json::parse (i);
// If there is no UUID at all.
json_object_iter u = root_obj->_data.find ("uuid");
auto u = root_obj->_data.find ("uuid");
if (u == root_obj->_data.end () ||
u->second->type () != json::j_string)
{
@ -508,9 +486,8 @@ void Hooks::assertSameTask (const std::vector <std::string>& input, const Task&
void Hooks::assertFeedback (const std::vector <std::string>& input) const
{
bool foundSomething = false;
std::vector <std::string>::const_iterator i;
for (i = input.begin (); i != input.end (); ++i)
if (nontrivial (*i))
for (auto& i : input)
if (nontrivial (i))
foundSomething = true;
if (! foundSomething)
@ -559,22 +536,20 @@ int Hooks::callHookScript (
if (_debug >= 2)
{
context.debug ("Hook: input");
std::vector <std::string>::const_iterator i;
for (i = input.begin (); i != input.end (); ++i)
context.debug (" " + *i);
for (auto& i : input)
context.debug (" " + i);
}
std::string inputStr;
std::vector <std::string>::const_iterator i;
for (i = input.begin (); i != input.end (); ++i)
inputStr += *i + "\n";
for (auto& i : input)
inputStr += i + "\n";
std::vector <std::string> args;
buildHookScriptArgs (args);
if (_debug >= 2)
{
context.debug ("Hooks: args");
for (auto arg: args)
for (auto& arg: args)
context.debug (" " + arg);
}
@ -596,10 +571,9 @@ int Hooks::callHookScript (
if (_debug >= 2)
{
context.debug ("Hook: output");
std::vector <std::string>::iterator i;
for (i = output.begin (); i != output.end (); ++i)
if (*i != "")
context.debug (" " + *i);
for (auto& i : output)
if (i != "")
context.debug (" " + i);
context.debug (format ("Hook: Completed with status {1}", status));
context.debug (" "); // Blank line

View file

@ -162,9 +162,8 @@ std::string json::literal::dump ()
////////////////////////////////////////////////////////////////////////////////
json::array::~array ()
{
std::vector <json::value*>::iterator i;
for (i = _data.begin (); i != _data.end (); ++i)
delete *i;
for (auto& i : _data)
delete i;
}
////////////////////////////////////////////////////////////////////////////////
@ -227,10 +226,7 @@ std::string json::array::dump ()
std::string output;
output += "[";
std::vector <json::value*>::iterator i;
for (i = _data.begin ();
i != _data.end ();
++i)
for (auto i = _data.begin (); i != _data.end (); ++i)
{
if (i != _data.begin ())
output += ",";
@ -245,9 +241,8 @@ std::string json::array::dump ()
////////////////////////////////////////////////////////////////////////////////
json::object::~object ()
{
std::map <std::string, json::value*>::iterator i;
for (i = _data.begin (); i != _data.end (); ++i)
delete i->second;
for (auto& i : _data)
delete i.second;
}
////////////////////////////////////////////////////////////////////////////////
@ -341,8 +336,7 @@ std::string json::object::dump ()
std::string output;
output += "{";
std::map <std::string, json::value*>::iterator i;
for (i = _data.begin (); i != _data.end (); ++i)
for (auto i = _data.begin (); i != _data.end (); ++i)
{
if (i != _data.begin ())
output += ",";
@ -384,9 +378,9 @@ std::string json::encode (const std::string& input)
{
std::string output;
for (std::string::size_type i = 0; i < input.length (); ++i)
for (auto& i : input)
{
switch (input[i])
switch (i)
{
// Simple translations.
case '"': output += "\\\""; break;
@ -399,7 +393,7 @@ std::string json::encode (const std::string& input)
case '\t': output += "\\t"; break;
// Default NOP.
default: output += input[i]; break;
default: output += i; break;
}
}

View file

@ -131,8 +131,5 @@ namespace json
std::string decode (const std::string&);
}
typedef std::vector <json::value*>::iterator json_array_iter;
typedef std::map <std::string, json::value*>::iterator json_object_iter;
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -102,8 +102,7 @@ void Msg::setPayload (const std::string& payload)
////////////////////////////////////////////////////////////////////////////////
std::string Msg::get (const std::string& name) const
{
std::map <std::string, std::string>::const_iterator i;
i = _header.find (name);
auto i = _header.find (name);
if (i != _header.end ())
return i->second;
@ -119,9 +118,8 @@ std::string Msg::getPayload () const
////////////////////////////////////////////////////////////////////////////////
void Msg::all (std::vector <std::string>& names) const
{
std::map <std::string, std::string>::const_iterator i;
for (i = _header.begin (); i != _header.end (); ++i)
names.push_back (i->first);
for (auto& i : _header)
names.push_back (i.first);
}
////////////////////////////////////////////////////////////////////////////////
@ -129,9 +127,8 @@ std::string Msg::serialize () const
{
std::string output;
std::map <std::string, std::string>::const_iterator i;
for (i = _header.begin (); i != _header.end (); ++i)
output += i->first + ": " + i->second + "\n";
for (auto& i : _header)
output += i.first + ": " + i.second + "\n";
output += "\n" + _payload + "\n";
@ -144,21 +141,20 @@ bool Msg::parse (const std::string& input)
_header.clear ();
_payload = "";
std::string::size_type separator = input.find ("\n\n");
auto separator = input.find ("\n\n");
if (separator == std::string::npos)
throw std::string ("ERROR: Malformed message");
// Parse header.
std::vector <std::string> lines;
split (lines, input.substr (0, separator), '\n');
std::vector <std::string>::iterator i;
for (i = lines.begin (); i != lines.end (); ++i)
for (auto& i : lines)
{
std::string::size_type delimiter = i->find (':');
std::string::size_type delimiter = i.find (':');
if (delimiter == std::string::npos)
throw std::string ("ERROR: Malformed message header '") + *i + "'";
throw std::string ("ERROR: Malformed message header '") + i + "'";
_header[trim (i->substr (0, delimiter))] = trim (i->substr (delimiter + 1));
_header[trim (i.substr (0, delimiter))] = trim (i.substr (delimiter + 1));
}
// Parse payload.

View file

@ -982,12 +982,11 @@ bool Nibbler::getOneOf (
const std::vector <std::string>& options,
std::string& found)
{
std::vector <std::string>::const_iterator option;
for (option = options.begin (); option != options.end (); ++option)
for (auto& option : options)
{
if (getLiteral (*option))
if (getLiteral (option))
{
found = *option;
found = option;
return true;
}
}

View file

@ -121,12 +121,11 @@ bool TF2::get (const std::string& uuid, Task& task)
if (! _loaded_tasks)
load_tasks ();
std::vector <Task>::iterator i;
for (i = _tasks.begin (); i != _tasks.end (); ++i)
for (auto& i : _tasks)
{
if (i->get ("uuid") == uuid)
if (i.get ("uuid") == uuid)
{
task = *i;
task = i;
return true;
}
}
@ -140,9 +139,8 @@ bool TF2::has (const std::string& uuid)
if (! _loaded_tasks)
load_tasks ();
std::vector <Task>::iterator i;
for (i = _tasks.begin (); i != _tasks.end (); ++i)
if (i->get ("uuid") == uuid)
for (auto& i : _tasks)
if (i.get ("uuid") == uuid)
return true;
return false;
@ -174,12 +172,11 @@ bool TF2::modify_task (const Task& task)
{
// Modify in-place.
std::string uuid = task.get ("uuid");
std::vector <Task>::iterator i;
for (i = _tasks.begin (); i != _tasks.end (); ++i)
for (auto& i : _tasks)
{
if (i->get ("uuid") == uuid)
if (i.get ("uuid") == uuid)
{
*i = task;
i = task;
_modified_tasks.push_back (task);
_dirty = true;
@ -229,24 +226,14 @@ void TF2::commit ()
_file.lock ();
// Write out all the added tasks.
std::vector <Task>::iterator task;
for (task = _added_tasks.begin ();
task != _added_tasks.end ();
++task)
{
_file.append (task->composeF4 () + "\n");
}
for (auto& task : _added_tasks)
_file.append (task.composeF4 () + "\n");
_added_tasks.clear ();
// Write out all the added lines.
std::vector <std::string>::iterator line;
for (line = _added_lines.begin ();
line != _added_lines.end ();
++line)
{
_file.append (*line);
}
for (auto& line : _added_lines)
_file.append (line);
_added_lines.clear ();
_file.close ();
@ -264,22 +251,12 @@ void TF2::commit ()
_file.truncate ();
// Only write out _tasks, because any deltas have already been applied.
std::vector <Task>::iterator task;
for (task = _tasks.begin ();
task != _tasks.end ();
++task)
{
_file.append (task->composeF4 () + "\n");
}
for (auto& task : _tasks)
_file.append (task.composeF4 () + "\n");
// Write out all the added lines.
std::vector <std::string>::iterator line;
for (line = _added_lines.begin ();
line != _added_lines.end ();
++line)
{
_file.append (*line);
}
for (auto& line : _added_lines)
_file.append (line);
_added_lines.clear ();
_file.close ();
@ -299,9 +276,8 @@ void TF2::load_tasks ()
load_lines ();
// Apply previously added lines.
std::vector <std::string>::iterator i;
for (i = _added_lines.begin (); i != _added_lines.end (); ++i)
_lines.push_back (*i);
for (auto& line : _added_lines)
_lines.push_back (line);
}
int line_number = 0;
@ -310,11 +286,10 @@ void TF2::load_tasks ()
// Reduce unnecessary allocations/copies.
_tasks.reserve (_lines.size ());
std::vector <std::string>::iterator i;
for (i = _lines.begin (); i != _lines.end (); ++i)
for (auto& line : _lines)
{
++line_number;
Task task (*i);
Task task (line);
// Some tasks get an ID.
if (_has_ids)
@ -374,13 +349,12 @@ std::string TF2::uuid (int id)
load_tasks ();
// Apply previously added tasks.
std::vector <Task>::iterator i;
for (i = _added_tasks.begin (); i != _added_tasks.end (); ++i)
_tasks.push_back (*i);
for (auto& task : _added_tasks)
_tasks.push_back (task);
}
std::map <int, std::string>::const_iterator i;
if ((i = _I2U.find (id)) != _I2U.end ())
auto i = _I2U.find (id);
if (i != _I2U.end ())
return i->second;
return "";
@ -394,13 +368,12 @@ int TF2::id (const std::string& uuid)
load_tasks ();
// Apply previously added tasks.
std::vector <Task>::iterator i;
for (i = _added_tasks.begin (); i != _added_tasks.end (); ++i)
_tasks.push_back (*i);
for (auto& task : _added_tasks)
_tasks.push_back (task);
}
std::map <std::string, int>::const_iterator i;
if ((i = _U2I.find (uuid)) != _U2I.end ())
auto i = _U2I.find (uuid);
if (i != _U2I.end ())
return i->second;
return 0;
@ -448,38 +421,32 @@ void TF2::clear ()
void TF2::dependency_scan ()
{
// Iterate and modify TDB2 in-place. Don't do this at home.
std::vector <Task>::iterator left;
for (left = _tasks.begin ();
left != _tasks.end ();
++left)
for (auto& left : _tasks)
{
if (left->has ("depends"))
if (left.has ("depends"))
{
std::vector <std::string> deps;
left->getDependencies (deps);
left.getDependencies (deps);
std::vector <std::string>::iterator d;
for (d = deps.begin (); d != deps.end (); ++d)
for (auto& dep : deps)
{
std::vector <Task>::iterator right;
for (right = _tasks.begin ();
right != _tasks.end ();
++right)
for (auto& right : _tasks)
{
if (right->get ("uuid") == *d)
if (right.get ("uuid") == dep)
{
// GC hasn't run yet, check both tasks for their current status
Task::status lstatus = left->getStatus ();
Task::status rstatus = right->getStatus ();
Task::status lstatus = left.getStatus ();
Task::status rstatus = right.getStatus ();
if (lstatus != Task::completed &&
lstatus != Task::deleted &&
rstatus != Task::completed &&
rstatus != Task::deleted)
{
left->is_blocked = true;
right->is_blocking = true;
left.is_blocked = true;
right.is_blocking = true;
}
// Only want to break out of the "right" loop.
break;
}
}
@ -701,18 +668,17 @@ void TDB2::commit ()
void TDB2::gather_changes ()
{
_changes.clear ();
std::vector <Task>::iterator i;
for (i = pending._added_tasks.begin (); i != pending._added_tasks.end (); ++i)
_changes.push_back (*i);
for (auto& task : pending._added_tasks)
_changes.push_back (task);
for (i = pending._modified_tasks.begin (); i != pending._modified_tasks.end (); ++i)
_changes.push_back (*i);
for (auto& task : pending._modified_tasks)
_changes.push_back (task);
for (i = completed._added_tasks.begin (); i != completed._added_tasks.end (); ++i)
_changes.push_back (*i);
for (auto& task : completed._added_tasks)
_changes.push_back (task);
for (i = completed._modified_tasks.begin (); i != completed._modified_tasks.end (); ++i)
_changes.push_back (*i);
for (auto& task : completed._modified_tasks)
_changes.push_back (task);
}
////////////////////////////////////////////////////////////////////////////////
@ -842,8 +808,7 @@ void TDB2::revert_pending (
std::string uuid_att = "uuid:\"" + uuid + "\"";
// is 'current' in pending?
std::vector <std::string>::iterator task;
for (task = p.begin (); task != p.end (); ++task)
for (auto task = p.begin (); task != p.end (); ++task)
{
if (task->find (uuid_att) != std::string::npos)
{
@ -877,8 +842,7 @@ void TDB2::revert_completed (
std::string uuid_att = "uuid:\"" + uuid + "\"";
// is 'current' in completed?
std::vector <std::string>::iterator task;
for (task = c.begin (); task != c.end (); ++task)
for (auto task = c.begin (); task != c.end (); ++task)
{
if (task->find (uuid_att) != std::string::npos)
{
@ -927,8 +891,7 @@ void TDB2::revert_backlog (
std::string uuid_att = "\"uuid\":\"" + uuid + "\"";
bool found = false;
std::vector <std::string>::reverse_iterator task;
for (task = b.rbegin (); task != b.rend (); ++task)
for (auto task = b.rbegin (); task != b.rend (); ++task)
{
if (task->find (uuid_att) != std::string::npos)
{
@ -995,59 +958,56 @@ void TDB2::show_diff (
Task before (prior);
std::vector <std::string> beforeAtts;
std::map <std::string, std::string>::iterator att;
for (att = before.begin (); att != before.end (); ++att)
beforeAtts.push_back (att->first);
for (auto& att : before)
beforeAtts.push_back (att.first);
std::vector <std::string> afterAtts;
for (att = after.begin (); att != after.end (); ++att)
afterAtts.push_back (att->first);
for (auto& att : after)
afterAtts.push_back (att.first);
std::vector <std::string> beforeOnly;
std::vector <std::string> afterOnly;
listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly);
int row;
std::vector <std::string>::iterator name;
for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name)
for (auto& name : beforeOnly)
{
row = view.addRow ();
view.set (row, 0, *name);
view.set (row, 1, renderAttribute (*name, before.get (*name)), color_red);
view.set (row, 0, name);
view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
}
for (att = before.begin (); att != before.end (); ++att)
for (auto& att : before)
{
std::string priorValue = before.get (att->first);
std::string currentValue = after.get (att->first);
std::string priorValue = before.get (att.first);
std::string currentValue = after.get (att.first);
if (currentValue != "")
{
row = view.addRow ();
view.set (row, 0, att->first);
view.set (row, 1, renderAttribute (att->first, priorValue),
view.set (row, 0, att.first);
view.set (row, 1, renderAttribute (att.first, priorValue),
(priorValue != currentValue ? color_red : Color ()));
view.set (row, 2, renderAttribute (att->first, currentValue),
view.set (row, 2, renderAttribute (att.first, currentValue),
(priorValue != currentValue ? color_green : Color ()));
}
}
for (name = afterOnly.begin (); name != afterOnly.end (); ++name)
for (auto& name : afterOnly)
{
row = view.addRow ();
view.set (row, 0, *name);
view.set (row, 2, renderAttribute (*name, after.get (*name)), color_green);
view.set (row, 0, name);
view.set (row, 2, renderAttribute (name, after.get (name)), color_green);
}
}
else
{
int row;
std::map <std::string, std::string>::iterator att;
for (att = after.begin (); att != after.end (); ++att)
for (auto& att : after)
{
row = view.addRow ();
view.set (row, 0, att->first);
view.set (row, 2, renderAttribute (att->first, after.get (att->first)), color_green);
view.set (row, 0, att.first);
view.set (row, 2, renderAttribute (att.first, after.get (att.first)), color_green);
}
}
@ -1101,14 +1061,13 @@ void TDB2::show_diff (
std::vector <std::string> all = context.getColumns ();
// Now factor in the annotation attributes.
Task::iterator it;
for (it = before.begin (); it != before.end (); ++it)
if (it->first.substr (0, 11) == "annotation_")
all.push_back (it->first);
for (auto& it : before)
if (it.first.substr (0, 11) == "annotation_")
all.push_back (it.first);
for (it = after.begin (); it != after.end (); ++it)
if (it->first.substr (0, 11) == "annotation_")
all.push_back (it->first);
for (auto& it : after)
if (it.first.substr (0, 11) == "annotation_")
all.push_back (it.first);
// Now render all the attributes.
std::sort (all.begin (), all.end ());
@ -1116,19 +1075,18 @@ void TDB2::show_diff (
std::string before_att;
std::string after_att;
std::string last_att;
std::vector <std::string>::iterator a;
for (a = all.begin (); a != all.end (); ++a)
for (auto& a : all)
{
if (*a != last_att) // Skip duplicates.
if (a != last_att) // Skip duplicates.
{
last_att = *a;
last_att = a;
before_att = before.get (*a);
after_att = after.get (*a);
before_att = before.get (a);
after_att = after.get (a);
// Don't report different uuid.
// Show nothing if values are the unchanged.
if (*a == "uuid" ||
if (a == "uuid" ||
before_att == after_att)
{
// Show nothing - no point displaying that which did not change.
@ -1142,21 +1100,21 @@ void TDB2::show_diff (
else if (before_att != "" && after_att == "")
{
row = view.addRow ();
view.set (row, 0, "-" + *a + ":", color_red);
view.set (row, 0, "-" + a + ":", color_red);
view.set (row, 1, before_att, color_red);
row = view.addRow ();
view.set (row, 0, "+" + *a + ":", color_green);
view.set (row, 0, "+" + a + ":", color_green);
}
// Attribute added.
else if (before_att == "" && after_att != "")
{
row = view.addRow ();
view.set (row, 0, "-" + *a + ":", color_red);
view.set (row, 0, "-" + a + ":", color_red);
row = view.addRow ();
view.set (row, 0, "+" + *a + ":", color_green);
view.set (row, 0, "+" + a + ":", color_green);
view.set (row, 1, after_att, color_green);
}
@ -1164,11 +1122,11 @@ void TDB2::show_diff (
else
{
row = view.addRow ();
view.set (row, 0, "-" + *a + ":", color_red);
view.set (row, 0, "-" + a + ":", color_red);
view.set (row, 1, before_att, color_red);
row = view.addRow ();
view.set (row, 0, "+" + *a + ":", color_green);
view.set (row, 0, "+" + a + ":", color_green);
view.set (row, 1, after_att, color_green);
}
}
@ -1198,10 +1156,10 @@ int TDB2::gc ()
// Allowed as an override, but not recommended.
if (context.config.getBoolean ("gc"))
{
std::vector <Task> pending_tasks = pending.get_tasks ();
auto pending_tasks = pending.get_tasks ();
// TODO Thread.
std::vector <Task> completed_tasks = completed.get_tasks ();
auto completed_tasks = completed.get_tasks ();
// TODO Assume pending < completed, therefore there is room here to process
// data before joining with the completed.data thread.
@ -1218,32 +1176,29 @@ int TDB2::gc ()
// completed, or need to be 'woken'.
Date now;
std::string status;
std::vector <Task>::iterator task;
for (task = pending_tasks.begin ();
task != pending_tasks.end ();
++task)
for (auto& task : pending_tasks)
{
status = task->get ("status");
status = task.get ("status");
if (status == "pending" ||
status == "recurring")
{
pending_tasks_after.push_back (*task);
pending_tasks_after.push_back (task);
}
else if (status == "waiting")
{
Date wait (task->get_date ("wait"));
Date wait (task.get_date ("wait"));
if (wait < now)
{
task->set ("status", "pending");
task->remove ("wait");
task.set ("status", "pending");
task.remove ("wait");
pending_changes = true;
}
pending_tasks_after.push_back (*task);
pending_tasks_after.push_back (task);
}
else
{
completed_tasks_after.push_back (*task);
completed_tasks_after.push_back (task);
pending_changes = true;
completed_changes = true;
}
@ -1256,35 +1211,33 @@ int TDB2::gc ()
// Scan all completed tasks, looking for any that need to be relocated to
// pending.
for (task = completed_tasks.begin ();
task != completed_tasks.end ();
++task)
for (auto& task : completed_tasks)
{
status = task->get ("status");
status = task.get ("status");
if (status == "pending" ||
status == "recurring")
{
pending_tasks_after.push_back (*task);
pending_tasks_after.push_back (task);
pending_changes = true;
completed_changes = true;
}
else if (status == "waiting")
{
Date wait (task->get_date ("wait"));
Date wait (task.get_date ("wait"));
if (wait < now)
{
task->set ("status", "pending");
task->remove ("wait");
pending_tasks_after.push_back (*task);
task.set ("status", "pending");
task.remove ("wait");
pending_tasks_after.push_back (task);
pending_changes = true;
completed_changes = true;
}
pending_tasks_after.push_back (*task);
pending_tasks_after.push_back (task);
}
else
{
completed_tasks_after.push_back (*task);
completed_tasks_after.push_back (task);
}
}
@ -1296,12 +1249,8 @@ int TDB2::gc ()
pending._loaded_tasks = true;
_id = 1;
for (task = pending._tasks.begin ();
task != pending._tasks.end ();
++task)
{
task->id = _id++;
}
for (auto& task : pending._tasks)
task.id = _id++;
// Note: deliberately no commit.
}
@ -1347,9 +1296,8 @@ const std::vector <Task> TDB2::all_tasks ()
completed._added_tasks.size ());
extra = completed.get_tasks ();
std::vector <Task>::iterator task;
for (task = extra.begin (); task != extra.end (); ++task)
all.push_back (*task);
for (auto& task : extra)
all.push_back (task);
return all;
}
@ -1390,21 +1338,20 @@ const std::vector <Task> TDB2::siblings (Task& task)
if (! pending._loaded_tasks)
pending.load_tasks ();
std::vector <Task>::iterator i;
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
for (auto& i : pending._tasks)
{
// Do not include self in results.
if (i->id != task.id)
if (i.id != task.id)
{
// Do not include completed or deleted tasks.
if (i->getStatus () != Task::completed &&
i->getStatus () != Task::deleted)
if (i.getStatus () != Task::completed &&
i.getStatus () != Task::deleted)
{
// If task has the same parent, it is a sibling.
if (i->has ("parent") &&
i->get ("parent") == parent)
if (i.has ("parent") &&
i.get ("parent") == parent)
{
results.push_back (*i);
results.push_back (i);
}
}
}
@ -1424,19 +1371,18 @@ const std::vector <Task> TDB2::children (Task& task)
if (! pending._loaded_tasks)
pending.load_tasks ();
std::vector <Task>::iterator i;
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
for (auto& i : pending._tasks)
{
// Do not include self in results.
if (i->id != task.id)
if (i.id != task.id)
{
// Do not include completed or deleted tasks.
if (i->getStatus () != Task::completed &&
i->getStatus () != Task::deleted)
if (i.getStatus () != Task::completed &&
i.getStatus () != Task::deleted)
{
// If task has the same parent, it is a sibling.
if (i->get ("parent") == parent)
results.push_back (*i);
if (i.get ("parent") == parent)
results.push_back (i);
}
}
}

View file

@ -130,10 +130,9 @@ bool Task::operator== (const Task& other)
if (size () != other.size ())
return false;
Task::iterator i;
for (i = this->begin (); i != this->end (); ++i)
if (i->first != "uuid" &&
i->second != other.get (i->first))
for (auto& i : *this)
if (i.first != "uuid" &&
i.second != other.get (i.first))
return false;
return true;
@ -194,7 +193,7 @@ void Task::setAsNow (const std::string& att)
////////////////////////////////////////////////////////////////////////////////
bool Task::has (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return true;
@ -205,8 +204,7 @@ bool Task::has (const std::string& name) const
std::vector <std::string> Task::all ()
{
std::vector <std::string> all;
Task::iterator i;
for (i = this->begin (); i != this->end (); ++i)
for (auto i = this->begin (); i != this->end (); ++i)
all.push_back (i->first);
return all;
@ -215,7 +213,7 @@ std::vector <std::string> Task::all ()
////////////////////////////////////////////////////////////////////////////////
const std::string Task::get (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return i->second;
@ -225,7 +223,7 @@ const std::string Task::get (const std::string& name) const
////////////////////////////////////////////////////////////////////////////////
const std::string& Task::get_ref (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return i->second;
@ -235,7 +233,7 @@ const std::string& Task::get_ref (const std::string& name) const
////////////////////////////////////////////////////////////////////////////////
int Task::get_int (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return strtol (i->second.c_str (), NULL, 10);
@ -245,7 +243,7 @@ int Task::get_int (const std::string& name) const
////////////////////////////////////////////////////////////////////////////////
unsigned long Task::get_ulong (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return strtoul (i->second.c_str (), NULL, 10);
@ -255,7 +253,7 @@ unsigned long Task::get_ulong (const std::string& name) const
////////////////////////////////////////////////////////////////////////////////
float Task::get_float (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return strtof (i->second.c_str (), NULL);
@ -265,7 +263,7 @@ float Task::get_float (const std::string& name) const
////////////////////////////////////////////////////////////////////////////////
time_t Task::get_date (const std::string& name) const
{
Task::const_iterator i = this->find (name);
auto i = this->find (name);
if (i != this->end ())
return (time_t) strtoul (i->second.c_str (), NULL, 10);
@ -291,8 +289,8 @@ void Task::set (const std::string& name, int value)
////////////////////////////////////////////////////////////////////////////////
void Task::remove (const std::string& name)
{
Task::iterator it;
if ((it = this->find (name)) != this->end ())
auto it = this->find (name);
if (it != this->end ())
{
this->erase (it);
recalc_urgency = true;
@ -606,66 +604,60 @@ void Task::parseJSON (const std::string& line)
json::object* root_obj = (json::object*)root;
// For each object element...
json_object_iter i;
for (i = root_obj->_data.begin ();
i != root_obj->_data.end ();
++i)
for (auto& i : root_obj->_data)
{
// If the attribute is a recognized column.
std::string type = Task::attributes[i->first];
std::string type = Task::attributes[i.first];
if (type != "")
{
// Any specified id is ignored.
if (i->first == "id")
if (i.first == "id")
;
// Urgency, if present, is ignored.
else if (i->first == "urgency")
else if (i.first == "urgency")
;
// TW-1274 Standardization.
else if (i->first == "modification")
else if (i.first == "modification")
{
Date d (unquoteText (i->second->dump ()));
Date d (unquoteText (i.second->dump ()));
set ("modified", d.toEpochString ());
}
// Dates are converted from ISO to epoch.
else if (type == "date")
{
std::string text = unquoteText (i->second->dump ());
std::string text = unquoteText (i.second->dump ());
Date d (text);
set (i->first, text == "" ? "" : d.toEpochString ());
set (i.first, text == "" ? "" : d.toEpochString ());
}
// Tags are an array of JSON strings.
else if (i->first == "tags" && i->second->type() == json::j_array)
else if (i.first == "tags" && i.second->type() == json::j_array)
{
json::array* tags = (json::array*)i->second;
json_array_iter t;
for (t = tags->_data.begin ();
t != tags->_data.end ();
++t)
json::array* tags = (json::array*)i.second;
for (auto& t : tags->_data)
{
json::string* tag = (json::string*)*t;
json::string* tag = (json::string*)t;
addTag (tag->_data);
}
}
// This is a temporary measure to allow Mirakel sync, and will be removed
// in a future release.
else if (i->first == "tags" && i->second->type() == json::j_string)
else if (i.first == "tags" && i.second->type() == json::j_string)
{
json::string* tag = (json::string*)i->second;
json::string* tag = (json::string*)i.second;
addTag (tag->_data);
}
// Strings are decoded.
else if (type == "string")
set (i->first, json::decode (unquoteText (i->second->dump ())));
set (i.first, json::decode (unquoteText (i.second->dump ())));
// Other types are simply added.
else
set (i->first, unquoteText (i->second->dump ()));
set (i.first, unquoteText (i.second->dump ()));
}
// UDA orphans and annotations do not have columns.
@ -673,17 +665,14 @@ void Task::parseJSON (const std::string& line)
{
// Annotations are an array of JSON objects with 'entry' and
// 'description' values and must be converted.
if (i->first == "annotations")
if (i.first == "annotations")
{
std::map <std::string, std::string> annos;
json::array* atts = (json::array*)i->second;
json_array_iter annotations;
for (annotations = atts->_data.begin ();
annotations != atts->_data.end ();
++annotations)
json::array* atts = (json::array*)i.second;
for (auto& annotations : atts->_data)
{
json::object* annotation = (json::object*)*annotations;
json::object* annotation = (json::object*)annotations;
json::string* when = (json::string*)annotation->_data["entry"];
json::string* what = (json::string*)annotation->_data["description"];
@ -706,13 +695,13 @@ void Task::parseJSON (const std::string& line)
#ifdef PRODUCT_TASKWARRIOR
std::stringstream message;
message << "Task::parseJSON found orphan '"
<< i->first
<< i.first
<< "' with value '"
<< i->second
<< i.second
<< "' --> preserved\n";
context.debug (message.str ());
#endif
set (i->first, json::decode (unquoteText (i->second->dump ())));
set (i.first, json::decode (unquoteText (i.second->dump ())));
}
}
}
@ -761,15 +750,14 @@ std::string Task::composeF4 () const
std::string ff4 = "[";
bool first = true;
Task::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
for (auto it : *this)
{
if (it->second != "")
if (it.second != "")
{
ff4 += (first ? "" : " ")
+ it->first
+ it.first
+ ":\""
+ encode (json::encode (it->second))
+ encode (json::encode (it.second))
+ "\"";
first = false;
@ -793,33 +781,32 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
// First the non-annotations.
int attributes_written = 0;
Task::const_iterator i;
for (i = this->begin (); i != this->end (); ++i)
for (auto& i : *this)
{
// Annotations are not written out here.
if (i->first.substr (0, 11) == "annotation_")
if (i.first.substr (0, 11) == "annotation_")
continue;
// If value is an empty string, do not ever output it
if (i->second == "")
if (i.second == "")
continue;
if (attributes_written)
out << ",";
std::string type = Task::attributes[i->first];
std::string type = Task::attributes[i.first];
if (type == "")
type = "string";
// Date fields are written as ISO 8601.
if (type == "date")
{
Date d (i->second);
Date d (i.second);
out << "\""
<< (i->first == "modification" ? "modified" : i->first)
<< (i.first == "modification" ? "modified" : i.first)
<< "\":\""
// Date was deleted, do not export parsed empty string
<< (i->second == "" ? "" : d.toISO ())
<< (i.second == "" ? "" : d.toISO ())
<< "\"";
++attributes_written;
@ -828,23 +815,22 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
else if (type == "numeric")
{
out << "\""
<< i->first
<< i.first
<< "\":"
<< i->second;
<< i.second;
++attributes_written;
}
// Tags are converted to an array.
else if (i->first == "tags")
else if (i.first == "tags")
{
std::vector <std::string> tags;
split (tags, i->second, ',');
split (tags, i.second, ',');
out << "\"tags\":[";
std::vector <std::string>::iterator i;
for (i = tags.begin (); i != tags.end (); ++i)
for (auto i = tags.begin (); i != tags.end (); ++i)
{
if (i != tags.begin ())
out << ",";
@ -861,9 +847,9 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
else
{
out << "\""
<< i->first
<< i.first
<< "\":\""
<< json::encode (i->second)
<< json::encode (i.second)
<< "\"";
++attributes_written;
@ -877,18 +863,18 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
<< "\"annotations\":[";
int annotations_written = 0;
for (i = this->begin (); i != this->end (); ++i)
for (auto& i : *this)
{
if (i->first.substr (0, 11) == "annotation_")
if (i.first.substr (0, 11) == "annotation_")
{
if (annotations_written)
out << ",";
Date d (i->first.substr (11));
Date d (i.first.substr (11));
out << "{\"entry\":\""
<< d.toISO ()
<< "\",\"description\":\""
<< json::encode (i->second)
<< json::encode (i.second)
<< "\"}";
++annotations_written;
@ -943,7 +929,7 @@ void Task::addAnnotation (const std::string& description)
void Task::removeAnnotations ()
{
// Erase old annotations.
Task::iterator i = this->begin ();
auto i = this->begin ();
while (i != this->end ())
{
if (i->first.substr (0, 11) == "annotation_")
@ -963,10 +949,9 @@ void Task::getAnnotations (std::map <std::string, std::string>& annotations) con
{
annotations.clear ();
Task::const_iterator ci;
for (ci = this->begin (); ci != this->end (); ++ci)
if (ci->first.substr (0, 11) == "annotation_")
annotations.insert (*ci);
for (auto& ann : *this)
if (ann.first.substr (0, 11) == "annotation_")
annotations.insert (ann);
}
////////////////////////////////////////////////////////////////////////////////
@ -975,9 +960,8 @@ void Task::setAnnotations (const std::map <std::string, std::string>& annotation
// Erase old annotations.
removeAnnotations ();
std::map <std::string, std::string>::const_iterator ci;
for (ci = annotations.begin (); ci != annotations.end (); ++ci)
this->insert (*ci);
for (auto& anno : annotations)
this->insert (anno);
annotation_count = annotations.size ();
recalc_urgency = true;
@ -1031,8 +1015,7 @@ void Task::removeDependency (const std::string& uuid)
std::vector <std::string> deps;
split (deps, get ("depends"), ',');
std::vector <std::string>::iterator i;
i = std::find (deps.begin (), deps.end (), uuid);
auto i = std::find (deps.begin (), deps.end (), uuid);
if (i != deps.end ())
{
deps.erase (i);
@ -1064,9 +1047,8 @@ void Task::getDependencies (std::vector <int>& all) const
all.clear ();
std::vector <std::string>::iterator i;
for (i = deps.begin (); i != deps.end (); ++i)
all.push_back (context.tdb2.pending.id (*i));
for (auto& dep : deps)
all.push_back (context.tdb2.pending.id (dep));
}
////////////////////////////////////////////////////////////////////////////////
@ -1160,9 +1142,8 @@ void Task::addTags (const std::vector <std::string>& tags)
{
remove ("tags");
std::vector <std::string>::const_iterator it;
for (it = tags.begin (); it != tags.end (); ++it)
addTag (*it);
for (auto& tag : tags)
addTag (tag);
recalc_urgency = true;
}
@ -1179,8 +1160,7 @@ void Task::removeTag (const std::string& tag)
std::vector <std::string> tags;
split (tags, get ("tags"), ',');
std::vector <std::string>::iterator i;
i = std::find (tags.begin (), tags.end (), tag);
auto i = std::find (tags.begin (), tags.end (), tag);
if (i != tags.end ())
{
tags.erase (i);
@ -1198,21 +1178,19 @@ void Task::removeTag (const std::string& tag)
// 'uda.<name>.type'
void Task::getUDAs (std::vector <std::string>& names) const
{
Task::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
if (context.config.get ("uda." + it->first + ".type") != "")
names.push_back (it->first);
for (auto& it : *this)
if (context.config.get ("uda." + it.first + ".type") != "")
names.push_back (it.first);
}
////////////////////////////////////////////////////////////////////////////////
// A UDA Orphan is an attribute that is not represented in context.columns.
void Task::getUDAOrphans (std::vector <std::string>& names) const
{
Task::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
if (it->first.substr (0, 11) != "annotation_")
if (context.columns.find (it->first) == context.columns.end ())
names.push_back (it->first);
for (auto& it : *this)
if (it.first.substr (0, 11) != "annotation_")
if (context.columns.find (it.first) == context.columns.end ())
names.push_back (it.first);
}
////////////////////////////////////////////////////////////////////////////////
@ -1257,17 +1235,16 @@ void Task::substitute (
if (!done)
{
// Perform all subs on annotations.
std::map <std::string, std::string>::iterator it;
for (it = annotations.begin (); it != annotations.end () && !done; ++it)
for (auto& it : annotations)
{
start.clear ();
end.clear ();
if (rx.match (start, end, it->second))
if (rx.match (start, end, it.second))
{
int skew = 0;
for (unsigned int i = 0; i < start.size () && !done; ++i)
{
it->second.replace (start[i + skew], end[i] - start[i], to);
it.second.replace (start[i + skew], end[i] - start[i], to);
skew += to.length () - (end[i] - start[i]);
++changes;
@ -1304,14 +1281,13 @@ void Task::substitute (
{
// Perform all subs on annotations.
counter = 0;
std::map <std::string, std::string>::iterator i;
for (i = annotations.begin (); i != annotations.end () && !done; ++i)
for (auto& anno : annotations)
{
pos = 0;
skew = 0;
while ((pos = ::find (i->second, from, pos, Task::searchCaseSensitive)) != std::string::npos && !done)
while ((pos = ::find (anno.second, from, pos, Task::searchCaseSensitive)) != std::string::npos && !done)
{
i->second.replace (pos + skew, from.length (), to);
anno.second.replace (pos + skew, from.length (), to);
skew += to.length () - from.length ();
pos += to.length ();
@ -1412,15 +1388,14 @@ void Task::validate (bool applyDefault /* = true */)
// override with uda.(uda).default, if not specified.
// Gather a list of all UDAs with a .default value
std::vector <std::string> udas;
Config::const_iterator var;
for (var = context.config.begin (); var != context.config.end (); ++var)
for (auto& var : context.config)
{
if (var->first.substr (0, 4) == "uda." &&
var->first.find (".default") != std::string::npos)
if (var.first.substr (0, 4) == "uda." &&
var.first.find (".default") != std::string::npos)
{
std::string::size_type period = var->first.find ('.', 4);
std::string::size_type period = var.first.find ('.', 4);
if (period != std::string::npos)
udas.push_back (var->first.substr (4, period - 4));
udas.push_back (var.first.substr (4, period - 4));
}
}
@ -1428,14 +1403,13 @@ void Task::validate (bool applyDefault /* = true */)
{
// For each of those, setup the default value on the task now,
// of course only if we don't have one on the command line already
std::vector <std::string>::iterator uda;
for (uda = udas.begin (); uda != udas.end (); ++uda)
for (auto& uda : udas)
{
std::string defVal= context.config.get ("uda." + *uda + ".default");
std::string defVal= context.config.get ("uda." + uda + ".default");
// If the default is empty, or we already have a value, skip it
if (defVal != "" && get (*uda) == "")
set (*uda, defVal);
if (defVal != "" && get (uda) == "")
set (uda, defVal);
}
}
}
@ -1650,64 +1624,63 @@ float Task::urgency_c () const
value += fabsf (Task::urgencyInheritCoefficient) > epsilon ? (urgency_inherit () * Task::urgencyInheritCoefficient) : 0.0;
// Tag- and project-specific coefficients.
std::map <std::string, float>::iterator var;
for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var)
for (auto& var : Task::coefficients)
{
if (fabs (var->second) > epsilon)
if (fabs (var.second) > epsilon)
{
if (var->first.substr (0, 13) == "urgency.user.")
if (var.first.substr (0, 13) == "urgency.user.")
{
// urgency.user.project.<project>.coefficient
std::string::size_type end = std::string::npos;
if (var->first.substr (13, 8) == "project." &&
(end = var->first.find (".coefficient")) != std::string::npos)
if (var.first.substr (13, 8) == "project." &&
(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 (get ("project").find (project) == 0)
value += var->second;
value += var.second;
}
// urgency.user.tag.<tag>.coefficient
if (var->first.substr (13, 4) == "tag." &&
(end = var->first.find (".coefficient")) != std::string::npos)
if (var.first.substr (13, 4) == "tag." &&
(end = var.first.find (".coefficient")) != std::string::npos)
{
std::string tag = var->first.substr (17, end - 17);
std::string tag = var.first.substr (17, end - 17);
if (hasTag (tag))
value += var->second;
value += var.second;
}
// urgency.user.keyword.<keyword>.coefficient
if (var->first.substr (13, 8) == "keyword." &&
(end = var->first.find (".coefficient")) != std::string::npos)
if (var.first.substr (13, 8) == "keyword." &&
(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 (get ("description").find (keyword) != std::string::npos)
value += var->second;
value += var.second;
}
}
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>.<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)
{
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 (".");
if (dot == std::string::npos)
{
// urgency.uda.<name>.coefficient
if (has (uda))
value += var->second;
value += var.second;
}
else
{
// urgency.uda.<name>.<value>.coefficient
if (get (uda.substr(0, dot)) == uda.substr(dot+1))
value += var->second;
value += var.second;
}
}
}
@ -1744,20 +1717,19 @@ float Task::urgency_inherit () const
dependencyGetBlocked (*this, blocked);
float v = 0.0;
std::vector <Task>::const_iterator it;
for (it = blocked.begin (); it != blocked.end (); ++it)
for (auto& task : blocked)
{
// urgency_blocked, _blocking, _project and _tags left out.
v += it->urgency_active ();
v += it->urgency_age ();
v += it->urgency_annotations ();
v += it->urgency_due ();
v += it->urgency_next ();
v += it->urgency_scheduled ();
v += it->urgency_waiting ();
v += task.urgency_active ();
v += task.urgency_age ();
v += task.urgency_annotations ();
v += task.urgency_due ();
v += task.urgency_next ();
v += task.urgency_scheduled ();
v += task.urgency_waiting ();
// Inherit from all parent tasks in the dependency chain recursively.
v += it->urgency_inherit ();
v += task.urgency_inherit ();
}
return v;
@ -1910,17 +1882,16 @@ void Task::modify (modType type, bool text_required /* = false */)
std::string label = " MODIFICATION ";
int modCount = 0;
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
for (auto& a : context.cli._args)
{
if (a->hasTag ("MODIFICATION"))
if (a.hasTag ("MODIFICATION"))
{
if (a->hasTag ("ATTRIBUTE"))
if (a.hasTag ("ATTRIBUTE"))
{
// 'name' is canonical.
// 'value' requires eval.
std::string name = a->attribute ("name");
std::string value = a->attribute ("value");
std::string name = a.attribute ("name");
std::string value = a.attribute ("value");
if (value == "" ||
value == "''" ||
value == "\"\"")
@ -1948,22 +1919,21 @@ void Task::modify (modType type, bool text_required /* = false */)
split (deps, value, ',');
// Apply or remove dendencies in turn.
std::vector <std::string>::iterator i;
for (i = deps.begin (); i != deps.end (); i++)
for (auto& dep : deps)
{
if ((*i)[0] == '-')
if (dep[0] == '-')
{
if ((*i).length () == 37)
removeDependency (context.tdb2.pending.id ((*i).substr (1)));
if (dep.length () == 37)
removeDependency (context.tdb2.pending.id (dep.substr (1)));
else
removeDependency (strtol ((*i).substr (1).c_str (), NULL, 10));
removeDependency (strtol (dep.substr (1).c_str (), NULL, 10));
}
else
{
if ((*i).length () == 36)
addDependency (context.tdb2.pending.id ((*i)));
if (dep.length () == 36)
addDependency (context.tdb2.pending.id (dep));
else
addDependency (strtol ((*i).c_str (), NULL, 10));
addDependency (strtol (dep.c_str (), NULL, 10));
}
}
@ -2104,22 +2074,22 @@ void Task::modify (modType type, bool text_required /* = false */)
}
// arg7 from='from' global='1' raw='/from/to/g' to='to' ORIGINAL SUBSTITUTION MODIFICATION
else if (a->hasTag ("SUBSTITUTION"))
else if (a.hasTag ("SUBSTITUTION"))
{
context.debug (label + "substitute " + a->attribute ("raw"));
substitute (a->attribute ("from"),
a->attribute ("to"),
(a->attribute ("global") == "1"));
context.debug (label + "substitute " + a.attribute ("raw"));
substitute (a.attribute ("from"),
a.attribute ("to"),
(a.attribute ("global") == "1"));
++modCount;
}
// Tags need special handling because they are essentially a vector stored
// in a single string, therefore Task::{add,remove}Tag must be called as
// appropriate.
else if (a->hasTag ("TAG"))
else if (a.hasTag ("TAG"))
{
std::string tag = a->attribute ("name");
if (a->attribute ("sign") == "+")
std::string tag = a.attribute ("name");
if (a.attribute ("sign") == "+")
{
context.debug (label + "tags <-- add '" + tag + "'");
addTag (tag);
@ -2135,12 +2105,12 @@ void Task::modify (modType type, bool text_required /* = false */)
}
// WORD and TERMINATED args are accumulated.
else if (a->hasTag ("WORD") ||
a->hasTag ("TERMINATED"))
else if (a.hasTag ("WORD") ||
a.hasTag ("TERMINATED"))
{
if (text != "")
text += ' ';
text += a->attribute ("raw");
text += a.attribute ("raw");
}
// Unknown args are accumulated as though they were WORDs.
@ -2148,7 +2118,7 @@ void Task::modify (modType type, bool text_required /* = false */)
{
if (text != "")
text += ' ';
text += a->attribute ("raw");
text += a.attribute ("raw");
}
}
}

View file

@ -1010,9 +1010,8 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
std::map <std::string, std::string> annotations;
task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator a;
for (a = annotations.begin (); a != annotations.end (); ++a)
if (r.match (a->second))
for (auto& a : annotations)
if (r.match (a.second))
return true;
}
}
@ -1028,9 +1027,8 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
std::map <std::string, std::string> annotations;
task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator a;
for (a = annotations.begin (); a != annotations.end (); ++a)
if (find (a->second, pattern, searchCaseSensitive) != std::string::npos)
for (auto& a : annotations)
if (find (a.second, pattern, searchCaseSensitive) != std::string::npos)
return true;
}
}

View file

@ -60,9 +60,8 @@ ViewTask::ViewTask ()
////////////////////////////////////////////////////////////////////////////////
ViewTask::~ViewTask ()
{
std::vector <Column*>::iterator i;
for (i = _columns.begin (); i != _columns.end (); ++i)
delete *i;
for (auto& col : _columns)
delete col;
_columns.clear ();
}
@ -297,7 +296,6 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
// Compose, render columns, in sequence.
_rows = 0;
std::vector <std::vector <std::string>> cells;
std::vector <int>::iterator s;
for (unsigned int s = 0; s < sequence.size (); ++s)
{
max_lines = 0;
@ -334,10 +332,9 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
if (s > 0 &&
_breaks.size () > 0)
{
std::vector <std::string>::iterator b;
for (b = _breaks.begin (); b != _breaks.end (); ++b)
for (auto& b : _breaks)
{
if (data[sequence[s - 1]].get (*b) != data[sequence[s]].get (*b))
if (data[sequence[s - 1]].get (b) != data[sequence[s]].get (b))
{
out += "\n";
++_lines;

View file

@ -56,9 +56,8 @@ ViewText::ViewText ()
////////////////////////////////////////////////////////////////////////////////
ViewText::~ViewText ()
{
std::vector <Column*>::iterator i;
for (i = _columns.begin (); i != _columns.end (); ++i)
delete *i;
for (auto& col : _columns)
delete col;
_columns.clear ();
}
@ -147,14 +146,13 @@ std::string ViewText::render ()
// Sum the minimal widths.
int sum_minimal = 0;
std::vector <int>::iterator c;
for (c = minimal.begin (); c != minimal.end (); ++c)
sum_minimal += *c;
for (auto& c : minimal)
sum_minimal += c;
// Sum the ideal widths.
int sum_ideal = 0;
for (c = ideal.begin (); c != ideal.end (); ++c)
sum_ideal += *c;
for (auto& c : ideal)
sum_ideal += c;
// Calculate final column widths.
int overage = _width

View file

@ -141,9 +141,8 @@ int main (int argc, char** argv)
e.evaluatePostfixExpression (expression, result);
// Show any debug output.
std::vector <std::string>::iterator i;
for (i = context.debugMessages.begin (); i != context.debugMessages.end (); ++i)
std::cout << *i << "\n";
for (auto& i : context.debugMessages)
std::cout << i << "\n";
// Show the result in string form.
std::cout << (std::string) result

View file

@ -42,14 +42,13 @@ void dependencyGetBlocked (const Task& task, std::vector <Task>& blocked)
{
std::string uuid = task.get ("uuid");
const std::vector <Task>& all = context.tdb2.pending.get_tasks ();
std::vector <Task>::const_iterator it;
for (it = all.begin (); it != all.end (); ++it)
if ((it->getStatus () == Task::pending ||
it->getStatus () == Task::waiting) &&
it->has ("depends") &&
it->get ("depends").find (uuid) != std::string::npos)
blocked.push_back (*it);
auto all = context.tdb2.pending.get_tasks ();
for (auto& it : all)
if ((it.getStatus () == Task::pending ||
it.getStatus () == Task::waiting) &&
it.has ("depends") &&
it.get ("depends").find (uuid) != std::string::npos)
blocked.push_back (it);
}
////////////////////////////////////////////////////////////////////////////////
@ -57,15 +56,11 @@ void dependencyGetBlocking (const Task& task, std::vector <Task>& blocking)
{
std::string depends = task.get ("depends");
if (depends != "")
{
const std::vector <Task>& all = context.tdb2.pending.get_tasks ();
std::vector <Task>::const_iterator it;
for (it = all.begin (); it != all.end (); ++it)
if ((it->getStatus () == Task::pending ||
it->getStatus () == Task::waiting) &&
depends.find (it->get ("uuid")) != std::string::npos)
blocking.push_back (*it);
}
for (auto& it : context.tdb2.pending.get_tasks ())
if ((it.getStatus () == Task::pending ||
it.getStatus () == Task::waiting) &&
depends.find (it.get ("uuid")) != std::string::npos)
blocking.push_back (it);
}
////////////////////////////////////////////////////////////////////////////////
@ -152,9 +147,8 @@ void dependencyChainOnComplete (Task& task)
std::cout << format (STRING_DEPEND_BLOCKED, task.id)
<< "\n";
std::vector <Task>::iterator b;
for (b = blocking.begin (); b != blocking.end (); ++b)
std::cout << " " << b->id << " " << b->get ("description") << "\n";
for (auto& b : blocking)
std::cout << " " << b.id << " " << b.get ("description") << "\n";
}
// If there are both blocking and blocked tasks, the chain is broken.
@ -165,9 +159,8 @@ void dependencyChainOnComplete (Task& task)
std::cout << STRING_DEPEND_BLOCKING
<< "\n";
std::vector <Task>::iterator b;
for (b = blocked.begin (); b != blocked.end (); ++b)
std::cout << " " << b->id << " " << b->get ("description") << "\n";
for (auto& b : blocked)
std::cout << " " << b.id << " " << b.get ("description") << "\n";
}
if (!context.config.getBoolean ("dependency.confirmation") ||
@ -175,22 +168,20 @@ void dependencyChainOnComplete (Task& task)
{
// Repair the chain - everything in blocked should now depend on
// everything in blocking, instead of task.id.
std::vector <Task>::iterator left;
std::vector <Task>::iterator right;
for (left = blocked.begin (); left != blocked.end (); ++left)
for (auto& left : blocked)
{
left->removeDependency (task.id);
left.removeDependency (task.id);
for (right = blocking.begin (); right != blocking.end (); ++right)
left->addDependency (right->id);
for (auto& right : blocking)
left.addDependency (right.id);
}
// Now update TDB2, now that the updates have all occurred.
for (left = blocked.begin (); left != blocked.end (); ++left)
context.tdb2.modify (*left);
for (auto& left : blocked)
context.tdb2.modify (left);
for (right = blocking.begin (); right != blocking.end (); ++right)
context.tdb2.modify (*right);
for (auto& right : blocking)
context.tdb2.modify (right);
}
}
}
@ -211,9 +202,8 @@ void dependencyChainOnStart (Task& task)
std::cout << format (STRING_DEPEND_BLOCKED, task.id)
<< "\n";
std::vector <Task>::iterator b;
for (b = blocking.begin (); b != blocking.end (); ++b)
std::cout << " " << b->id << " " << b->get ("description") << "\n";
for (auto& b : blocking)
std::cout << " " << b.id << " " << b.get ("description") << "\n";
}
}
}
@ -254,12 +244,9 @@ void dependencyChainOnModify (Task& before, Task& after)
std::vector <Task> blocked;
dependencyGetBlocked (after, blocked);
std::vector <Task>::iterator b;
for (b = blocked.begin (); b != blocked.end (); ++b)
{
for (auto& b : blocked)
std::cout << "# dependencyChainOnModify\n";
}
}
*/
}

View file

@ -49,13 +49,12 @@ bool taskDiff (const Task& before, const Task& after)
// Attributes are all there is, so figure the different attribute names
// between before and after.
std::vector <std::string> beforeAtts;
Task::const_iterator att;
for (att = before.begin (); att != before.end (); ++att)
beforeAtts.push_back (att->first);
for (auto& att : before)
beforeAtts.push_back (att.first);
std::vector <std::string> afterAtts;
for (att = after.begin (); att != after.end (); ++att)
afterAtts.push_back (att->first);
for (auto& att : after)
afterAtts.push_back (att.first);
std::vector <std::string> beforeOnly;
std::vector <std::string> afterOnly;
@ -65,10 +64,9 @@ bool taskDiff (const Task& before, const Task& after)
afterOnly.size ())
return true;
std::vector <std::string>::iterator name;
for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name)
if (*name != "uuid" &&
before.get (*name) != after.get (*name))
for (auto& name : beforeAtts)
if (name != "uuid" &&
before.get (name) != after.get (name))
return true;
return false;
@ -80,13 +78,12 @@ std::string taskDifferences (const Task& before, const Task& after)
// Attributes are all there is, so figure the different attribute names
// between before and after.
std::vector <std::string> beforeAtts;
Task::const_iterator att;
for (att = before.begin (); att != before.end (); ++att)
beforeAtts.push_back (att->first);
for (auto& att : before)
beforeAtts.push_back (att.first);
std::vector <std::string> afterAtts;
for (att = after.begin (); att != after.end (); ++att)
afterAtts.push_back (att->first);
for (auto& att : after)
afterAtts.push_back (att.first);
std::vector <std::string> beforeOnly;
std::vector <std::string> afterOnly;
@ -94,15 +91,14 @@ std::string taskDifferences (const Task& before, const Task& after)
// Now start generating a description of the differences.
std::stringstream out;
std::vector <std::string>::iterator name;
for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name)
for (auto& name : beforeOnly)
out << " - "
<< format (STRING_FEEDBACK_DELETED, ucFirst (*name))
<< format (STRING_FEEDBACK_DELETED, ucFirst (name))
<< "\n";
for (name = afterOnly.begin (); name != afterOnly.end (); ++name)
for (auto& name : afterOnly)
{
if (*name == "depends")
if (name == "depends")
{
std::vector <int> deps_after;
after.getDependencies (deps_after);
@ -116,21 +112,21 @@ std::string taskDifferences (const Task& before, const Task& after)
else
out << " - "
<< format (STRING_FEEDBACK_ATT_SET,
ucFirst (*name),
renderAttribute (*name, after.get (*name)))
ucFirst (name),
renderAttribute (name, after.get (name)))
<< "\n";
}
for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name)
for (auto& name : beforeAtts)
{
// Ignore UUID differences, and find values that changed, but are not also
// in the beforeOnly and afterOnly lists, which have been handled above..
if (*name != "uuid" &&
before.get (*name) != after.get (*name) &&
std::find (beforeOnly.begin (), beforeOnly.end (), *name) == beforeOnly.end () &&
std::find (afterOnly.begin (), afterOnly.end (), *name) == afterOnly.end ())
if (name != "uuid" &&
before.get (name) != after.get (name) &&
std::find (beforeOnly.begin (), beforeOnly.end (), name) == beforeOnly.end () &&
std::find (afterOnly.begin (), afterOnly.end (), name) == afterOnly.end ())
{
if (*name == "depends")
if (name == "depends")
{
std::vector <int> deps_before;
before.getDependencies (deps_before);
@ -149,9 +145,9 @@ std::string taskDifferences (const Task& before, const Task& after)
else
out << " - "
<< format (STRING_FEEDBACK_ATT_MOD,
ucFirst (*name),
renderAttribute (*name, before.get (*name)),
renderAttribute (*name, after.get (*name)))
ucFirst (name),
renderAttribute (name, before.get (name)),
renderAttribute (name, after.get (name)))
<< "\n";
}
}
@ -176,13 +172,12 @@ std::string taskInfoDifferences (
// Attributes are all there is, so figure the different attribute names
// between before and after.
std::vector <std::string> beforeAtts;
Task::const_iterator att;
for (att = before.begin (); att != before.end (); ++att)
beforeAtts.push_back (att->first);
for (auto& att : before)
beforeAtts.push_back (att.first);
std::vector <std::string> afterAtts;
for (att = after.begin (); att != after.end (); ++att)
afterAtts.push_back (att->first);
for (auto& att : after)
afterAtts.push_back (att.first);
std::vector <std::string> beforeOnly;
std::vector <std::string> afterOnly;
@ -190,10 +185,9 @@ std::string taskInfoDifferences (
// Now start generating a description of the differences.
std::stringstream out;
std::vector <std::string>::iterator name;
for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name)
for (auto& name : beforeOnly)
{
if (*name == "depends")
if (name == "depends")
{
std::vector <int> deps_before;
before.getDependencies (deps_before);
@ -203,27 +197,27 @@ std::string taskInfoDifferences (
out << format (STRING_FEEDBACK_DEP_DEL, from)
<< "\n";
}
else if (name->substr (0, 11) == "annotation_")
else if (name.substr (0, 11) == "annotation_")
{
out << format (STRING_FEEDBACK_ANN_DEL, before.get (*name))
out << format (STRING_FEEDBACK_ANN_DEL, before.get (name))
<< "\n";
}
else if (*name == "start")
else if (name == "start")
{
out << format (STRING_FEEDBACK_ATT_DEL_DUR, ucFirst (*name),
out << format (STRING_FEEDBACK_ATT_DEL_DUR, ucFirst (name),
Duration (current_timestamp - last_timestamp).formatPrecise ())
<< "\n";
}
else
{
out << format (STRING_FEEDBACK_ATT_DEL, ucFirst (*name))
out << format (STRING_FEEDBACK_ATT_DEL, ucFirst (name))
<< "\n";
}
}
for (name = afterOnly.begin (); name != afterOnly.end (); ++name)
for (auto& name : afterOnly)
{
if (*name == "depends")
if (name == "depends")
{
std::vector <int> deps_after;
after.getDependencies (deps_after);
@ -233,30 +227,31 @@ std::string taskInfoDifferences (
out << format (STRING_FEEDBACK_DEP_WAS_SET, to)
<< "\n";
}
else if (name->substr (0, 11) == "annotation_")
else if (name.substr (0, 11) == "annotation_")
{
out << format (STRING_FEEDBACK_ANN_ADD, after.get (*name))
out << format (STRING_FEEDBACK_ANN_ADD, after.get (name))
<< "\n";
}
else
{
if (*name == "start")
if (name == "start")
last_timestamp = current_timestamp;
out << format (STRING_FEEDBACK_ATT_WAS_SET,
ucFirst (*name),
renderAttribute (*name, after.get (*name), dateformat))
ucFirst (name),
renderAttribute (name, after.get (name), dateformat))
<< "\n";
}
}
for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name)
if (*name != "uuid" &&
*name != "modified" &&
before.get (*name) != after.get (*name) &&
before.get (*name) != "" && after.get (*name) != "")
for (auto& name : beforeAtts)
if (name != "uuid" &&
name != "modified" &&
before.get (name) != after.get (name) &&
before.get (name) != "" &&
after.get (name) != "")
{
if (*name == "depends")
if (name == "depends")
{
std::vector <int> deps_before;
before.getDependencies (deps_before);
@ -271,16 +266,16 @@ std::string taskInfoDifferences (
out << format (STRING_FEEDBACK_DEP_WAS_MOD, from, to)
<< "\n";
}
else if (name->substr (0, 11) == "annotation_")
else if (name.substr (0, 11) == "annotation_")
{
out << format (STRING_FEEDBACK_ANN_WAS_MOD, after.get (*name))
out << format (STRING_FEEDBACK_ANN_WAS_MOD, after.get (name))
<< "\n";
}
else
out << format (STRING_FEEDBACK_ATT_WAS_MOD,
ucFirst (*name),
renderAttribute (*name, before.get (*name), dateformat),
renderAttribute (*name, after.get (*name), dateformat))
ucFirst (name),
renderAttribute (name, before.get (name), dateformat),
renderAttribute (name, after.get (name), dateformat))
<< "\n";
}
@ -397,24 +392,23 @@ void feedback_unblocked (const Task& task)
dependencyGetBlocked (task, blocked);
// Scan all the tasks that were blocked by this task
std::vector <Task>::iterator i;
for (i = blocked.begin (); i != blocked.end (); ++i)
for (auto& i : blocked)
{
std::vector <Task> blocking;
dependencyGetBlocking (*i, blocking);
dependencyGetBlocking (i, blocking);
if (blocking.size () == 0)
{
if (i->id)
if (i.id)
std::cout << format (STRING_FEEDBACK_UNBLOCKED,
i->id,
i->get ("description"))
i.id,
i.get ("description"))
<< "\n";
else
{
std::string uuid = i->get ("uuid");
std::string uuid = i.get ("uuid");
std::cout << format (STRING_FEEDBACK_UNBLOCKED,
i->get ("uuid"),
i->get ("description"))
i.get ("uuid"),
i.get ("description"))
<< "\n";
}
}
@ -429,10 +423,9 @@ void feedback_backlog ()
context.verbose ("sync"))
{
std::vector <std::string> lines = context.tdb2.backlog.get_lines ();
std::vector <std::string>::iterator line;
for (line = lines.begin (); line != lines.end (); ++line)
for (auto& line : lines)
{
if ((*line)[0] == '{')
if ((line)[0] == '{')
{
context.footnote (STRING_FEEDBACK_BACKLOG);
break;
@ -518,12 +511,11 @@ static void countTasks (
int& count_pending,
int& count_done)
{
std::vector <Task>::const_iterator it;
for (it = all.begin (); it != all.end (); ++it)
for (auto& it : all)
{
if (it->get ("project") == project)
if (it.get ("project") == project)
{
switch (it->getStatus ())
switch (it.getStatus ())
{
case Task::pending:
case Task::waiting:

View file

@ -63,7 +63,7 @@ void legacyColumnMap (std::string& name)
}
// If a legacy column was used, complain about it, but modify it anyway.
std::map <std::string, std::string>::iterator found = legacyMap.find (name);
auto found = legacyMap.find (name);
if (found != legacyMap.end ())
{
context.footnote (format (STRING_LEGACY_PRIORITY, name, found->second));
@ -95,7 +95,7 @@ void legacySortColumnMap (std::string& name)
}
// If a legacy column was used, complain about it, but modify it anyway.
std::map <std::string, std::string>::iterator found = legacyMap.find (name);
auto found = legacyMap.find (name);
if (found != legacyMap.end ())
{
context.footnote (format (STRING_LEGACY_PRIORITY, name, found->second));
@ -115,25 +115,24 @@ std::string legacyCheckForDeprecatedColor ()
std::string legacyCheckForDeprecatedVariables ()
{
std::vector <std::string> deprecated;
std::map <std::string, std::string>::const_iterator it;
for (it = context.config.begin (); it != context.config.end (); ++it)
for (auto& it : context.config)
{
// 2014-07-04: report.*.limit removed.
// report.*.annotations
if (it->first.length () > 19 &&
it->first.substr (0, 7) == "report." &&
it->first.substr (it->first.length () - 12) == ".annotations")
deprecated.push_back (it->first);
if (it.first.length () > 19 &&
it.first.substr (0, 7) == "report." &&
it.first.substr (it.first.length () - 12) == ".annotations")
deprecated.push_back (it.first);
if (it->first == "next" ||
it->first == "annotations" ||
it->first == "export.ical.class")
deprecated.push_back (it->first);
if (it.first == "next" ||
it.first == "annotations" ||
it.first == "export.ical.class")
deprecated.push_back (it.first);
// Deprecated іn 2.4.0.
if (it->first == "alias._query")
deprecated.push_back (it->first);
if (it.first == "alias._query")
deprecated.push_back (it.first);
}
std::stringstream out;
@ -142,9 +141,8 @@ std::string legacyCheckForDeprecatedVariables ()
out << STRING_CONFIG_DEPRECATED_VAR
<< "\n";
std::vector <std::string>::iterator it2;
for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
out << " " << *it2 << "\n";
for (auto& dep : deprecated)
out << " " << dep << "\n";
out << "\n";
}
@ -156,16 +154,15 @@ std::string legacyCheckForDeprecatedVariables ()
std::string legacyCheckForDeprecatedColumns ()
{
std::vector <std::string> deprecated;
std::map <std::string, std::string>::const_iterator it;
for (it = context.config.begin (); it != context.config.end (); ++it)
for (auto& it : context.config)
{
if (it->first.find ("report") == 0)
if (it.first.find ("report") == 0)
{
std::string value = context.config.get (it->first);
std::string value = context.config.get (it.first);
if (value.find ("entry_time") != std::string::npos ||
value.find ("start_time") != std::string::npos ||
value.find ("end_time") != std::string::npos)
deprecated.push_back (it->first);
deprecated.push_back (it.first);
}
}
@ -177,9 +174,8 @@ std::string legacyCheckForDeprecatedColumns ()
out << STRING_CONFIG_DEPRECATED_COL
<< "\n";
std::vector <std::string>::iterator it2;
for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
out << " " << *it2 << "=" << context.config.get (*it2) << "\n";
for (auto& dep : deprecated)
out << " " << dep << "=" << context.config.get (dep) << "\n";
out << "\n";
}

View file

@ -60,56 +60,54 @@ void handleRecurrence ()
if (! context.config.getBoolean ("recurrence"))
return;
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
auto tasks = context.tdb2.pending.get_tasks ();
Date now;
// Look at all tasks and find any recurring ones.
std::vector <Task>::iterator t;
for (t = tasks.begin (); t != tasks.end (); ++t)
for (auto& t : tasks)
{
if (t->getStatus () == Task::recurring)
if (t.getStatus () == Task::recurring)
{
// Generate a list of due dates for this recurring task, regardless of
// the mask.
std::vector <Date> due;
if (!generateDueDates (*t, due))
if (!generateDueDates (t, due))
{
// Determine the end date.
t->setStatus (Task::deleted);
context.tdb2.modify (*t);
context.footnote (onExpiration (*t));
t.setStatus (Task::deleted);
context.tdb2.modify (t);
context.footnote (onExpiration (t));
continue;
}
// Get the mask from the parent task.
std::string mask = t->get ("mask");
std::string mask = t.get ("mask");
// Iterate over the due dates, and check each against the mask.
bool changed = false;
unsigned int i = 0;
std::vector <Date>::iterator d;
for (d = due.begin (); d != due.end (); ++d)
for (auto& d : due)
{
if (mask.length () <= i)
{
changed = true;
Task rec (*t); // Clone the parent.
Task rec (t); // Clone the parent.
rec.setStatus (Task::pending); // Change the status.
rec.id = context.tdb2.next_id (); // New ID.
rec.set ("uuid", uuid ()); // New UUID.
rec.set ("parent", t->get ("uuid")); // Remember mom.
rec.set ("parent", t.get ("uuid")); // Remember mom.
rec.setAsNow ("entry"); // New entry date.
char dueDate[16];
sprintf (dueDate, "%u", (unsigned int) d->toEpoch ());
sprintf (dueDate, "%u", (unsigned int) d.toEpoch ());
rec.set ("due", dueDate); // Store generated due date.
if (t->has ("wait"))
if (t.has ("wait"))
{
Date old_wait (t->get_date ("wait"));
Date old_due (t->get_date ("due"));
Date due (*d);
Date old_wait (t.get_date ("wait"));
Date old_due (t.get_date ("due"));
Date due (d);
sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ());
rec.set ("wait", dueDate);
rec.setStatus (Task::waiting);
@ -137,20 +135,20 @@ void handleRecurrence ()
// Only modify the parent if necessary.
if (changed)
{
t->set ("mask", mask);
context.tdb2.modify (*t);
t.set ("mask", mask);
context.tdb2.modify (t);
}
}
// Non-recurring tasks expire too.
else
{
if (t->has ("until") &&
Date (t->get_date ("until")) < now)
if (t.has ("until") &&
Date (t.get_date ("until")) < now)
{
t->setStatus (Task::deleted);
context.tdb2.modify(*t);
context.footnote (onExpiration (*t));
t.setStatus (Task::deleted);
context.tdb2.modify(t);
context.footnote (onExpiration (t));
}
}
}
@ -424,14 +422,11 @@ bool nag (Task& task)
std::string nagMessage = context.config.get ("nag");
if (nagMessage != "")
{
// Load all pending tasks.
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
// Scan all pending tasks.
std::vector <Task>::iterator t;
for (t = tasks.begin (); t != tasks.end (); ++t)
auto pending = context.tdb2.pending.get_tasks ();
for (auto& t : pending)
{
if (t->urgency () > task.urgency ())
if (t.urgency () > task.urgency ())
{
context.footnote (nagMessage);
return true;

View file

@ -53,15 +53,14 @@ void initializeColorRules ()
// Load all the configuration values, filter to only the ones that begin with
// "color.", then store name/value in gsColor, and name in rules.
std::vector <std::string> rules;
Config::const_iterator v;
for (v = context.config.begin (); v != context.config.end (); ++v)
for (auto& v : context.config)
{
if (v->first.substr (0, 6) == "color.")
if (v.first.substr (0, 6) == "color.")
{
Color c (v->second);
gsColor[v->first] = c;
Color c (v.second);
gsColor[v.first] = c;
rules.push_back (v->first);
rules.push_back (v.first);
}
}
@ -71,16 +70,14 @@ void initializeColorRules ()
std::vector <std::string> precedence;
split (precedence, context.config.get ("rule.precedence.color"), ',');
std::vector <std::string>::iterator p;
for (p = precedence.begin (); p != precedence.end (); ++p)
for (auto& p : precedence)
{
// Add the leading "color." string.
std::string rule = "color." + *p;
std::string rule = "color." + p;
autoComplete (rule, rules, results, 3); // Hard-coded 3.
std::vector <std::string>::iterator r;
for (r = results.begin (); r != results.end (); ++r)
gsPrecedence.push_back (*r);
for (auto& r : results)
gsPrecedence.push_back (r);
}
}
@ -185,11 +182,10 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
// first match.
else
{
Task::iterator it;
for (it = task.begin (); it != task.end (); ++it)
for (auto& it : task)
{
if (it->first.substr (0, 11) == "annotation_" &&
find (it->second, rule.substr (14), sensitive) != std::string::npos)
if (it.first.substr (0, 11) == "annotation_" &&
find (it.second, rule.substr (14), sensitive) != std::string::npos)
{
c.blend (base);
return;
@ -292,8 +288,7 @@ void autoColorize (Task& task, Color& c)
// Note: c already contains colors specifically assigned via command.
// Note: These rules form a hierarchy - the last rule is King, hence the
// reverse iterator.
std::vector <std::string>::reverse_iterator r;
for (r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r)
for (auto r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r)
{
Color base = gsColor[*r];
if (base.nontrivial ())

View file

@ -80,10 +80,9 @@ static bool sort_compare (int left, int right)
float left_real;
float right_real;
std::vector <std::string>::iterator k;
for (k = global_keys.begin (); k != global_keys.end (); ++k)
for (auto& k : global_keys)
{
context.decomposeSortField (*k, field, ascending, breakIndicator);
context.decomposeSortField (k, field, ascending, breakIndicator);
// Urgency.
if (field == "urgency")

View file

@ -156,23 +156,22 @@ int autoComplete (
unsigned int length = partial.length ();
if (length)
{
std::vector <std::string>::const_iterator item;
for (item = list.begin (); item != list.end (); ++item)
for (auto& item : list)
{
// An exact match is a special case. Assume there is only one exact match
// and return immediately.
if (partial == *item)
if (partial == item)
{
matches.clear ();
matches.push_back (*item);
matches.push_back (item);
return 1;
}
// Maintain a list of partial matches.
else if (length >= (unsigned) minimum &&
length <= item->length () &&
partial == item->substr (0, length))
matches.push_back (*item);
length <= item.length () &&
partial == item.substr (0, length))
matches.push_back (item);
}
}