[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master ea25cc6 4/4: Generally prefer 'int' to 'size_
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master ea25cc6 4/4: Generally prefer 'int' to 'size_t' |
Date: |
Wed, 26 Sep 2018 19:35:14 -0400 (EDT) |
branch: master
commit ea25cc65b145ef454d2200cf1a2d9107b26538de
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Generally prefer 'int' to 'size_t'
---
group_quote_pdf_gen_wx.cpp | 4 +-
istream_to_string_test.cpp | 1 +
ledger_evaluator.cpp | 2 +-
ledger_evaluator.hpp | 3 +-
ledger_pdf_generator_wx.cpp | 26 ++++++------
loads_test.cpp | 92 ++++++++++++++++++++---------------------
miscellany.cpp | 3 +-
preferences_model.cpp | 6 +--
print_matrix.hpp | 14 +++----
wx_table_generator.cpp | 38 +++++++----------
wx_table_generator.hpp | 21 ++++------
wx_test_calculation_summary.cpp | 10 ++---
wx_test_input_validation.cpp | 3 +-
wx_test_paste_census.cpp | 26 +++++++-----
wx_utility.cpp | 3 +-
15 files changed, 122 insertions(+), 130 deletions(-)
diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index af89bd3..1142de9 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -956,14 +956,14 @@ void group_quote_pdf_generator_wx::output_document_header
fields.insert(fields.end(), f.begin(), f.end());
text fields_html;
- for(std::size_t i = 0; i < fields.size(); i += 2)
+ for(int i = 0; i < lmi::ssize(fields); i += 2)
{
auto row_html = name_value_as_html_table_data
(fields[i].name, fields[i].value
)
;
- if(i + 1 < fields.size())
+ if(i + 1 < lmi::ssize(fields))
{
row_html += name_value_as_html_table_data
(fields[i + 1].name, fields[i + 1].value
diff --git a/istream_to_string_test.cpp b/istream_to_string_test.cpp
index 2bd189a..0163d0a 100644
--- a/istream_to_string_test.cpp
+++ b/istream_to_string_test.cpp
@@ -27,6 +27,7 @@
#include "test_tools.hpp"
#include "timer.hpp"
+#include <cstddef> // size_t
#include <cstdio>
#include <fstream>
#include <iterator> // istreambuf_iterator
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 32afed2..8f6fbbe 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -135,7 +135,7 @@ std::string ledger_evaluator::operator()(std::string const&
scalar) const
std::string ledger_evaluator::operator()
(std::string const& vector
- ,std::size_t index
+ ,int index
) const
{
return map_lookup(vectors_, vector).at(index);
diff --git a/ledger_evaluator.hpp b/ledger_evaluator.hpp
index 3f0d612..40dc882 100644
--- a/ledger_evaluator.hpp
+++ b/ledger_evaluator.hpp
@@ -26,7 +26,6 @@
#include "so_attributes.hpp"
-#include <cstddef> // size_t
#include <string>
#include <unordered_map>
#include <vector>
@@ -44,7 +43,7 @@ class LMI_SO ledger_evaluator
public:
std::string operator()(std::string const& scalar) const;
- std::string operator()(std::string const& vector, std::size_t index) const;
+ std::string operator()(std::string const& vector, int index) const;
private:
// Constructible only by friends: see Ledger::make_evaluator().
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index aa6c47b..eb4e2e3 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -51,7 +51,6 @@
#include <wx/html/m_templ.h>
#include <array>
-#include <cstddef> // size_t
#include <cstdint> // SIZE_MAX
#include <cstdlib> // strtoul()
#include <exception> // uncaught_exceptions()
@@ -227,7 +226,7 @@ class html_interpolator
}
// Return a single value of a vector variable.
- std::string evaluate(std::string const& name, std::size_t index) const
+ std::string evaluate(std::string const& name, int index) const
{
return evaluator_(name, index);
}
@@ -282,7 +281,7 @@ class html_interpolator
return html::text::from
(evaluator_
(s.substr(0, open_pos)
- ,static_cast<std::size_t>(index)
+ ,bourn_cast<int>(index)
)
);
}
@@ -837,9 +836,10 @@ class pdf_illustration : protected html_interpolator,
protected pdf_writer_wx
pdf_writer_wx & get_writer () {return *this;}
// Helper for abbreviating a string to at most the given length (in bytes).
- static std::string abbreviate_if_necessary(std::string s, std::size_t len)
+ static std::string abbreviate_if_necessary(std::string s, int len)
{
- if(len < s.length() && 3 < len)
+ LMI_ASSERT(3 < len && len < 1000); // Implausible otherwise.
+ if(len < lmi::ssize(s) && 3 < len)
{
s.replace(len - 3, std::string::npos, "...");
}
@@ -851,7 +851,7 @@ class pdf_illustration : protected html_interpolator,
protected pdf_writer_wx
// variables have the name based on the name of the original variable with
// "Abbrev" and "len" appended to it and their value is at most "len" bytes
// long.
- void add_abbreviated_variable(std::string const& var, std::size_t len)
+ void add_abbreviated_variable(std::string const& var, int len)
{
add_variable
(var + "Abbrev" + std::to_string(len)
@@ -913,7 +913,7 @@ class pdf_illustration : protected html_interpolator,
protected pdf_writer_wx
,!invar.ContractNumber.empty()
);
- std::size_t const full_abbrev_length = 30;
+ int const full_abbrev_length = 30;
add_abbreviated_variable("MasterContractNumber", full_abbrev_length);
add_abbreviated_variable("MasterContractNumber", full_abbrev_length /
2);
add_abbreviated_variable("ContractNumber", full_abbrev_length);
@@ -2112,11 +2112,11 @@ class standard_supplemental_report : public
page_with_tabular_report
(html_interpolator const& interpolator
)
{
- constexpr std::size_t max_columns = 12;
+ constexpr int max_columns = 12;
std::string const empty_column_name("[none]");
illustration_table_columns columns;
- for(std::size_t i = 0; i < max_columns; ++i)
+ for(int i = 0; i < max_columns; ++i)
{
auto name =
interpolator.evaluate("SupplementalReportColumnsNames", i);
if(name != empty_column_name)
@@ -2444,12 +2444,12 @@ class page_with_basic_tabular_report : public
page_with_tabular_report
// declare a const reference to it?
auto const& z = interpolator_;
auto const output_two_column_super_header = [=,&table_gen]
- (basis guar_or_curr
- ,interest_rate zero_or_not
- ,std::size_t begin_column
+ (basis guar_or_curr
+ ,interest_rate zero_or_not
+ ,int begin_column
) -> int
{
- std::size_t end_column = begin_column + 2;
+ int end_column = begin_column + 2;
LMI_ASSERT(end_column <= column_max);
auto y = pos_y;
diff --git a/loads_test.cpp b/loads_test.cpp
index 206db95..492688c 100644
--- a/loads_test.cpp
+++ b/loads_test.cpp
@@ -27,10 +27,10 @@
#include "materially_equal.hpp"
#include "oecumenic_enumerations.hpp"
#include "round_to.hpp"
+#include "ssize_lmi.hpp"
#include "test_tools.hpp"
#include "timer.hpp"
-#include <cstddef> // size_t
#include <functional> // bind()
namespace
@@ -108,51 +108,51 @@ void LoadsTest::Reinitialize()
void LoadsTest::TestVectorLengths(char const* file, int line)
{
- std::size_t const z = details_.length_;
-
- INVOKE_BOOST_TEST_EQUAL(z, loads_.refundable_sales_load_proportion
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.premium_tax_load
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.amortized_premium_tax_load
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.dac_tax_load
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z,
loads_.target_premium_load_excluding_premium_tax().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z,
loads_.excess_premium_load_excluding_premium_tax().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_premium_load_maximum_premium_tax
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_premium_load_maximum_premium_tax
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_premium_load_minimum_premium_tax
().size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_premium_load_minimum_premium_tax
().size(), file, line);
-
- INVOKE_BOOST_TEST_EQUAL(z, loads_.monthly_policy_fee
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.annual_policy_fee
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.specified_amount_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.separate_account_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_premium_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_premium_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_sales_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_sales_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_total_load
(mce_gen_curr).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_total_load
(mce_gen_curr).size(), file, line);
-
- INVOKE_BOOST_TEST_EQUAL(z, loads_.monthly_policy_fee
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.annual_policy_fee
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.specified_amount_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.separate_account_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_premium_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_premium_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_sales_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_sales_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_total_load
(mce_gen_guar).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_total_load
(mce_gen_guar).size(), file, line);
-
- INVOKE_BOOST_TEST_EQUAL(z, loads_.monthly_policy_fee
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.annual_policy_fee
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.specified_amount_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.separate_account_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_premium_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_premium_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_sales_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_sales_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.target_total_load
(mce_gen_mdpt).size(), file, line);
- INVOKE_BOOST_TEST_EQUAL(z, loads_.excess_total_load
(mce_gen_mdpt).size(), file, line);
+ int const z = details_.length_;
+
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.refundable_sales_load_proportion ()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.premium_tax_load
()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.amortized_premium_tax_load
()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.dac_tax_load
()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.target_premium_load_excluding_premium_tax()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.excess_premium_load_excluding_premium_tax()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.target_premium_load_maximum_premium_tax ()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.excess_premium_load_maximum_premium_tax ()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.target_premium_load_minimum_premium_tax ()), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z,
lmi::ssize(loads_.excess_premium_load_minimum_premium_tax ()), file, line);
+
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.monthly_policy_fee
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.annual_policy_fee
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.specified_amount_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.separate_account_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_premium_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_premium_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_sales_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_sales_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_total_load
(mce_gen_curr)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_total_load
(mce_gen_curr)), file, line);
+
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.monthly_policy_fee
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.annual_policy_fee
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.specified_amount_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.separate_account_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_premium_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_premium_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_sales_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_sales_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_total_load
(mce_gen_guar)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_total_load
(mce_gen_guar)), file, line);
+
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.monthly_policy_fee
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.annual_policy_fee
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.specified_amount_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.separate_account_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_premium_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_premium_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_sales_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_sales_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.target_total_load
(mce_gen_mdpt)), file, line);
+ INVOKE_BOOST_TEST_EQUAL(z, lmi::ssize(loads_.excess_total_load
(mce_gen_mdpt)), file, line);
}
void LoadsTest::TestCalculations(char const* file, int line)
diff --git a/miscellany.cpp b/miscellany.cpp
index 4be7039..16fe2a7 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -25,6 +25,7 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
+#include "bourn_cast.hpp"
#include "ssize_lmi.hpp"
#include <algorithm> // equal(), max()
@@ -159,7 +160,7 @@ int scale_power(int max_power, double min_value, double
max_value)
int count_newlines(std::string const& s)
{
- return std::count(s.begin(), s.end(), '\n');
+ return bourn_cast<int>(std::count(s.begin(), s.end(), '\n'));
}
/// Split an internally-newline-delimited string into lines.
diff --git a/preferences_model.cpp b/preferences_model.cpp
index 9e11d3a..4689a15 100644
--- a/preferences_model.cpp
+++ b/preferences_model.cpp
@@ -26,12 +26,12 @@
#include "alert.hpp"
#include "configurable_settings.hpp"
#include "miscellany.hpp" // begins_with()
+#include "ssize_lmi.hpp"
#include "value_cast.hpp"
#include <boost/filesystem/operations.hpp> // fs::system_complete()
#include <boost/filesystem/path.hpp>
-#include <cstddef> // size_t
#include <sstream>
#include <vector>
@@ -251,14 +251,14 @@ void PreferencesModel::Load()
configurable_settings const& z = configurable_settings::instance();
std::vector<std::string> columns(input_calculation_summary_columns());
- for(std::size_t i = 0; i < member_names().size(); ++i)
+ for(int i = 0; i < lmi::ssize(member_names()); ++i)
{
std::string const& name = member_names()[i];
if(!is_calculation_summary_column_name(name))
{
continue;
}
- if(columns.size() <= i)
+ if(lmi::ssize(columns) <= i)
{
operator[](name) = empty_column_name;
}
diff --git a/print_matrix.hpp b/print_matrix.hpp
index 504381b..d217e1e 100644
--- a/print_matrix.hpp
+++ b/print_matrix.hpp
@@ -25,10 +25,10 @@
#include "config.hpp"
#include "assert_lmi.hpp"
+#include "ssize_lmi.hpp"
#include "value_cast.hpp"
#include <algorithm>
-#include <cstddef> // size_t
#include <functional>
#include <iterator> // back_inserter()
#include <numeric>
@@ -74,7 +74,7 @@ void print_matrix
,std::vector<int> const& dimensions
)
{
- std::vector<std::size_t> nonempty_dimensions;
+ std::vector<int> nonempty_dimensions;
std::remove_copy
(dimensions.begin()
,dimensions.end()
@@ -82,19 +82,19 @@ void print_matrix
,1
);
- std::vector<std::size_t> moduli(nonempty_dimensions.size());
+ std::vector<int> moduli(nonempty_dimensions.size());
std::partial_sum
(nonempty_dimensions.rbegin()
,nonempty_dimensions.rend()
,moduli.rbegin()
- ,std::multiplies<std::size_t>()
+ ,std::multiplies<int>()
);
- LMI_ASSERT(1 == data.size() || moduli.front() == data.size());
+ LMI_ASSERT(1 == lmi::ssize(data) || moduli.front() == lmi::ssize(data));
- for(std::size_t j = 0; j < data.size(); ++j)
+ for(int j = 0; j < lmi::ssize(data); ++j)
{
os << '\t' << value_cast<std::string>(data[j]);
- for(std::size_t k = 0; k < moduli.size(); ++k)
+ for(int k = 0; k < lmi::ssize(moduli); ++k)
{
if(0 == (1 + j) % moduli[k])
{
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index 4ec91b8..7c6fca0 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -174,16 +174,16 @@ void wx_table_generator::output_headers
// Split headers in single lines and fill up the entire columns*lines 2D
// matrix, using empty strings for the headers with less than the maximal
// number of lines.
- std::size_t const number_of_columns = all_columns().size();
+ int const number_of_columns = lmi::ssize(all_columns());
std::vector<std::string> headers_by_line(max_header_lines_ *
number_of_columns);
- for(std::size_t i = 0; i < number_of_columns; ++i)
+ for(int i = 0; i < number_of_columns; ++i)
{
// Fill the elements from the bottom line to the top one, so that a
// single line header is shown on the last line.
table_column_info const& ci = all_columns().at(i);
std::vector<std::string> const
lines(split_into_lines(ci.col_header()));
- std::size_t const first_line = max_header_lines_ - lines.size();
- for(std::size_t j = 0; j < lines.size(); ++j)
+ int const first_line = max_header_lines_ - lmi::ssize(lines);
+ for(int j = 0; j < lmi::ssize(lines); ++j)
{
headers_by_line.at
((first_line + j) * number_of_columns + i
@@ -194,7 +194,7 @@ void wx_table_generator::output_headers
// And output all lines of all column headers.
int y_top = pos_y;
int x = 0;
- for(std::size_t i = 0; i < max_header_lines_; ++i)
+ for(int i = 0; i < max_header_lines_; ++i)
{
std::vector<std::string> const nth_line
(headers_by_line.begin() + i * number_of_columns
@@ -222,8 +222,8 @@ void wx_table_generator::output_headers
void wx_table_generator::output_super_header
(std::string const& header
- ,std::size_t a_begin_column
- ,std::size_t a_end_column
+ ,int a_begin_column
+ ,int a_end_column
,int& pos_y
,oenum_render_or_only_measure output_mode
)
@@ -259,7 +259,7 @@ void wx_table_generator::output_super_header
/// Shade the background of a single cell; center the given contents.
void wx_table_generator::output_highlighted_cell
- (std::size_t a_column
+ (int a_column
,int y
,std::string const& value
)
@@ -304,10 +304,7 @@ void wx_table_generator::output_row
/// If the column index equals the number of columns, output a
/// separator after the last column.
-void wx_table_generator::output_vert_separator
- (std::size_t a_before_column
- ,int y
- )
+void wx_table_generator::output_vert_separator(int a_before_column, int y)
{
int before_column = indices_[a_before_column];
@@ -321,8 +318,8 @@ void wx_table_generator::output_vert_separator
/// The column range is specified as [begin, end), as is usual in C++.
void wx_table_generator::output_horz_separator
- (std::size_t a_begin_column
- ,std::size_t a_end_column
+ (int a_begin_column
+ ,int a_end_column
,int y
,oenum_render_or_only_measure output_mode
)
@@ -368,7 +365,7 @@ int wx_table_generator::separator_line_height() const
return row_height() / 2;
}
-wxRect wx_table_generator::external_text_rect(std::size_t a_column, int y)
const
+wxRect wx_table_generator::external_text_rect(int a_column, int y) const
{
int column = indices_[a_column];
return text_rect(column, y);
@@ -418,13 +415,10 @@ void wx_table_generator::enroll_column(column_parameters
const& z)
dc().GetMultiLineTextExtent(z.header, &w, &h, &lh, &dc().GetFont());
LMI_ASSERT(0 != lh);
LMI_ASSERT(0 == h % lh);
-// Temporarily assert that this does the same as the code it replaced:
-LMI_ASSERT(h / lh == int(1u + count_newlines(z.header)));
-// Check it again because of the unfortunate mixed-mode arithmetic:
-LMI_ASSERT(std::size_t(h / lh) == 1u + count_newlines(z.header));
+ LMI_ASSERT(h / lh == int(1u + count_newlines(z.header)));
// Store number of lines used by tallest header:
// output_headers() uses it to write all headers as a block.
- max_header_lines_ = std::max(max_header_lines_, std::size_t(h / lh));
+ max_header_lines_ = std::max(max_header_lines_, h / lh);
switch(z.elasticity)
{
@@ -460,8 +454,8 @@ void wx_table_generator::do_output_single_row
do_output_vert_separator(pos_x, y_top, pos_y);
}
- std::size_t const number_of_columns = all_columns().size();
- for(std::size_t i = 0; i < number_of_columns; ++i)
+ int const number_of_columns = lmi::ssize(all_columns());
+ for(int i = 0; i < number_of_columns; ++i)
{
table_column_info const& ci = all_columns().at(i);
std::string const& s = values[i];
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index 58ec6b6..19814fa 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -30,7 +30,6 @@
#include <wx/dc.h>
#include <wx/font.h>
-#include <cstddef> // size_t
#include <string>
#include <vector>
@@ -99,24 +98,20 @@ class wx_table_generator
void output_super_header
(std::string const& header
- ,std::size_t a_begin_column
- ,std::size_t a_end_column
+ ,int a_begin_column
+ ,int a_end_column
,int& pos_y
,oenum_render_or_only_measure output_mode = oe_render
);
- void output_highlighted_cell
- (std::size_t a_column
- ,int y
- ,std::string const& value
- );
+ void output_highlighted_cell(int a_column, int y, std::string const&
value);
void output_row(int& pos_y, std::vector<std::string> const values);
- void output_vert_separator(std::size_t a_before_column, int y);
+ void output_vert_separator(int a_before_column, int y);
void output_horz_separator
- (std::size_t a_begin_column
- ,std::size_t a_end_column
+ (int a_begin_column
+ ,int a_end_column
,int y
,oenum_render_or_only_measure output_mode = oe_render
);
@@ -127,7 +122,7 @@ class wx_table_generator
// Used only by group_quote_pdf_generator_wx::output_aggregate_values(),
// in a context where something like output_highlighted_cell() should
// probably be used instead. PDF !! revisit this later
- wxRect external_text_rect(std::size_t a_column, int y) const;
+ wxRect external_text_rect(int a_column, int y) const;
private:
void enroll_column(column_parameters const&);
@@ -170,7 +165,7 @@ class wx_table_generator
// Maximal number of lines in any column header, initially 1 but can be
// higher if multiline headers are used.
- std::size_t max_header_lines_;
+ int max_header_lines_;
// If false, separator lines are not drawn automatically (they can still be
// drawn by calling output_horz_separator() or output_vert_separator()
diff --git a/wx_test_calculation_summary.cpp b/wx_test_calculation_summary.cpp
index a9308fb..e413b97 100644
--- a/wx_test_calculation_summary.cpp
+++ b/wx_test_calculation_summary.cpp
@@ -37,8 +37,6 @@
#include <wx/testing.h>
#include <wx/uiaction.h>
-#include <cstddef> // size_t
-
namespace
{
@@ -176,7 +174,7 @@ class expect_preferences_dialog_base
};
void check_calculation_summary_columns
- (std::size_t number_of_columns
+ (int number_of_columns
,name_and_title const columns_info[]
)
{
@@ -201,7 +199,7 @@ void check_calculation_summary_columns
ill.close();
// Find the start of the table after the separating line.
- std::size_t pos = html.find("<hr>\n<table");
+ auto pos = html.find("<hr>\n<table");
LMI_ASSERT(pos != wxString::npos);
pos = html.find("\n<td", pos);
@@ -211,7 +209,7 @@ void check_calculation_summary_columns
// We have found the place where the columns are described in the HTML,
// iterate over all of them.
- for(std::size_t n = 0; n < number_of_columns; ++n)
+ for(int n = 0; n < number_of_columns; ++n)
{
LMI_ASSERT_EQUAL(wxString(html, pos, 3), "<td");
@@ -220,7 +218,7 @@ void check_calculation_summary_columns
++pos; // <td> tag contents
- std::size_t const next = html.find("\n", pos); // the next line start
+ auto const next = html.find("\n", pos); // the next line start
LMI_ASSERT(next != wxString::npos);
// Extract the column title from the rest of the line.
diff --git a/wx_test_input_validation.cpp b/wx_test_input_validation.cpp
index 67e5c3e..5753e77 100644
--- a/wx_test_input_validation.cpp
+++ b/wx_test_input_validation.cpp
@@ -22,6 +22,7 @@
#include "pchfile_wx.hpp"
#include "assert_lmi.hpp"
+#include "bourn_cast.hpp"
#include "global_settings.hpp"
#include "mvc_controller.hpp"
#include "wx_test_case.hpp"
@@ -210,7 +211,7 @@ LMI_WX_TEST_CASE(input_validation)
// between the expected and actual errors more concise.
char const* const
error_prefix = "Input validation problems for '':\n";
- std::size_t error_prefix_len = std::strlen(error_prefix);
+ int error_prefix_len = bourn_cast<int>(std::strlen(error_prefix));
LMI_ASSERT_WITH_MSG
(error_message.substr(0, error_prefix_len) == error_prefix
diff --git a/wx_test_paste_census.cpp b/wx_test_paste_census.cpp
index a1a52d8..62c613d 100644
--- a/wx_test_paste_census.cpp
+++ b/wx_test_paste_census.cpp
@@ -225,14 +225,19 @@ LMI_WX_TEST_CASE(paste_census)
"Female\t19550625\tPresident\t700000, @65; 100000\n"
;
- std::size_t const number_of_rows = std::count
- (census_data
- ,census_data + std::strlen(census_data)
- ,'\n'
- )
+ int const number_of_rows =
+ bourn_cast<int>
+ (
+ std::count
+ (census_data
+ ,census_data + std::strlen(census_data)
+ ,'\n'
+ )
+ )
- 1 // Not counting the header.
- 1 // Nor the empty line after it.
;
+ LMI_ASSERT(0 < number_of_rows);
// Put the data to paste on clipboard.
ClipboardEx::SetText(census_data);
@@ -249,7 +254,7 @@ LMI_WX_TEST_CASE(paste_census)
// correctly.
wxDataViewCtrl* const list_window = find_census_list_window();
wxDataViewListModel* const list_model = get_census_list_model(list_window);
- LMI_ASSERT_EQUAL(list_model->GetCount(), number_of_rows);
+ LMI_ASSERT_EQUAL(bourn_cast<int>(list_model->GetCount()), number_of_rows);
check_list_columns
(list_window
@@ -332,12 +337,11 @@ LMI_WX_TEST_CASE(paste_census)
);
// Verify that the "Gender" column value is "Unisex" in every row now.
- int const
- gender_column = find_model_column_by_title(list_window, "Gender");
- LMI_ASSERT_EQUAL(list_model->GetCount(), number_of_rows);
+ int const gender_column = find_model_column_by_title(list_window,
"Gender");
+ LMI_ASSERT_EQUAL(bourn_cast<int>(list_model->GetCount()), number_of_rows);
// Only the first two rows are affected, because only they belong
// to the first employee class.
- for(std::size_t row = 0; row < 2; ++row)
+ for(int row = 0; row < 2; ++row)
{
wxVariant value;
list_model->GetValueByRow(value, row, gender_column);
@@ -395,7 +399,7 @@ LMI_WX_TEST_CASE(paste_census)
// Check that we still have the same cells but that now the underwriting
// class column has disappeared as its value has been fixed.
- LMI_ASSERT_EQUAL(list_model->GetCount(), number_of_rows);
+ LMI_ASSERT_EQUAL(bourn_cast<int>(list_model->GetCount()), number_of_rows);
column_titles.erase("Underwriting Class");
check_list_columns
diff --git a/wx_utility.cpp b/wx_utility.cpp
index 6bb9b60..d3adf83 100644
--- a/wx_utility.cpp
+++ b/wx_utility.cpp
@@ -42,7 +42,6 @@
#include <wx/utils.h> // wxSafeYield()
#include <wx/window.h>
-#include <cstddef> // size_t
#include <sstream>
/// Return whatever plain text the clipboard contains, or an empty
@@ -217,7 +216,7 @@ void TestDateConversions()
std::vector<std::string> EnumerateBookPageNames(wxBookCtrlBase const& book)
{
std::vector<std::string> z;
- for(std::size_t j = 0; j < book.GetPageCount(); ++j)
+ for(int j = 0; j < bourn_cast<int>(book.GetPageCount()); ++j)
{
std::string name(book.GetPageText(j).ToStdString(wxConvUTF8));
LMI_ASSERT(!contains(z, name));