[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0ec27b7 3/4: Transplant a useful class out of
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0ec27b7 3/4: Transplant a useful class out of a unit test |
Date: |
Fri, 21 Sep 2018 17:22:38 -0400 (EDT) |
branch: master
commit 0ec27b754503541ffacc1dadf3c8354c1093913b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Transplant a useful class out of a unit test
Do use 'git diff --color-moved=plain' to review the diffs.
---
report_table.cpp | 45 +++++++++++++++++++++++++++++
report_table.hpp | 33 ++++++++++++++++++++++
report_table_test.cpp | 78 ---------------------------------------------------
3 files changed, 78 insertions(+), 78 deletions(-)
diff --git a/report_table.cpp b/report_table.cpp
index 9a8e76e..bbd6006 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -236,3 +236,48 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
page_count_ = 1;
}
}
+
+int paginate::init(int total_rows, int rows_per_group, int max_lines_per_page)
+{
+ total_rows_ = total_rows ;
+ rows_per_group_ = rows_per_group ;
+
+ paginator p(total_rows, rows_per_group, max_lines_per_page);
+ lines_on_full_page_ = p.lines_on_full_page();
+ lines_on_last_page_ = p.lines_on_last_page();
+ page_count_ = p.page_count();
+
+ return page_count_;
+}
+
+void paginate::print()
+{
+ prelude();
+ int row = 0;
+ int line_count = 0;
+ for(int page = 0; page < page_count(); ++page)
+ {
+ int const max_lines =
+ ((page_count() - 1) == page)
+ ? lines_on_last_page()
+ : lines_on_full_page()
+ ;
+ open_page();
+ for(int line = 0; line < max_lines; ++line)
+ {
+ if(rows_per_group() != line % (1 + rows_per_group()))
+ {
+ print_a_data_row();
+ ++row;
+ }
+ else
+ {
+ print_a_separator();
+ }
+ ++line_count;
+ }
+ close_page();
+ }
+ postlude();
+ LMI_ASSERT(total_rows() == row);
+}
diff --git a/report_table.hpp b/report_table.hpp
index cf768d5..287431e 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -169,4 +169,37 @@ class LMI_SO paginator
int page_count_;
};
+class LMI_SO paginate
+{
+ public:
+ paginate() {}
+
+ int init(int total_rows, int rows_per_group, int max_lines_per_page);
+ void print();
+
+ private:
+ virtual void prelude () = 0;
+ virtual void open_page () = 0;
+ virtual void print_a_data_row () = 0;
+ virtual void print_a_separator() = 0;
+ virtual void close_page () = 0;
+ virtual void postlude () = 0;
+
+ int total_rows () const {return total_rows_ ;}
+ int rows_per_group () const {return rows_per_group_ ;}
+
+ 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_ ;}
+
+ // init() arguments.
+ int total_rows_ {};
+ int rows_per_group_ {};
+
+ // init() results.
+ int lines_on_full_page_ {};
+ int lines_on_last_page_ {};
+ int page_count_ {};
+};
+
#endif // report_table_hpp
diff --git a/report_table_test.cpp b/report_table_test.cpp
index 84d2562..88fc461 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -401,84 +401,6 @@ void
report_table_test::test_column_widths_for_illustrations()
}
}
-class /* LMI_SO */ paginate
-{
- public:
- paginate() {}
-
- int init(int total_rows, int rows_per_group, int max_lines_per_page);
- void print();
-
- private:
- virtual void prelude () = 0;
- virtual void open_page () = 0;
- virtual void print_a_data_row () = 0;
- virtual void print_a_separator() = 0;
- virtual void close_page () = 0;
- virtual void postlude () = 0;
-
- int total_rows () const {return total_rows_ ;}
- int rows_per_group () const {return rows_per_group_ ;}
-
- 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_ ;}
-
- // init() arguments.
- int total_rows_ {};
- int rows_per_group_ {};
-
- // init() results.
- int lines_on_full_page_ {};
- int lines_on_last_page_ {};
- int page_count_ {};
-};
-
-int paginate::init(int total_rows, int rows_per_group, int max_lines_per_page)
-{
- total_rows_ = total_rows ;
- rows_per_group_ = rows_per_group ;
-
- paginator p(total_rows, rows_per_group, max_lines_per_page);
- lines_on_full_page_ = p.lines_on_full_page();
- lines_on_last_page_ = p.lines_on_last_page();
- page_count_ = p.page_count();
-
- return page_count_;
-}
-
-void paginate::print()
-{
- prelude();
- int row = 0;
- int line_count = 0;
- for(int page = 0; page < page_count(); ++page)
- {
- int const max_lines =
- ((page_count() - 1) == page)
- ? lines_on_last_page()
- : lines_on_full_page()
- ;
- open_page();
- for(int line = 0; line < max_lines; ++line)
- {
- if(rows_per_group() != line % (1 + rows_per_group()))
- {
- print_a_data_row();
- ++row;
- }
- else
- {
- print_a_separator();
- }
- ++line_count;
- }
- close_page();
- }
- postlude();
- LMI_ASSERT(total_rows() == row);
-}
-
class paginate_demo : public paginate
{
public: