From 7c910e46bef03e58c370fc2726ef6b71a4287645 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 7 Jun 2011 00:48:00 -0400 Subject: [PATCH] Code Cleanup - Just found out about std::vector::back, after all these years. --- src/Expression.cpp | 20 +++++++++++--------- src/commands/CmdBurndown.cpp | 4 ++-- src/commands/CmdImport.cpp | 6 +++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Expression.cpp b/src/Expression.cpp index 2fc20c48b..13e4e3d6a 100644 --- a/src/Expression.cpp +++ b/src/Expression.cpp @@ -52,8 +52,10 @@ Expression::~Expression () //////////////////////////////////////////////////////////////////////////////// bool Expression::eval (Task& task) { - // TODO Duplicate the _postfix vector as the operating stack. - // TODO ... + std::vector >::iterator arg; + for (arg = _postfix.begin (); arg != _postfix.end (); ++arg) + { + } return true; } @@ -430,9 +432,9 @@ void Expression::to_postfix () else if (arg->first == ")") { while (op_stack.size () > 0 && - op_stack[op_stack.size () - 1].first != "(") + op_stack.back ().first != "(") { - _postfix.push_back (op_stack[op_stack.size () - 1]); + _postfix.push_back (op_stack.back ()); op_stack.pop_back (); } @@ -451,11 +453,11 @@ void Expression::to_postfix () int precedence2; char associativity2; while (op_stack.size () > 0 && - Arguments::is_operator (op_stack[op_stack.size () - 1].first, type2, precedence2, associativity2) && + Arguments::is_operator (op_stack.back ().first, type2, precedence2, associativity2) && ((associativity == 'l' && precedence <= precedence2) || (associativity == 'r' && precedence < precedence2))) { - _postfix.push_back (op_stack[op_stack.size () - 1]); + _postfix.push_back (op_stack.back ()); op_stack.pop_back (); } @@ -469,11 +471,11 @@ void Expression::to_postfix () while (op_stack.size () != 0) { - if (op_stack[op_stack.size () - 1].first == "(" || - op_stack[op_stack.size () - 1].first == ")") + if (op_stack.back ().first == "(" || + op_stack.back ().first == ")") throw std::string ("Mismatched parentheses in expression"); - _postfix.push_back (op_stack[op_stack.size () - 1]); + _postfix.push_back (op_stack.back ()); op_stack.pop_back (); } diff --git a/src/commands/CmdBurndown.cpp b/src/commands/CmdBurndown.cpp index 093a9dcf3..7d34da84d 100644 --- a/src/commands/CmdBurndown.cpp +++ b/src/commands/CmdBurndown.cpp @@ -832,7 +832,7 @@ void Chart::calculateRates (std::vector & sequence) { // If there are no current pending tasks, then it is meaningless to find // rates or estimated completion date. - if (bars[sequence[sequence.size () - 1]].pending == 0) + if (bars[sequence.back ()].pending == 0) return; // Calculate how many items we have. @@ -936,7 +936,7 @@ void Chart::calculateRates (std::vector & sequence) // Estimate completion if (fix_rate > find_rate) { - int current_pending = bars[sequence[sequence.size () - 1]].pending; + int current_pending = bars[sequence.back ()].pending; int remaining_days = (int) (current_pending / (fix_rate - find_rate)); Date now; diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 12b218ce2..3d0d462ee 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -235,7 +235,7 @@ std::string CmdImport::task_1_4_3 (const std::vector & lines) if (fields[f][0] != '\'' && fields[f][fields[f].length () - 1] == '\'') { - modified[modified.size () - 1] += "," + fields[f]; + modified.back () += "," + fields[f]; } else @@ -391,7 +391,7 @@ std::string CmdImport::task_1_5_0 (const std::vector & lines) if (fields[f][0] != '\'' && fields[f][fields[f].length () - 1] == '\'') { - modified[modified.size () - 1] += "," + fields[f]; + modified.back () += "," + fields[f]; } else @@ -552,7 +552,7 @@ std::string CmdImport::task_1_6_0 (const std::vector & lines) if (fields[f][0] != '\'' && fields[f][fields[f].length () - 1] == '\'') { - modified[modified.size () - 1] += "," + fields[f]; + modified.back () += "," + fields[f]; } else