[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0c55621 085/156: Replace trivial PDF page cla
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0c55621 085/156: Replace trivial PDF page classes with single standard_page one |
Date: |
Tue, 30 Jan 2018 17:22:18 -0500 (EST) |
branch: master
commit 0c5562154f2186988c90e7d6208cd4857bfce63f
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Replace trivial PDF page classes with single standard_page one
Get rid of trivial classes such as narrative_summary_page for the pages
which are entirely defined in the external template.
Extend pdf_illustration::add() to accept arguments to pass to the page
class constructor to allow for this.
This makes the code shorter and arguably more clear.
---
ledger_pdf_generator_wx.cpp | 54 +++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 34 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 722ec02..24921f2 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -650,10 +650,13 @@ class pdf_illustration : protected html_interpolator
}
// Add a page.
- template<typename T>
- void add()
+ //
+ // This is a template just in order to save on writing std::make_unique<>()
+ // in the code using it to make it slightly shorter.
+ template<typename T, typename... Args>
+ void add(Args&&... args)
{
- pages_.emplace_back(new T());
+ pages_.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
}
// Render all pages.
@@ -997,24 +1000,19 @@ class numbered_page : public page_with_footer
int numbered_page::last_page_number_ = 0;
-class narrative_summary_page : public numbered_page
+// Simplest possible page which is entirely defined by its external template
+// whose name must be specified when constructing it.
+class standard_page : public numbered_page
{
public:
- void render
- (Ledger const& ledger
- ,pdf_writer_wx& writer
- ,html_interpolator const& interpolate_html
- ) override
+ // Accept only string literals as template names, there should be no need
+ // to use anything else.
+ template<int N>
+ explicit standard_page(char const (&page_template_name)[N])
+ :page_template_name_(page_template_name)
{
- numbered_page::render(ledger, writer, interpolate_html);
-
- render_page_template("narrative_summary", writer, interpolate_html);
}
-};
-class narrative_summary_cont_page : public numbered_page
-{
- public:
void render
(Ledger const& ledger
,pdf_writer_wx& writer
@@ -1023,23 +1021,11 @@ class narrative_summary_cont_page : public numbered_page
{
numbered_page::render(ledger, writer, interpolate_html);
- render_page_template("narrative_summary_cont", writer,
interpolate_html);
+ render_page_template(page_template_name_, writer, interpolate_html);
}
-};
-class column_headings_page : public numbered_page
-{
- public:
- void render
- (Ledger const& ledger
- ,pdf_writer_wx& writer
- ,html_interpolator const& interpolate_html
- ) override
- {
- numbered_page::render(ledger, writer, interpolate_html);
-
- render_page_template("column_headings", writer, interpolate_html);
- }
+ private:
+ char const* const page_template_name_;
};
// Helper classes used to show the numeric summary table. The approach used
@@ -1806,9 +1792,9 @@ class pdf_illustration_regular : public pdf_illustration
// Add all the pages.
add<cover_page>();
- add<narrative_summary_page>();
- add<narrative_summary_cont_page>();
- add<column_headings_page>();
+ add<standard_page>("narrative_summary");
+ add<standard_page>("narrative_summary_cont");
+ add<standard_page>("column_headings");
if(!invar.IsInforce)
{
add<numeric_summary_or_attachment_page<false>>();
- [lmi-commits] [lmi] master 61430d2 092/156: Move some variable definitions to the base illustration class, (continued)
- [lmi-commits] [lmi] master 61430d2 092/156: Move some variable definitions to the base illustration class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7ccd207 087/156: Rename "footer_contents" to more precise "page_number", Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3a64b87 094/156: Correct misleading comment for page class dtor, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to the string interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b5fe850 102/156: Add NASD basic illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4250de9 104/156: Add first variant of NASD supplemental page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7a1e1e8 025/156: Include the missing <cstring> header, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 8bfb896 109/156: Add NASD illustration first explanatory notes page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ea20a31 095/156: Make pdf_illustration dtor virtual, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 61fae89 091/156: Reimplement the contract numbers fragment as an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0c55621 085/156: Replace trivial PDF page classes with single standard_page one,
Greg Chicares <=
- [lmi-commits] [lmi] master ea2564b 099/156: Split the NASD header template in the upper and lower parts, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master c1bf4a8 032/156: Adjust position of the right hand side of the header manually, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 89b4674 120/156: Add automatic support for multiline super-headers, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0f885a2 116/156: Define CorpNameAbbrev60 and Insured1Abbrev30 in common code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 08559c3 121/156: Factor out base_suffix() and ir_suffix() functions, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 36c84ce 123/156: Add another individual private placement illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0ecc8ec 036/156: Add support for partials to our ad hoc Mustache parser, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6f09722 107/156: Add missing words to the narrative summary continuation page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6510601 150/156: Rename a mute variable to avoid gcc -Wshadow warning, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 048ae05 093/156: Start NASD PDF illustration class implementation, Greg Chicares, 2018/01/30