lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master f1c185c 2/4: Replace certain local variables


From: Greg Chicares
Subject: [lmi-commits] [lmi] master f1c185c 2/4: Replace certain local variables with data members
Date: Wed, 5 Sep 2018 20:56:27 -0400 (EDT)

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

    Replace certain local variables with data members
    
    This begins a series of commits that demonstrates design tradeoffs.
    
    This commit is desirable because it makes the results of intermediate
    calculations available to new member functions that may be added later,
    and, if const accessors are added, to clients of class paginator--yet
    one must rue the loss of constness.
---
 report_table.cpp | 12 ++++++------
 report_table.hpp |  5 +++++
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/report_table.cpp b/report_table.cpp
index b65bc83..91e7651 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -195,21 +195,21 @@ paginator::paginator(int total_rows, int rows_per_group, 
int max_lines_per_page)
         }
 
     // "+ 1": blank-line separator after each group.
-    int const lines_per_group = rows_per_group_ + 1;
+    lines_per_group_ = rows_per_group_ + 1;
 
     // "+ 1": no blank-line separator after the last group.
-    int const groups_per_page = (max_lines_per_page_ + 1) / lines_per_group;
+    groups_per_page_ = (max_lines_per_page_ + 1) / lines_per_group_;
 
-    int const rows_per_page = rows_per_group_ * groups_per_page;
+    rows_per_page_ = rows_per_group_ * groups_per_page_;
 
-    page_count_ = outward_quotient(total_rows_, rows_per_page);
+    page_count_ = outward_quotient(total_rows_, rows_per_page_);
 
     // Avoid widowing a partial group on the last page, by moving it
     // to the preceding page if there's room.
     if(1 < page_count_)
         {
-        auto const rows_on_last_page = total_rows_ - (page_count_ - 1) * 
rows_per_page;
-        auto const free_lines = max_lines_per_page_ - lines_per_group * 
groups_per_page;
+        auto const rows_on_last_page = total_rows_ - (page_count_ - 1) * 
rows_per_page_;
+        auto const free_lines = max_lines_per_page_ - lines_per_group_ * 
groups_per_page_;
         LMI_ASSERT(free_lines < rows_per_group_);
         if(rows_on_last_page <= free_lines)
             {
diff --git a/report_table.hpp b/report_table.hpp
index d08b058..ace4c2b 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -142,10 +142,15 @@ class LMI_SO paginator
     int page_count() const {return page_count_;}
 
   private:
+    // Ctor arguments.
     int const total_rows_;
     int const rows_per_group_;
     int const max_lines_per_page_;
 
+    // Internals in dependency order.
+    int /* const */ lines_per_group_;
+    int /* const */ groups_per_page_;
+    int /* const */ rows_per_page_;
     int page_count_;
 };
 



reply via email to

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