lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 0d5b38d 4/4: Prefer single-character iterator


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0d5b38d 4/4: Prefer single-character iterator names
Date: Sat, 26 May 2018 09:54:17 -0400 (EDT)

branch: master
commit 0d5b38d32939d8fbd92a98f530cb9738d7f22719
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Prefer single-character iterator names
    
    The natural name for the [dereferenced] iterator in [ranged] for(...) is
    i in an outer loop and j in an inner loop.
---
 group_quote_pdf_gen_wx.cpp  | 74 ++++++++++++++++++++++-----------------------
 ledger_pdf_generator_wx.cpp | 29 +++++++++---------
 wx_table_generator.cpp      | 35 +++++++++++----------
 3 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index b2c7d99..0773d0a 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -357,9 +357,9 @@ class group_quote_pdf_generator_wx
       public:
         totals_data()
             {
-            for(int col = e_first_totalled_column; col < e_col_max; ++col)
+            for(int i = e_first_totalled_column; i < e_col_max; ++i)
                 {
-                value(col) = 0.0;
+                value(i) = 0.0;
                 }
             }
 
@@ -538,32 +538,32 @@ void group_quote_pdf_generator_wx::add_ledger(Ledger 
const& ledger)
     bool const is_composite = ledger.is_composite();
 
     row_data rd;
-    for(int col = 0; col < e_col_max; ++col)
+    for(int i = 0; i < e_col_max; ++i)
         {
         // The cast is only used to ensure that if any new elements are added
         // to the enum, the compiler would warn about their values not being
         // present in this switch.
-        switch(static_cast<enum_group_quote_columns>(col))
+        switch(static_cast<enum_group_quote_columns>(i))
             {
             case e_col_number:
                 {
                 // Row numbers shown to human beings should be 1-based.
-                rd.output_values[col] = wxString::Format("%d", row_num_ + 
1).ToStdString();
+                rd.output_values[i] = wxString::Format("%d", row_num_ + 
1).ToStdString();
                 }
                 break;
             case e_col_name:
                 {
-                rd.output_values[col] = invar.Insured1;
+                rd.output_values[i] = invar.Insured1;
                 }
                 break;
             case e_col_age:
                 {
-                rd.output_values[col] = wxString::Format("%.0f", 
invar.Age).ToStdString();
+                rd.output_values[i] = wxString::Format("%.0f", 
invar.Age).ToStdString();
                 }
                 break;
             case e_col_dob:
                 {
-                rd.output_values[col] = ConvertDateToWx
+                rd.output_values[i] = ConvertDateToWx
                     (jdn_t(static_cast<int>(invar.DateOfBirthJdn))
                     ).FormatDate().ToStdString(wxConvUTF8);
                 }
@@ -571,60 +571,60 @@ void group_quote_pdf_generator_wx::add_ledger(Ledger 
const& ledger)
             case e_col_basic_face_amount:
                 {
                 double const z = invar.SpecAmt.at(year);
-                rd.output_values[col] = '$' + ledger_format(z, f0);
+                rd.output_values[i] = '$' + ledger_format(z, f0);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
             case e_col_basic_premium:
                 {
                 double const z = invar.ErModalMinimumPremium.at(year);
-                rd.output_values[col] = '$' + ledger_format(z, f2);
+                rd.output_values[i] = '$' + ledger_format(z, f2);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
             case e_col_supplemental_face_amount:
                 {
                 double const z = invar.TermSpecAmt.at(year);
-                rd.output_values[col] = '$' + ledger_format(z, f0);
+                rd.output_values[i] = '$' + ledger_format(z, f0);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
             case e_col_additional_premium:
                 {
                 double const z = invar.EeModalMinimumPremium.at(year) + 
invar.ModalMinimumDumpin;
-                rd.output_values[col] = '$' + ledger_format(z, f2);
+                rd.output_values[i] = '$' + ledger_format(z, f2);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
             case e_col_total_face_amount:
                 {
                 double const z = invar.SpecAmt.at(year) + 
invar.TermSpecAmt.at(year);
-                rd.output_values[col] = '$' + ledger_format(z, f0);
+                rd.output_values[i] = '$' + ledger_format(z, f0);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
             case e_col_total_premium:
                 {
                 double const z = invar.ModalMinimumPremium.at(year) + 
invar.ModalMinimumDumpin;
-                rd.output_values[col] = '$' + ledger_format(z, f2);
+                rd.output_values[i] = '$' + ledger_format(z, f2);
                 if(is_composite)
                     {
-                    totals_.total(col, z);
+                    totals_.total(i, z);
                     }
                 }
                 break;
@@ -671,22 +671,22 @@ void group_quote_pdf_generator_wx::save(std::string 
const& output_filename)
     bool const has_addl_premium = totals_.total(e_col_additional_premium      
) != 0.0;
 
     std::vector<column_parameters> vc;
-    for(int col = 0; col < e_col_max; ++col)
+    for(int i = 0; i < e_col_max; ++i)
         {
-        column_definition const& cd = column_definitions[col];
+        column_definition const& cd = column_definitions[i];
         std::string header;
         oenum_h_align alignment = oe_center;
         // PDF !! This doesn't fit into the switch logic below.
-        if(e_col_name == col) {alignment = oe_left;}
+        if(e_col_name == i) {alignment = oe_left;}
         oenum_visibility visibility = oe_shown;
         oenum_elasticity elasticity = oe_inelastic;
         // PDF !! This doesn't fit into the switch logic below.
-        if(e_col_name == col) {elasticity = oe_elastic;}
+        if(e_col_name == i) {elasticity = oe_elastic;}
 
         // The cast is only used to ensure that if any new elements are added
         // to the enum, the compiler would warn about their values not being
         // present in this switch.
-        switch(static_cast<enum_group_quote_columns>(col))
+        switch(static_cast<enum_group_quote_columns>(i))
             {
             case e_col_supplemental_face_amount:
             case e_col_total_face_amount:
@@ -1081,23 +1081,23 @@ void 
group_quote_pdf_generator_wx::output_aggregate_values
         ,wxALIGN_RIGHT
         );
 
-    for(int col = e_first_totalled_column; col < e_col_max; ++col)
+    for(int i = e_first_totalled_column; i < e_col_max; ++i)
         {
         int const decimals =
-            ((e_col_basic_face_amount           == col) ? 0
-            :(e_col_basic_premium               == col) ? 2
-            :(e_col_supplemental_face_amount    == col) ? 0
-            :(e_col_additional_premium          == col) ? 2
-            :(e_col_total_face_amount           == col) ? 0
-            :(e_col_total_premium               == col) ? 2
+            ((e_col_basic_face_amount           == i) ? 0
+            :(e_col_basic_premium               == i) ? 2
+            :(e_col_supplemental_face_amount    == i) ? 0
+            :(e_col_additional_premium          == i) ? 2
+            :(e_col_total_face_amount           == i) ? 0
+            :(e_col_total_premium               == i) ? 2
             :throw std::logic_error("Invalid column type.")
             );
         std::pair<int,oenum_format_style> const f(decimals, oe_format_normal);
 
         table_gen.output_highlighted_cell
-            (col
+            (i
             ,y
-            ,'$' + ledger_format(totals_.total(col), f)
+            ,'$' + ledger_format(totals_.total(i), f)
             );
 
         // Average cost per $1000 is presented only for the "basic"
@@ -1122,7 +1122,7 @@ void group_quote_pdf_generator_wx::output_aggregate_values
         // The cast is only used to ensure that if any new elements are added
         // to the enum, the compiler would warn about their values not being
         // present in this switch.
-        switch(static_cast<enum_group_quote_columns>(col))
+        switch(static_cast<enum_group_quote_columns>(i))
             {
             case e_col_basic_premium:
                 {
@@ -1152,13 +1152,13 @@ void 
group_quote_pdf_generator_wx::output_aggregate_values
                 break;
             default:
                 {
-                alarum() << "Case " << col << " not found." << LMI_FLUSH;
+                alarum() << "Case " << i << " not found." << LMI_FLUSH;
                 }
             }
 
         // For columns that do not have averages, writing an empty
         // string ensures that the background is homogeneous.
-        table_gen.output_highlighted_cell(col, y_next, average_text);
+        table_gen.output_highlighted_cell(i, y_next, average_text);
         }
 
     table_gen.output_vert_separator(e_col_max, y);
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 29f330f..8c76783 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -733,13 +733,13 @@ class pdf_illustration : protected html_interpolator
         html_cell_for_pdf_output::pdf_context_setter
             set_pdf_context(ledger_, writer, *this);
 
-        for(auto const& page : pages_)
+        for(auto const& i : pages_)
             {
-            page->pre_render(ledger_, writer, *this);
+            i->pre_render(ledger_, writer, *this);
             }
 
         bool first = true;
-        for(auto const& page : pages_)
+        for(auto const& i : pages_)
             {
             if(first)
                 {
@@ -754,7 +754,7 @@ class pdf_illustration : protected html_interpolator
                 writer.dc().StartPage();
                 }
 
-            page->render(ledger_, writer, *this);
+            i->render(ledger_, writer, *this);
             }
 
         writer.save();
@@ -1456,26 +1456,27 @@ class numeric_summary_table_cell
                     break;
 
                 case oe_render:
-                    for(std::size_t col = 0; col < columns.size(); ++col)
+                    for(std::size_t j = 0; j < columns.size(); ++j)
                         {
-                        std::string const variable_name = 
columns[col].variable_name;
+                        std::string const variable_name = 
columns[j].variable_name;
 
-                        // According to regulations, we need to replace the
-                        // policy year in the last row with the age.
-                        if(col == column_policy_year)
+                        // The illustration reg calls for values at certain
+                        // durations, and then at one summary age, so change
+                        // beginning of last row from a duration to an age.
+                        if(j == column_policy_year)
                             {
                             if(is_last_row)
                                 {
                                 std::ostringstream oss;
                                 oss << "Age " << age_last;
-                                output_values[col] = oss.str();
+                                output_values[j] = oss.str();
                                 continue;
                                 }
                             }
 
                         // Special hack for the dummy columns whose value is 
always
                         // empty as it's used only as separator.
-                        output_values[col] = variable_name.empty()
+                        output_values[j] = variable_name.empty()
                             ? std::string{}
                             : interpolate_html.evaluate(variable_name, year - 
1)
                             ;
@@ -1594,14 +1595,14 @@ class page_with_tabular_report
 
             for(;;)
                 {
-                for(std::size_t col = 0; col < columns.size(); ++col)
+                for(std::size_t j = 0; j < columns.size(); ++j)
                     {
-                    std::string const variable_name = 
columns[col].variable_name;
+                    std::string const variable_name = columns[j].variable_name;
 
                     // Special hack for the dummy columns used in some reports,
                     // whose value is always empty as it's used only as
                     // separator.
-                    output_values[col] = variable_name.empty()
+                    output_values[j] = variable_name.empty()
                         ? std::string{}
                         : interpolate_html.evaluate(variable_name, year)
                         ;
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index 8ffd66d..eb19080 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -217,9 +217,9 @@ void wx_table_generator::output_headers
     // number of lines.
     std::size_t const number_of_columns = all_columns().size();
     std::vector<std::string> headers_by_line(max_header_lines_ * 
number_of_columns);
-    for(std::size_t col = 0; col < number_of_columns; ++col)
+    for(std::size_t i = 0; i < number_of_columns; ++i)
         {
-        column_info const& ci = all_columns().at(col);
+        column_info const& ci = all_columns().at(i);
         if(ci.is_hidden())
             {
             continue;
@@ -230,22 +230,22 @@ void wx_table_generator::output_headers
         // Fill the elements from the bottom line to the top one, so that a
         // single line header is shown on the last line.
         std::size_t const first_line = max_header_lines_ - lines.size();
-        for(std::size_t line = 0; line < lines.size(); ++line)
+        for(std::size_t j = 0; j < lines.size(); ++j)
             {
             headers_by_line.at
-                ((first_line + line) * number_of_columns + col
-                ) = lines.at(line);
+                ((first_line + j) * number_of_columns + i
+                ) = lines.at(j);
             }
         }
 
     // And output all lines of all column headers.
     int y_top = pos_y;
     int x = 0;
-    for(std::size_t line = 0; line < max_header_lines_; ++line)
+    for(std::size_t i = 0; i < max_header_lines_; ++i)
         {
         std::vector<std::string> const nth_line
-            (headers_by_line.begin() +      line  * number_of_columns
-            ,headers_by_line.begin() + (1 + line) * number_of_columns
+            (headers_by_line.begin() +      i  * number_of_columns
+            ,headers_by_line.begin() + (1 + i) * number_of_columns
             );
         x = left_margin_;
         do_output_single_row(x, pos_y, nth_line);
@@ -294,10 +294,9 @@ void wx_table_generator::output_super_header
     auto rect = text_rect(begin_column, pos_y);
     rect.width += cell_pos_x(end_column) - cell_pos_x(begin_column + 1);
 
-    for(auto const& line : lines)
+    for(auto const& i : lines)
         {
-        dc_.DrawLabel(line, rect, wxALIGN_CENTER_HORIZONTAL);
-
+        dc_.DrawLabel(i, rect, wxALIGN_CENTER_HORIZONTAL);
         rect.y += row_height_;
         pos_y  += row_height_;
         }
@@ -388,9 +387,9 @@ void wx_table_generator::output_horz_separator
     int const x1 = cell_pos_x(begin_column);
 
     int x2 = x1;
-    for(std::size_t col = begin_column; col < end_column; ++col)
+    for(std::size_t i = begin_column; i < end_column; ++i)
         {
-        x2 += all_columns().at(col).col_width();
+        x2 += all_columns().at(i).col_width();
         }
 
     do_output_horz_separator(x1, x2, y);
@@ -709,15 +708,15 @@ void wx_table_generator::do_output_single_row
         }
 
     std::size_t const number_of_columns = all_columns().size();
-    for(std::size_t col = 0; col < number_of_columns; ++col)
+    for(std::size_t i = 0; i < number_of_columns; ++i)
         {
-        column_info const& ci = all_columns().at(col);
+        column_info const& ci = all_columns().at(i);
         if(ci.is_hidden())
             {
             continue;
             }
 
-        std::string const& s = values[col];
+        std::string const& s = values[i];
         if(!s.empty())
             {
             int x_text = pos_x;
@@ -796,9 +795,9 @@ void wx_table_generator::do_output_horz_separator(int x1, 
int x2, int y)
 int wx_table_generator::cell_pos_x(std::size_t column) const
 {
     int x = left_margin_;
-    for(std::size_t col = 0; col < column; ++col)
+    for(std::size_t i = 0; i < column; ++i)
         {
-        x += all_columns().at(col).col_width();
+        x += all_columns().at(i).col_width();
         }
 
     return x;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]