lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 1ab47c0 063/156: Fix definition of integer-va


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 1ab47c0 063/156: Fix definition of integer-valued variable in PDF illustrations
Date: Tue, 30 Jan 2018 17:22:12 -0500 (EST)

branch: master
commit 1ab47c08f08919ef93b4d8e7244f13fd13ff18b3
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Fix definition of integer-valued variable in PDF illustrations
    
    Add add_variable() overload for integers and use it instead of wrongly
    passing double-valued variables to the existing overload taking bool.
    
    Explicitly delete the overload for double as it can't be used here
    because formatting information, required for any floating point value,
    is only available at ledger_evaluator level.
---
 ledger_pdf_generator_wx.cpp | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index b64d02a..9130b88 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -26,6 +26,7 @@
 #include "alert.hpp"
 #include "assert_lmi.hpp"
 #include "authenticity.hpp"
+#include "bourn_cast.hpp"
 #include "calendar_date.hpp"
 #include "force_linking.hpp"
 #include "html.hpp"
@@ -139,11 +140,23 @@ class html_interpolator
         add_variable(name, text::from(value));
     }
 
+    void add_variable(std::string const& name, int value)
+    {
+        std::ostringstream oss;
+        oss << value;
+        add_variable(name, oss.str());
+    }
+
     void add_variable(std::string const& name, bool value)
     {
         add_variable(name, std::string(value ? "1" : "0"));
     }
 
+    // Detect, at compile-time, mistaken attempts to add floating point
+    // variables: all those are only available from ledger_evaluator as they
+    // must be formatted correctly.
+    void add_variable(std::string const& name, double value) = delete;
+
     // Test a boolean variable: the value must be "0" or "1", which is mapped
     // to false or true respectively. Anything else results in an exception.
     bool test_variable(std::string const& name) const
@@ -2050,7 +2063,7 @@ class pdf_illustration_regular : public pdf_illustration
 
         add_variable
             ("MecYearPlus1"
-            ,invar.MecYear + 1
+            ,bourn_cast<int>(invar.MecYear) + 1
             );
 
         // Variable representing the premium payment frequency with the
@@ -2138,7 +2151,7 @@ class pdf_illustration_regular : public pdf_illustration
 
         add_variable
             ("LapseYear_Guaranteed_Plus1"
-            ,lapse_year_guaruanteed + 1
+            ,bourn_cast<int>(lapse_year_guaruanteed) + 1
             );
 
         add_variable
@@ -2148,7 +2161,7 @@ class pdf_illustration_regular : public pdf_illustration
 
         add_variable
             ("LapseYear_Midpoint_Plus1"
-            ,lapse_year_midpoint + 1
+            ,bourn_cast<int>(lapse_year_midpoint) + 1
             );
 
         add_variable
@@ -2158,7 +2171,7 @@ class pdf_illustration_regular : public pdf_illustration
 
         add_variable
             ("LapseYear_Current_Plus1"
-            ,lapse_year_current + 1
+            ,bourn_cast<int>(lapse_year_current) + 1
             );
 
         // Add all the pages.



reply via email to

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