[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a873fa4 4/6: Introduce additional paginator d
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a873fa4 4/6: Introduce additional paginator data members |
Date: |
Fri, 7 Sep 2018 19:33:54 -0400 (EDT) |
branch: master
commit a873fa4900e439818694ef99619a39a9b05e4e40
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Introduce additional paginator data members
The exact number of lines on the last page is not yet calculated.
---
report_table.cpp | 5 ++++-
report_table.hpp | 21 ++++++++++++++++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/report_table.cpp b/report_table.cpp
index 807c9e5..9ef9522 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -193,6 +193,9 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
// "+ 1": no blank-line separator after the last group.
,groups_per_page_ {(max_lines_per_page_ + 1) / lines_per_group_}
,rows_per_page_ {rows_per_group_ * groups_per_page_}
+ // "-1 +": no blank-line separator after the last group.
+ ,lines_on_full_page_ {-1 + lines_per_group_ * groups_per_page_}
+ ,lines_on_last_page_ {lines_on_full_page_}
,page_count_ {1}
{
LMI_ASSERT(0 <= total_rows);
@@ -211,7 +214,7 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
int const rows_on_last_page = total_rows_ - (page_count_ - 1) *
rows_per_page_;
// Avoid widowing a partial group on the last page, by moving it
- // to the preceding page if there's room.
+ // to the preceding page (which becomes the last) if there's room.
if(1 < page_count_)
{
int const free_lines = max_lines_per_page_ - lines_per_group_ *
groups_per_page_;
diff --git a/report_table.hpp b/report_table.hpp
index b548cf2..cf768d5 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -106,8 +106,19 @@ std::vector<int> LMI_SO set_column_widths
/// Display table rows in groups separated by blank lines.
///
/// Nomenclature:
-/// - a 'line' is a printable zone of unit height;
-/// - a 'row' is a series of data to be shown side by side.
+/// - A 'line' is a printable zone of unit height.
+/// - A 'row' is a series of data to be shown side by side.
+/// - A 'full' page has as many complete groups of rows as can fit,
+/// and nothing more. All pages except the last are always full;
+/// the last may also happen to be full.
+/// - The 'last' page is the one with the highest page number. It may
+/// have exactly as many rows as any 'full' page (if the cardinality
+/// of the data is congruent to zero (mod rows_per_group)); or
+/// fewer, as is naturally most common; or more, if a final partial
+/// group is displayed on the last page to avoid widowing.
+/// If a table prints on a single page, then the first is a 'last'
+/// page; it may or may not be full.
+///
/// With quinquennial spacing, the Morse alphabet is printed thus:
///
/// A .- line 0 row 0
@@ -139,7 +150,9 @@ class LMI_SO paginator
public:
paginator(int total_rows, int rows_per_group, int max_lines_per_page);
- int page_count() const {return page_count_;}
+ int lines_on_full_page() const {return lines_on_full_page_;}
+ int lines_on_last_page() const {return lines_on_last_page_;}
+ int page_count () const {return page_count_ ;}
private:
// Ctor arguments.
@@ -151,6 +164,8 @@ class LMI_SO paginator
int const lines_per_group_;
int const groups_per_page_;
int const rows_per_page_;
+ int const lines_on_full_page_;
+ int lines_on_last_page_;
int page_count_;
};
- [lmi-commits] [lmi] master updated (7376c94 -> f27b89f), Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master 033d6b6 2/6: Avoid 'auto' where it is not helpful, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master 2207a63 3/6: Refactor: move one line, for a reason soon to be revealed, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master ef971ec 1/6: Move test_main function to end where it belongs, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master baa8825 5/6: Calculate the exact number of lines on the last page, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master a873fa4 4/6: Introduce additional paginator data members,
Greg Chicares <=
- [lmi-commits] [lmi] master f27b89f 6/6: Demonstrate pagination with the simplest possible control structure, Greg Chicares, 2018/09/07