[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master acda6c9 2/4: Proceed toward IoC by holding ub
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master acda6c9 2/4: Proceed toward IoC by holding ubiquitous arguments as members |
Date: |
Fri, 21 Sep 2018 20:00:22 -0400 (EDT) |
branch: master
commit acda6c9b649b74887f3d8ae1e08924ff6e3c346f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Proceed toward IoC by holding ubiquitous arguments as members
See the immediately preceding commit message. The ledger and pdf_writer
arguments that are passed to so many functions cannot be passed to
overrides of class paginator's virtuals, which take no arguments.
Arguably those arguments should be members of root class logical_page,
with protected accessors. The alternative, here, is moderately long-
distance friendship and a couple of const_casts. Another option, worse
than either of those, would be
virtual paginator::whatever(void* blob)
but that's mentioned only for completeness.
---
ledger_pdf_generator_wx.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 420b15c..db6b17c 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -739,6 +739,8 @@ class logical_page
// their contents.
class pdf_illustration : protected html_interpolator, protected pdf_writer_wx
{
+ friend class page_with_tabular_report;
+
public:
explicit pdf_illustration
(Ledger const& ledger
@@ -1774,7 +1776,15 @@ class page_with_tabular_report
,protected using_illustration_table
{
public:
- using numbered_page::numbered_page;
+ page_with_tabular_report
+ (pdf_illustration const& illustration
+ ,html_interpolator const& interpolate_html
+ )
+ :numbered_page{illustration, interpolate_html}
+ ,ledger_ (const_cast<pdf_illustration&>(illustration_).ledger_)
+ ,writer_ (const_cast<pdf_illustration&>(illustration_).get_writer())
+ {
+ }
/// Initialize a wx_table_generator.
///
@@ -1793,6 +1803,9 @@ class page_with_tabular_report
,pdf_writer_wx & writer
) override
{
+ // Assertions demonstrate identity of arguments and class members.
+ LMI_ASSERT(&ledger_ == &ledger);
+ LMI_ASSERT(&writer_ == &writer);
table_gen_.reset(new wx_table_generator
{create_table_generator(ledger, writer)});
numbered_page::pre_render(ledger, writer);
}
@@ -1938,7 +1951,9 @@ class page_with_tabular_report
return z.page_count() - 1;
}
- std::unique_ptr<wx_table_generator> table_gen_;
+ Ledger const& ledger_;
+ pdf_writer_wx & writer_;
+ std::unique_ptr<wx_table_generator> table_gen_;
};
class ill_reg_tabular_detail_page : public page_with_tabular_report