lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 691e6b1 2/9: Refactor


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 691e6b1 2/9: Refactor
Date: Thu, 4 Oct 2018 13:00:39 -0400 (EDT)

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

    Refactor
    
    Class ledger_evaluator contains all the data written with
      --pyx=values_tsv
    so it's reasonable to put that code in a member function of that class.
    
    The class Ledger instance is passed to this new member function because
    a couple of Ledger members are used, at least for now.
    
    The PDF output filename is also passed, although it's not yet used. It
    will soon be used instead of the static constant filename 'values.tsv',
    which unreasonably limits the usefulness of this facility.
---
 ledger_evaluator.cpp        | 20 +++++++++++++-------
 ledger_evaluator.hpp        |  6 ++++++
 ledger_pdf_generator_wx.cpp | 11 ++++++++++-
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 96d7569..497b592 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -987,9 +987,17 @@ ledger_evaluator Ledger::make_evaluator() const
         stringvectors["SupplementalReportColumnsMasks" ] = 
std::move(SupplementalReportColumnsMasks );
         }
 
-    if(is_composite() && contains(global_settings::instance().pyx(), 
"values_tsv"))
+    return ledger_evaluator(std::move(stringscalars), 
std::move(stringvectors));
+}
+
+void ledger_evaluator::write_tsv
+    (fs::path const& // pdf_out_file
+    ,Ledger   const& ledger
+    ) const
+{
+    if(ledger.is_composite() && contains(global_settings::instance().pyx(), 
"values_tsv"))
         {
-        throw_if_interdicted(*this);
+        throw_if_interdicted(ledger);
 
         configurable_settings const& z = configurable_settings::instance();
         fs::path filepath
@@ -999,12 +1007,12 @@ ledger_evaluator Ledger::make_evaluator() const
             );
         fs::ofstream ofs(filepath, ios_out_trunc_binary());
 
-        // Copy 'stringvectors' to a (sorted) std::map in order to
+        // Copy 'vectors_' to a (sorted) std::map in order to
         // show columns alphabetically. Other, more complicated
         // techniques are faster, but direct copying favors simplicity
         // over speed--appropriately, as this facility is rarely used.
         using map_t = std::map<std::string,std::vector<std::string>> const;
-        map_t sorted_stringvectors(stringvectors.begin(), stringvectors.end());
+        map_t sorted_stringvectors(vectors_.begin(), vectors_.end());
 
         for(auto const& j : sorted_stringvectors)
             {
@@ -1012,7 +1020,7 @@ ledger_evaluator Ledger::make_evaluator() const
             }
         ofs << '\n';
 
-        for(int i = 0; i < GetMaxLength(); ++i)
+        for(int i = 0; i < ledger.GetMaxLength(); ++i)
             {
             for(auto const& j : sorted_stringvectors)
                 {
@@ -1033,6 +1041,4 @@ ledger_evaluator Ledger::make_evaluator() const
             alarum() << "Unable to write '" << filepath << "'." << LMI_FLUSH;
             }
         }
-
-    return ledger_evaluator(std::move(stringscalars), 
std::move(stringvectors));
 }
diff --git a/ledger_evaluator.hpp b/ledger_evaluator.hpp
index 40dc882..d4b6909 100644
--- a/ledger_evaluator.hpp
+++ b/ledger_evaluator.hpp
@@ -26,10 +26,14 @@
 
 #include "so_attributes.hpp"
 
+#include <boost/filesystem/path.hpp>
+
 #include <string>
 #include <unordered_map>
 #include <vector>
 
+class Ledger;
+
 /// Class allowing to retrieve the string representation of any scalar or
 /// vector stored in a ledger.
 
@@ -45,6 +49,8 @@ class LMI_SO ledger_evaluator
     std::string operator()(std::string const& scalar) const;
     std::string operator()(std::string const& vector, int index) const;
 
+    void write_tsv(fs::path const&, Ledger const&) const;
+
   private:
     // Constructible only by friends: see Ledger::make_evaluator().
     ledger_evaluator(scalar_map_t&& scalars, vector_map_t&& vectors)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 001c4a5..4c6131d 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -240,6 +240,11 @@ class html_interpolator
         return (*this)("{{>" + template_name + "}}");
     }
 
+    // PDF !! Retrofitting this accessor seems to suggest that
+    // encapsulating the accessed object here may have been
+    // premature.
+    ledger_evaluator const& evaluator() {return evaluator_;}
+
   private:
     // The expansion function used with interpolate_string().
     html::text expand_html(std::string const& s) const
@@ -756,6 +761,7 @@ class pdf_illustration : protected html_interpolator, 
protected pdf_writer_wx
         :html_interpolator (ledger.make_evaluator())
         ,pdf_writer_wx     (pdf_out_file.string(), wxPORTRAIT, font_sizes_)
         ,ledger_           {ledger}
+        ,pdf_out_file_     {pdf_out_file}
     {
         init_variables();
     }
@@ -784,6 +790,8 @@ class pdf_illustration : protected html_interpolator, 
protected pdf_writer_wx
     // Render all pages to the specified PDF file.
     void render_all()
     {
+        evaluator().write_tsv(pdf_out_file_, ledger_);
+
         // PDF !! Apparently this is some sort of quasi-global object?
         html_cell_for_pdf_output::pdf_context_setter the_pdf_context
             {ledger_
@@ -972,7 +980,8 @@ class pdf_illustration : protected html_interpolator, 
protected pdf_writer_wx
             );
     }
 
-    Ledger const& ledger_;
+    Ledger   const& ledger_;
+    fs::path const& pdf_out_file_;
 
     // These font sizes are more suitable for illustrations than
     // the builtin wxHTML defaults. See:



reply via email to

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