[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0d9d0ea 4/5: Improve encapsulation
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0d9d0ea 4/5: Improve encapsulation |
Date: |
Mon, 30 Jul 2018 07:23:16 -0400 (EDT) |
branch: master
commit 0d9d0eab6020e03b2525ef1d59685cb5fb67af55
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Improve encapsulation
Class wx_table_generator needs to know only the width of each column;
it has no business knowing how much of the width is marginal padding:
that is a separate concern of free function set_column_widths() only.
---
report_table.cpp | 8 ++++----
report_table.hpp | 2 +-
report_table_test.cpp | 19 +++++--------------
wx_table_generator.cpp | 11 ++---------
wx_table_generator.hpp | 2 --
5 files changed, 12 insertions(+), 30 deletions(-)
diff --git a/report_table.cpp b/report_table.cpp
index 53b68f7..f251536 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -42,13 +42,13 @@
void set_column_widths
(int total_width
- ,int & column_margin
+ ,int column_margin
,std::vector<table_column_info>& all_columns
)
//
-// const total_width max table width (page width - page margins)
-// mutable column_margin spacing on both left and right of column
-// mutable all_columns std::vector<table_column_info>
+// total_width max table width (page width - page margins)
+// column_margin spacing on both left and right of column
+// all_columns std::vector<table_column_info>
// table_column_info::col_width_ is the only member changed
{
// PDF !! Unconditionally add bilateral margins even though they
diff --git a/report_table.hpp b/report_table.hpp
index 9ba01c6..de3b773 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -113,7 +113,7 @@ class LMI_SO table_column_info
void LMI_SO set_column_widths
(int total_width
- ,int & column_margin
+ ,int column_margin
,std::vector<table_column_info>& all_columns
);
diff --git a/report_table_test.cpp b/report_table_test.cpp
index 87c8e44..186d6fc 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -74,9 +74,7 @@ void report_table_test::test_group_quote()
,{"", 67, oe_center, oe_shown, oe_inelastic}
};
- int margin = default_margin;
- set_column_widths(total_width, margin, v);
- BOOST_TEST_EQUAL(margin, default_margin);
+ set_column_widths(total_width, default_margin, v);
std::vector<int> const observed = widths(v);
std::vector<int> const expected = {36, 129, 52, 62, 78, 81, 78, 81, 78,
81};
@@ -103,9 +101,7 @@ void report_table_test::test_illustration()
,{"", 53, oe_right, oe_shown, oe_inelastic}
};
- int margin = default_margin;
- set_column_widths(total_width, margin, v);
- BOOST_TEST_EQUAL(margin, default_margin);
+ set_column_widths(total_width, default_margin, v);
std::vector<int> const observed = widths(v);
std::vector<int> const expected = {38, 52, 67, 66, 45, 62, 62, 67};
@@ -131,9 +127,7 @@ void report_table_test::test_illustration()
,{"", 50, oe_right, oe_shown, oe_inelastic}
};
- int margin = default_margin;
- set_column_widths(total_width, margin, v);
- BOOST_TEST_EQUAL(margin, 1);
+ set_column_widths(total_width, default_margin, v);
std::vector<int> const observed = widths(v);
std::vector<int> const expected = {30, 28, 54, 36, 54, 54, 54, 54, 53, 53,
53, 53};
@@ -159,13 +153,10 @@ void report_table_test::test_illustration()
,{"", 50, oe_right, oe_shown, oe_inelastic}
};
- int margin = default_margin;
std::cout << "[Expect a multiline..." << std::endl;
- set_column_widths(total_width, margin, v);
+ set_column_widths(total_width, default_margin, v);
std::cout << "...warning message.]" << std::endl;
- BOOST_TEST_EQUAL(margin, default_margin);
-
// Today, two times the default margin is added to each column,
// even though the data cannot fit.
std::vector<int> const observed = widths(v);
@@ -175,7 +166,7 @@ std::cout << "...warning message.]" << std::endl;
#if 0 // Doesn't throw today, but might someday.
BOOST_TEST_THROW
- (set_column_widths(total_width, margin, v)
+ (set_column_widths(total_width, default_margin, v)
,std::runtime_error
,"3 iterations expected, but only 0 completed."
);
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index e00e8c7..17bbc4a 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -45,7 +45,6 @@ wx_table_generator::wx_table_generator
// Arbitrarily use 1.333 line spacing.
,row_height_ ((4 * char_height_ + 2) / 3)
,one_em_ (dc_.GetTextExtent("M").x)
- ,column_margin_ (one_em_)
,max_header_lines_ (1)
,draw_separators_ (true)
,use_bold_headers_ (true)
@@ -54,7 +53,7 @@ wx_table_generator::wx_table_generator
{
enroll_column(i);
}
- set_column_widths(total_width_, column_margin_, all_columns_);
+ set_column_widths(total_width_, one_em_, all_columns_);
// Set a pen with zero width to make grid lines thin,
// and round cap style so that they combine seamlessly.
@@ -76,7 +75,6 @@ wx_table_generator::wx_table_generator
,char_height_ (dc_.GetCharHeight())
,row_height_ (char_height_)
,one_em_ (dc_.GetTextExtent("M").x)
- ,column_margin_ (one_em_)
,max_header_lines_ (1)
,draw_separators_ (false)
,use_bold_headers_ (false)
@@ -85,7 +83,7 @@ wx_table_generator::wx_table_generator
{
enroll_column(i);
}
- set_column_widths(total_width_, column_margin_, all_columns_);
+ set_column_widths(total_width_, one_em_, all_columns_);
dc_.SetPen(illustration_rule_color);
}
@@ -544,11 +542,6 @@ wxDC const& wx_table_generator::dc() const
return dc_;
}
-int wx_table_generator::column_margin() const
-{
- return column_margin_;
-}
-
std::vector<table_column_info> const& wx_table_generator::all_columns() const
{
return all_columns_;
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index 84d7f21..079a63e 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -146,7 +146,6 @@ class wx_table_generator
// Const private accessors. Used in the implementation to
// distinguish access from mutation.
wxDC const& dc() const;
- int column_margin() const;
std::vector<table_column_info> const& all_columns() const;
wxDC& dc_;
@@ -158,7 +157,6 @@ class wx_table_generator
int const char_height_;
int const row_height_;
int const one_em_;
- int column_margin_;
std::vector<table_column_info> all_columns_;