[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d17155c 6/6: Reimplement column_value_varies_
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d17155c 6/6: Reimplement column_value_varies_across_cells() |
Date: |
Tue, 12 Jun 2018 17:50:20 -0400 (EDT) |
branch: master
commit d17155c7048d5c89531c27fc74d4607b1a1eca6a
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Reimplement column_value_varies_across_cells()
The only sensible use case is to test whether any class default or any
cell has a different value than the case default for the given column.
To achieve that, the function had to be called twice--once for classes,
and once for cells--but it was called incorrectly in one of the two
cases where it was used. The documentation reflected the sensible
intention, and was therefore wrong.
Reimplemented the function. Incidentally used a more descriptive name
for an entity specified by a for-range-declaration's declarator (it
would be nice to have a shorter technical term for such a thing), and
replaced !(x==y) by x!=y. Left the old implementation in place for the
moment only to assert that new and old are equivalent.
---
census_view.cpp | 38 +++++++++++++++++++++++++++++++-------
census_view.hpp | 2 ++
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/census_view.cpp b/census_view.cpp
index 3e4aa35..0b252f9 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -981,6 +981,33 @@ Input* CensusView::class_parms_from_class_name(std::string
const& class_name)
/// would not all be identical--i.e. because at least one cell or one
/// class default differs from the case default wrt that column.
+bool CensusView::column_value_varies_across_cells(std::string const& header)
const
+{
+ bool const old =
+ ( column_value_varies_across_cells(header, class_parms())
+ || column_value_varies_across_cells(header, cell_parms ())
+ );
+ auto const z = case_parms()[0][header];
+ for(auto const& j : class_parms())
+ {
+ if(z != j[header])
+ {
+ LMI_ASSERT(true == old);
+ return true;
+ }
+ }
+ for(auto const& j : cell_parms())
+ {
+ if(z != j[header])
+ {
+ LMI_ASSERT(true == old);
+ return true;
+ }
+ }
+ LMI_ASSERT(false == old);
+ return false;
+}
+
bool CensusView::column_value_varies_across_cells
(std::string const& header
,std::vector<Input> const& cells
@@ -1210,13 +1237,10 @@ void CensusView::update_visible_columns()
// wrt some column, we respect that conscious decision.
std::vector<std::string> const&
all_headers(case_parms()[0].member_names());
int column = 0;
- for(auto const& i : all_headers)
+ for(auto const& header : all_headers)
{
++column;
- if
- ( column_value_varies_across_cells(i, class_parms())
- || column_value_varies_across_cells(i, cell_parms ())
- )
+ if(column_value_varies_across_cells(header))
{
any_member<Input> const& representative_value =
list_model_->cell_at(0, column);
@@ -1225,7 +1249,7 @@ void CensusView::update_visible_columns()
list_window_->AppendColumn
(new(wx) wxDataViewColumn
- (insert_spaces_between_words(i)
+ (insert_spaces_between_words(header)
,renderer
,column
,width
@@ -1821,7 +1845,7 @@ void CensusView::DoPasteCensusOut() const
std::vector<std::string> const&
all_headers(case_parms()[0].member_names());
for(auto const& header : all_headers)
{
- if(column_value_varies_across_cells(header, cell_parms()))
+ if(column_value_varies_across_cells(header))
{
if(header != "UseDOB" && header != "IssueAge")
{
diff --git a/census_view.hpp b/census_view.hpp
index af2fb47..fccafb5 100644
--- a/census_view.hpp
+++ b/census_view.hpp
@@ -111,6 +111,8 @@ class CensusView final
std::string class_name_from_cell_number(int) const;
Input* class_parms_from_class_name(std::string const&);
+ bool column_value_varies_across_cells(std::string const& header) const;
+ // retained for the nonce, for testing only:
bool column_value_varies_across_cells
(std::string const& header
,std::vector<Input> const& cells
- [lmi-commits] [lmi] master updated (a80dbb6 -> d17155c), Greg Chicares, 2018/06/12
- [lmi-commits] [lmi] master 270d295 1/6: Purge a vestige of unsignedness from a comment, Greg Chicares, 2018/06/12
- [lmi-commits] [lmi] master 31377a0 3/6: Improve documentation, Greg Chicares, 2018/06/12
- [lmi-commits] [lmi] master dd0e779 2/6: Move and rename a member function, Greg Chicares, 2018/06/12
- [lmi-commits] [lmi] master d17155c 6/6: Reimplement column_value_varies_across_cells(),
Greg Chicares <=
- [lmi-commits] [lmi] master c9d6ebc 5/6: Add UponPasteCensusOut() to event table, Greg Chicares, 2018/06/12
- [lmi-commits] [lmi] master 8fc8f97 4/6: Rename a member function, Greg Chicares, 2018/06/12