lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [4855] Refactor, merging two classes into one


From: Greg Chicares
Subject: [lmi-commits] [4855] Refactor, merging two classes into one
Date: Fri, 23 Apr 2010 23:34:28 +0000

Revision: 4855
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4855
Author:   chicares
Date:     2010-04-23 23:34:27 +0000 (Fri, 23 Apr 2010)
Log Message:
-----------
Refactor, merging two classes into one

Modified Paths:
--------------
    lmi/trunk/Makefile.am
    lmi/trunk/generate_product_files.cpp
    lmi/trunk/ihs_basicval.cpp
    lmi/trunk/my_rnd.cpp
    lmi/trunk/objects.make
    lmi/trunk/product_file_test.cpp
    lmi/trunk/rounding_document.hpp
    lmi/trunk/rounding_rules.cpp
    lmi/trunk/rounding_rules.hpp

Removed Paths:
-------------
    lmi/trunk/ihs_rnddata.cpp
    lmi/trunk/ihs_rnddata.hpp

Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am       2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/Makefile.am       2010-04-23 23:34:27 UTC (rev 4855)
@@ -280,7 +280,6 @@
     path_utility.cpp \
     product_names.cpp \
     progress_meter.cpp \
-    rounding_rules.cpp \
     sigfpe.cpp \
     single_cell_document.cpp \
     surrchg_rates.cpp \
@@ -336,7 +335,6 @@
     ihs_irc7702a.cpp \
     ihs_mortal.cpp \
     ihs_pios.cpp \
-    ihs_rnddata.cpp \
     mc_enum.cpp \
     mc_enum_types.cpp \
     mc_enum_types_aux.cpp \
@@ -344,6 +342,7 @@
     mortality_rates_fetch.cpp \
     preferences_model.cpp \
     product_data.cpp \
+    rounding_rules.cpp \
     stratified_algorithms.cpp \
     stratified_charges.cpp \
     tn_range_types.cpp \
@@ -736,7 +735,6 @@
   ihs_fpios.cpp \
   ihs_funddata.cpp \
   ihs_pios.cpp \
-  ihs_rnddata.cpp \
   miscellany.cpp \
   path_utility.cpp \
   product_data.cpp \
@@ -923,7 +921,6 @@
     ihs_irc7702a.hpp \
     ihs_irc7702.hpp \
     ihs_pios.hpp \
-    ihs_rnddata.hpp \
     ihs_server7702.hpp \
     ihs_server7702io.hpp \
     ihs_x_type.hpp \

Modified: lmi/trunk/generate_product_files.cpp
===================================================================
--- lmi/trunk/generate_product_files.cpp        2010-04-23 22:28:24 UTC (rev 
4854)
+++ lmi/trunk/generate_product_files.cpp        2010-04-23 23:34:27 UTC (rev 
4855)
@@ -28,10 +28,10 @@
 
 #include "ihs_dbdict.hpp"
 #include "ihs_funddata.hpp"
-#include "ihs_rnddata.hpp"
 #include "main_common.hpp"
 #include "path_utility.hpp" // initialize_filesystem()
 #include "product_data.hpp"
+#include "rounding_rules.hpp"
 #include "stratified_charges.hpp"
 
 #include <iostream>
@@ -46,13 +46,13 @@
     DBDictionary::instance() .WriteSampleDBFile                  ();
     product_data            ::WritePolFiles                      ();
     FundData                ::WriteFundFiles                     ();
-    StreamableRoundingRules ::WriteRndFiles                      ();
+    rounding_rules          ::write_rounding_files               ();
     stratified_charges      ::write_stratified_files             ();
 
     DBDictionary::instance() .WriteProprietaryDBFiles            ();
     FundData                ::WriteProprietaryFundFiles          ();
     product_data            ::WriteProprietaryPolFiles           ();
-    StreamableRoundingRules ::WriteProprietaryRndFiles           ();
+    rounding_rules          ::write_proprietary_rounding_files   ();
     stratified_charges      ::write_proprietary_stratified_files ();
 
     std::cout << "\nAll product files written.\n" << std::endl;

Modified: lmi/trunk/ihs_basicval.cpp
===================================================================
--- lmi/trunk/ihs_basicval.cpp  2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/ihs_basicval.cpp  2010-04-23 23:34:27 UTC (rev 4855)
@@ -42,7 +42,6 @@
 #include "ihs_funddata.hpp"
 #include "ihs_irc7702.hpp"
 #include "ihs_irc7702a.hpp"
-#include "ihs_rnddata.hpp"
 #include "ihs_x_type.hpp"
 #include "input.hpp"
 #include "interest_rates.hpp"
@@ -53,6 +52,7 @@
 #include "mortality_rates.hpp"
 #include "outlay.hpp"
 #include "product_data.hpp"
+#include "rounding_rules.hpp"
 #include "stratified_charges.hpp"
 #include "surrchg_rates.hpp"
 #include "value_cast.hpp"
@@ -246,11 +246,7 @@
         }
     FundData_.reset(new 
FundData(AddDataDir(ProductData_->datum("FundFilename"))));
     RoundingRules_.reset
-        (new rounding_rules
-            (StreamableRoundingRules
-                (AddDataDir(ProductData_->datum("RoundingFilename"))
-                ).get_rounding_rules()
-            )
+        (new 
rounding_rules(AddDataDir(ProductData_->datum("RoundingFilename")))
         );
     SetRoundingFunctors();
     StratifiedCharges_.reset
@@ -333,11 +329,7 @@
 //      (AddDataDir(ProductData_->datum("FundFilename"))
 //      );
     RoundingRules_.reset
-        (new rounding_rules
-            (StreamableRoundingRules
-                (AddDataDir(ProductData_->datum("RoundingFilename"))
-                ).get_rounding_rules()
-            )
+        (new 
rounding_rules(AddDataDir(ProductData_->datum("RoundingFilename")))
         );
     SetRoundingFunctors();
     StratifiedCharges_.reset

Deleted: lmi/trunk/ihs_rnddata.cpp
===================================================================
--- lmi/trunk/ihs_rnddata.cpp   2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/ihs_rnddata.cpp   2010-04-23 23:34:27 UTC (rev 4855)
@@ -1,172 +0,0 @@
-// Rounding rules.
-//
-// Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010 Gregory W. Chicares.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-// Rounding rules for a policy form
-
-#ifdef __BORLANDC__
-#   include "pchfile.hpp"
-#   pragma hdrstop
-#endif // __BORLANDC__
-
-#include "ihs_rnddata.hpp"
-
-#include "alert.hpp"
-#include "data_directory.hpp"
-#include "mc_enum.hpp"
-#include "mc_enum_types.hpp"
-#include "platform_dependent.hpp" // access()
-#include "xml_lmi.hpp"
-#include "xml_serialize.hpp"
-
-#include <boost/filesystem/convenience.hpp>
-#include <boost/filesystem/path.hpp>
-
-namespace xml_serialize
-{
-template<> struct xml_io<round_to<double> >
-{
-    static void to_xml(xml::element& e, round_to<double> const& t)
-    {
-        set_element(e, "decimals",                    t.decimals() );
-        set_element(e, "style"   , mce_rounding_style(t.style   ()));
-    }
-
-    static void from_xml(xml::element const& e, round_to<double>& t)
-    {
-        int                decimals;
-        mce_rounding_style style   ;
-        get_element(e, "decimals", decimals);
-        get_element(e, "style"   , style   );
-        t = round_to<double>(decimals, style.value());
-    }
-};
-} // namespace xml_serialize
-
-//============================================================================
-StreamableRoundingRules::StreamableRoundingRules()
-{
-}
-
-//============================================================================
-StreamableRoundingRules::StreamableRoundingRules(std::string const& a_Filename)
-{
-    Init(a_Filename);
-}
-
-//============================================================================
-void StreamableRoundingRules::Init(std::string const& a_Filename)
-{
-    Read(a_Filename);
-    round_min_specamt_        = round_to<double>(round_specamt_      
.decimals(), r_upward);
-    round_max_specamt_        = round_to<double>(round_specamt_      
.decimals(), r_downward);
-    round_min_premium_        = 
round_to<double>(round_gross_premium_.decimals(), r_upward);
-    round_max_premium_        = 
round_to<double>(round_gross_premium_.decimals(), r_downward);
-    // One might alternatively not round this interest rate at all.
-    round_interest_rate_7702_ = 
round_to<double>(round_interest_rate_.decimals(), r_upward);
-}
-
-//============================================================================
-rounding_rules const& StreamableRoundingRules::get_rounding_rules()
-{
-    return dynamic_cast<rounding_rules&>(*this);
-}
-
-namespace
-{
-std::string xml_root_name()
-{
-    return "rounding";
-}
-} // Unnamed namespace.
-
-//============================================================================
-void StreamableRoundingRules::Read(std::string const& a_Filename)
-{
-    if(access(a_Filename.c_str(), R_OK))
-        {
-        fatal_error()
-            << "File '"
-            << a_Filename
-            << "' is required but could not be found. Try reinstalling."
-            << LMI_FLUSH
-            ;
-        }
-
-    xml_lmi::dom_parser parser(a_Filename);
-    xml::element const& root = parser.root_node(xml_root_name());
-
-    xml_serialize::get_element(root, "RoundSpecAmt"   , round_specamt_         
);
-    xml_serialize::get_element(root, "RoundDeathBft"  , round_death_benefit_   
);
-    xml_serialize::get_element(root, "RoundNaar"      , round_naar_            
);
-    xml_serialize::get_element(root, "RoundCoiRate"   , round_coi_rate_        
);
-    xml_serialize::get_element(root, "RoundCoiCharge" , round_coi_charge_      
);
-    xml_serialize::get_element(root, "RoundGrossPrem" , round_gross_premium_   
);
-    xml_serialize::get_element(root, "RoundNetPrem"   , round_net_premium_     
);
-    xml_serialize::get_element(root, "RoundIntRate"   , round_interest_rate_   
);
-    xml_serialize::get_element(root, "RoundIntCredit" , round_interest_credit_ 
);
-    xml_serialize::get_element(root, "RoundWithdrawal", round_withdrawal_      
);
-    xml_serialize::get_element(root, "RoundLoan"      , round_loan_            
);
-    xml_serialize::get_element(root, "RoundCorrFactor", round_corridor_factor_ 
);
-    xml_serialize::get_element(root, "RoundSurrCharge", 
round_surrender_charge_);
-    xml_serialize::get_element(root, "RoundIRR"       , round_irr_             
);
-}
-
-//============================================================================
-void StreamableRoundingRules::Write(std::string const& a_Filename) const
-{
-    xml_lmi::xml_document document(xml_root_name());
-    xml::element& root = document.root_node();
-
-    xml_lmi::set_attr(root, "version", "0");
-
-    xml_serialize::set_element(root, "RoundSpecAmt"   , round_specamt_         
);
-    xml_serialize::set_element(root, "RoundDeathBft"  , round_death_benefit_   
);
-    xml_serialize::set_element(root, "RoundNaar"      , round_naar_            
);
-    xml_serialize::set_element(root, "RoundCoiRate"   , round_coi_rate_        
);
-    xml_serialize::set_element(root, "RoundCoiCharge" , round_coi_charge_      
);
-    xml_serialize::set_element(root, "RoundGrossPrem" , round_gross_premium_   
);
-    xml_serialize::set_element(root, "RoundNetPrem"   , round_net_premium_     
);
-    xml_serialize::set_element(root, "RoundIntRate"   , round_interest_rate_   
);
-    xml_serialize::set_element(root, "RoundIntCredit" , round_interest_credit_ 
);
-    xml_serialize::set_element(root, "RoundWithdrawal", round_withdrawal_      
);
-    xml_serialize::set_element(root, "RoundLoan"      , round_loan_            
);
-    xml_serialize::set_element(root, "RoundCorrFactor", round_corridor_factor_ 
);
-    xml_serialize::set_element(root, "RoundSurrCharge", 
round_surrender_charge_);
-    xml_serialize::set_element(root, "RoundIRR"       , round_irr_             
);
-
-    // Instead of this:
-//    document.save(a_Filename);
-    // for the nonce, explicitly change the extension, in order to
-    // force external product-file code to use the new extension.
-    fs::path path(a_Filename, fs::native);
-    path = fs::change_extension(path, ".rounding");
-    document.save(path.string());
-}
-
-//============================================================================
-void StreamableRoundingRules::WriteRndFiles()
-{
-    StreamableRoundingRules sample;
-    sample.Write(AddDataDir("sample.rounding"));
-}
-

Deleted: lmi/trunk/ihs_rnddata.hpp
===================================================================
--- lmi/trunk/ihs_rnddata.hpp   2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/ihs_rnddata.hpp   2010-04-23 23:34:27 UTC (rev 4855)
@@ -1,57 +0,0 @@
-// Rounding rules.
-//
-// Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010 Gregory W. Chicares.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-#ifndef ihs_rnddata_hpp
-#define ihs_rnddata_hpp
-
-#include "config.hpp"
-
-#include "rounding_rules.hpp"
-
-#include "so_attributes.hpp"
-
-#include <string>
-
-class LMI_SO StreamableRoundingRules
-    :public rounding_rules
-{
-    friend class RoundingDocument;
-
-  public:
-    explicit StreamableRoundingRules(std::string const& a_Filename);
-
-    static void WriteRndFiles();
-    static void WriteProprietaryRndFiles();
-
-    rounding_rules const& get_rounding_rules();
-
-  private:
-    StreamableRoundingRules();
-
-    void Init(std::string const& a_Filename);
-    void Read(std::string const& a_Filename);
-    void Write(std::string const& a_Filename) const;
-};
-
-#endif // ihs_rnddata_hpp
-

Modified: lmi/trunk/my_rnd.cpp
===================================================================
--- lmi/trunk/my_rnd.cpp        2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/my_rnd.cpp        2010-04-23 23:34:27 UTC (rev 4855)
@@ -39,19 +39,18 @@
 #   pragma hdrstop
 #endif // __BORLANDC__
 
-#include "ihs_rnddata.hpp"
+#include "rounding_rules.hpp"
 
 #include "data_directory.hpp"
 
-// TODO ?? It would be better to call StreamableRoundingRules::WriteRndFiles()
-// here than to duplicate what it does. However, it would be better still
-// to use xml for all product data files.
+// TODO ?? It would be better to call rounding_rules::write_rounding_files()
+// here than to duplicate what it does.
 
 //============================================================================
-void StreamableRoundingRules::WriteProprietaryRndFiles()
+void rounding_rules::write_proprietary_rounding_files()
 {
     // Sample policy form.
-    StreamableRoundingRules sample;
+    rounding_rules sample;
 
     sample.round_specamt_         = round_to<double>(0, r_upward    );
     sample.round_death_benefit_   = round_to<double>(2, r_to_nearest);

Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make      2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/objects.make      2010-04-23 23:34:27 UTC (rev 4855)
@@ -229,7 +229,6 @@
   path_utility.o \
   product_names.o \
   progress_meter.o \
-  rounding_rules.o \
   sigfpe.o \
   single_cell_document.o \
   surrchg_rates.o \
@@ -283,7 +282,6 @@
   ihs_irc7702a.o \
   ihs_mortal.o \
   ihs_pios.o \
-  ihs_rnddata.o \
   md5.o \
   mec_input.o \
   mec_server.o \
@@ -292,6 +290,7 @@
   mortality_rates_fetch.o \
   preferences_model.o \
   product_data.o \
+  rounding_rules.o \
   stratified_algorithms.o \
   stratified_charges.o \
 
@@ -394,7 +393,6 @@
   ihs_funddata.o \
   ihs_mortal.o \
   ihs_pios.o \
-  ihs_rnddata.o \
   input.o \
   input_harmonization.o \
   input_realization.o \
@@ -786,7 +784,6 @@
   ihs_fpios.o \
   ihs_funddata.o \
   ihs_pios.o \
-  ihs_rnddata.o \
   mc_enum.o \
   mc_enum_types.o \
   miscellany.o \

Modified: lmi/trunk/product_file_test.cpp
===================================================================
--- lmi/trunk/product_file_test.cpp     2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/product_file_test.cpp     2010-04-23 23:34:27 UTC (rev 4855)
@@ -28,9 +28,9 @@
 
 #include "ihs_dbdict.hpp"
 #include "ihs_funddata.hpp"
-#include "ihs_rnddata.hpp"
 #include "path_utility.hpp" // initialize_filesystem()
 #include "product_data.hpp"
+#include "rounding_rules.hpp"
 #include "stratified_charges.hpp"
 
 #include "test_tools.hpp"
@@ -75,7 +75,7 @@
     DBDictionary::instance() .WriteSampleDBFile      ();
     product_data            ::WritePolFiles          ();
     FundData                ::WriteFundFiles         ();
-    StreamableRoundingRules ::WriteRndFiles          ();
+    rounding_rules          ::write_rounding_files   ();
     stratified_charges      ::write_stratified_files ();
 
     policy_filename_     = "sample";
@@ -104,7 +104,7 @@
 
 void product_file_test::read_rounding_file()
 {
-    StreamableRoundingRules r(rounding_filename_);
+    rounding_rules r(rounding_filename_);
 }
 
 void product_file_test::read_stratified_file()

Modified: lmi/trunk/rounding_document.hpp
===================================================================
--- lmi/trunk/rounding_document.hpp     2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/rounding_document.hpp     2010-04-23 23:34:27 UTC (rev 4855)
@@ -28,7 +28,7 @@
 
 #include "product_editor.hpp"
 
-#include "ihs_rnddata.hpp"
+#include "rounding_rules.hpp"
 
 #include <map>
 #include <string>
@@ -53,7 +53,7 @@
 
     RoundingView& PredominantView() const;
 
-    StreamableRoundingRules rounding_rules_;
+    rounding_rules rounding_rules_;
 
     values_type values_;
 

Modified: lmi/trunk/rounding_rules.cpp
===================================================================
--- lmi/trunk/rounding_rules.cpp        2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/rounding_rules.cpp        2010-04-23 23:34:27 UTC (rev 4855)
@@ -1,6 +1,6 @@
 // Rounding rules.
 //
-// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Gregory W. Chicares.
+// Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010 Gregory W. Chicares.
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -28,7 +28,40 @@
 
 #include "rounding_rules.hpp"
 
-//============================================================================
+#include "alert.hpp"
+#include "data_directory.hpp"
+#include "mc_enum.hpp"
+#include "mc_enum_types.hpp"
+#include "platform_dependent.hpp" // access()
+#include "xml_lmi.hpp"
+#include "xml_serialize.hpp"
+
+#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/path.hpp>
+
+namespace xml_serialize
+{
+template<> struct xml_io<round_to<double> >
+{
+    static void to_xml(xml::element& e, round_to<double> const& t)
+    {
+        set_element(e, "decimals",                    t.decimals() );
+        set_element(e, "style"   , mce_rounding_style(t.style   ()));
+    }
+
+    static void from_xml(xml::element const& e, round_to<double>& t)
+    {
+        int                decimals;
+        mce_rounding_style style   ;
+        get_element(e, "decimals", decimals);
+        get_element(e, "style"   , style   );
+        t = round_to<double>(decimals, style.value());
+    }
+};
+} // namespace xml_serialize
+
+/// Private default ctor.
+
 rounding_rules::rounding_rules()
     :round_specamt_           (0, r_upward    )
     ,round_death_benefit_     (2, r_to_nearest)
@@ -52,3 +85,89 @@
 {
 }
 
+rounding_rules::rounding_rules(std::string const& filename)
+{
+    Read(filename);
+    round_min_specamt_        = round_to<double>(round_specamt_      
.decimals(), r_upward);
+    round_max_specamt_        = round_to<double>(round_specamt_      
.decimals(), r_downward);
+    round_min_premium_        = 
round_to<double>(round_gross_premium_.decimals(), r_upward);
+    round_max_premium_        = 
round_to<double>(round_gross_premium_.decimals(), r_downward);
+    round_interest_rate_7702_ = 
round_to<double>(round_interest_rate_.decimals(), r_upward);
+}
+
+namespace
+{
+std::string xml_root_name()
+{
+    return "rounding";
+}
+} // Unnamed namespace.
+
+void rounding_rules::Read(std::string const& filename)
+{
+    if(access(filename.c_str(), R_OK))
+        {
+        fatal_error()
+            << "File '"
+            << filename
+            << "' is required but could not be found. Try reinstalling."
+            << LMI_FLUSH
+            ;
+        }
+
+    xml_lmi::dom_parser parser(filename);
+    xml::element const& root = parser.root_node(xml_root_name());
+
+    xml_serialize::get_element(root, "RoundSpecAmt"   , round_specamt_         
);
+    xml_serialize::get_element(root, "RoundDeathBft"  , round_death_benefit_   
);
+    xml_serialize::get_element(root, "RoundNaar"      , round_naar_            
);
+    xml_serialize::get_element(root, "RoundCoiRate"   , round_coi_rate_        
);
+    xml_serialize::get_element(root, "RoundCoiCharge" , round_coi_charge_      
);
+    xml_serialize::get_element(root, "RoundGrossPrem" , round_gross_premium_   
);
+    xml_serialize::get_element(root, "RoundNetPrem"   , round_net_premium_     
);
+    xml_serialize::get_element(root, "RoundIntRate"   , round_interest_rate_   
);
+    xml_serialize::get_element(root, "RoundIntCredit" , round_interest_credit_ 
);
+    xml_serialize::get_element(root, "RoundWithdrawal", round_withdrawal_      
);
+    xml_serialize::get_element(root, "RoundLoan"      , round_loan_            
);
+    xml_serialize::get_element(root, "RoundCorrFactor", round_corridor_factor_ 
);
+    xml_serialize::get_element(root, "RoundSurrCharge", 
round_surrender_charge_);
+    xml_serialize::get_element(root, "RoundIRR"       , round_irr_             
);
+}
+
+void rounding_rules::Write(std::string const& filename) const
+{
+    xml_lmi::xml_document document(xml_root_name());
+    xml::element& root = document.root_node();
+
+    xml_lmi::set_attr(root, "version", "0");
+
+    xml_serialize::set_element(root, "RoundSpecAmt"   , round_specamt_         
);
+    xml_serialize::set_element(root, "RoundDeathBft"  , round_death_benefit_   
);
+    xml_serialize::set_element(root, "RoundNaar"      , round_naar_            
);
+    xml_serialize::set_element(root, "RoundCoiRate"   , round_coi_rate_        
);
+    xml_serialize::set_element(root, "RoundCoiCharge" , round_coi_charge_      
);
+    xml_serialize::set_element(root, "RoundGrossPrem" , round_gross_premium_   
);
+    xml_serialize::set_element(root, "RoundNetPrem"   , round_net_premium_     
);
+    xml_serialize::set_element(root, "RoundIntRate"   , round_interest_rate_   
);
+    xml_serialize::set_element(root, "RoundIntCredit" , round_interest_credit_ 
);
+    xml_serialize::set_element(root, "RoundWithdrawal", round_withdrawal_      
);
+    xml_serialize::set_element(root, "RoundLoan"      , round_loan_            
);
+    xml_serialize::set_element(root, "RoundCorrFactor", round_corridor_factor_ 
);
+    xml_serialize::set_element(root, "RoundSurrCharge", 
round_surrender_charge_);
+    xml_serialize::set_element(root, "RoundIRR"       , round_irr_             
);
+
+    // Instead of this:
+//    document.save(filename);
+    // for the nonce, explicitly change the extension, in order to
+    // force external product-file code to use the new extension.
+    fs::path path(filename, fs::native);
+    path = fs::change_extension(path, ".rounding");
+    document.save(path.string());
+}
+
+void rounding_rules::write_rounding_files()
+{
+    rounding_rules sample;
+    sample.Write(AddDataDir("sample.rounding"));
+}
+

Modified: lmi/trunk/rounding_rules.hpp
===================================================================
--- lmi/trunk/rounding_rules.hpp        2010-04-23 22:28:24 UTC (rev 4854)
+++ lmi/trunk/rounding_rules.hpp        2010-04-23 23:34:27 UTC (rev 4855)
@@ -1,6 +1,6 @@
 // Rounding rules.
 //
-// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Gregory W. Chicares.
+// Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010 Gregory W. Chicares.
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -29,170 +29,88 @@
 #include "round_to.hpp"
 #include "so_attributes.hpp"
 
-// Design principle: round transactional changes to account value,
-// rather than rounding account value itself at each transaction.
-// This is the way admin systems are most likely to work, and
-// gratuitous differences between systems should be avoided.
-// Rounding is a property of the transaction, and not of the
-// variable it ultimately affects.
+#include <string>
 
+/// Product rounding rules.
+///
+/// The principle is to round transactional changes to account value,
+/// rather than rounding account value itself after each transaction.
+/// This is the way admin systems are most likely to work, and
+/// gratuitous differences between systems should be avoided. Thus,
+/// rounding is a property of the transaction, and not of the variable
+/// it ultimately affects.
+///
+/// Notes on particular rounding functors.
+///
+/// IRR must be rounded down in order to avoid overstating it, but its
+/// precision is an arbitrary parameter.
+///
+/// Premium and specamt must be rounded in the right direction for
+/// 7702 and 7702A calculations. In rounding functors' names:
+///   min- means we want the minimum amount that satisfies some
+///     condition, so we have to round it up to be sure; and
+///   max- means the opposite.
+/// The 7702 and 7702A interest rate must be rounded up, if at all.
+
 class LMI_SO rounding_rules
 {
-    friend class StreamableRoundingRules;
     friend class RoundingDocument;
     friend class RoundingView;
 
   public:
-    rounding_rules();
+    explicit rounding_rules(std::string const& filename);
 
-    round_to<double> const& round_specamt           () const;
-    round_to<double> const& round_death_benefit     () const;
-    round_to<double> const& round_naar              () const;
-    round_to<double> const& round_coi_rate          () const;
-    round_to<double> const& round_coi_charge        () const;
-    round_to<double> const& round_gross_premium     () const;
-    round_to<double> const& round_net_premium       () const;
-    round_to<double> const& round_interest_rate     () const;
-    round_to<double> const& round_interest_credit   () const;
-    round_to<double> const& round_withdrawal        () const;
-    round_to<double> const& round_loan              () const;
-    round_to<double> const& round_corridor_factor   () const;
-    round_to<double> const& round_surrender_charge  () const;
-    round_to<double> const& round_irr               () const;
-    round_to<double> const& round_min_specamt       () const;
-    round_to<double> const& round_max_specamt       () const;
-    round_to<double> const& round_min_premium       () const;
-    round_to<double> const& round_max_premium       () const;
-    round_to<double> const& round_interest_rate_7702() const;
+    // Legacy functions to support creating product files programmatically.
+    static void write_rounding_files();
+    static void write_proprietary_rounding_files();
 
+    round_to<double> const& round_specamt           () const {return 
round_specamt_           ;}
+    round_to<double> const& round_death_benefit     () const {return 
round_death_benefit_     ;}
+    round_to<double> const& round_naar              () const {return 
round_naar_              ;}
+    round_to<double> const& round_coi_rate          () const {return 
round_coi_rate_          ;}
+    round_to<double> const& round_coi_charge        () const {return 
round_coi_charge_        ;}
+    round_to<double> const& round_gross_premium     () const {return 
round_gross_premium_     ;}
+    round_to<double> const& round_net_premium       () const {return 
round_net_premium_       ;}
+    round_to<double> const& round_interest_rate     () const {return 
round_interest_rate_     ;}
+    round_to<double> const& round_interest_credit   () const {return 
round_interest_credit_   ;}
+    round_to<double> const& round_withdrawal        () const {return 
round_withdrawal_        ;}
+    round_to<double> const& round_loan              () const {return 
round_loan_              ;}
+    round_to<double> const& round_corridor_factor   () const {return 
round_corridor_factor_   ;}
+    round_to<double> const& round_surrender_charge  () const {return 
round_surrender_charge_  ;}
+    round_to<double> const& round_irr               () const {return 
round_irr_               ;}
+    round_to<double> const& round_min_specamt       () const {return 
round_min_specamt_       ;}
+    round_to<double> const& round_max_specamt       () const {return 
round_max_specamt_       ;}
+    round_to<double> const& round_min_premium       () const {return 
round_min_premium_       ;}
+    round_to<double> const& round_max_premium       () const {return 
round_max_premium_       ;}
+    round_to<double> const& round_interest_rate_7702() const {return 
round_interest_rate_7702_;}
+
   private:
-    round_to<double> round_specamt_;
-    round_to<double> round_death_benefit_;
-    round_to<double> round_naar_;
-    round_to<double> round_coi_rate_;
-    round_to<double> round_coi_charge_;
-    round_to<double> round_gross_premium_;
-    round_to<double> round_net_premium_;
-    round_to<double> round_interest_rate_;
-    round_to<double> round_interest_credit_;
-    round_to<double> round_withdrawal_;
-    round_to<double> round_loan_;
-    round_to<double> round_corridor_factor_;
-    round_to<double> round_surrender_charge_;
+    rounding_rules();
 
-    // IRR must be rounded down in order to avoid overstating it, but
-    // its precision is an arbitrary parameter.
+    // Legacy functions to be reimplemented soon.
+    void Read (std::string const& filename);
+    void Write(std::string const& filename) const;
 
-    round_to<double> round_irr_;
-
-    // Premium and specamt must be rounded in the right direction for
-    // 7702 and 7702A calculations. Here,
-    //   min- means we want the minimum amount that satisfies some
-    //     condition, so we have to round it up to be sure; and
-    //   max- means the opposite.
-    // The 7702 and 7702A interest rate must be rounded up, if at all.
-
-    round_to<double> round_min_specamt_;
-    round_to<double> round_max_specamt_;
-    round_to<double> round_min_premium_;
-    round_to<double> round_max_premium_;
+    round_to<double> round_specamt_           ;
+    round_to<double> round_death_benefit_     ;
+    round_to<double> round_naar_              ;
+    round_to<double> round_coi_rate_          ;
+    round_to<double> round_coi_charge_        ;
+    round_to<double> round_gross_premium_     ;
+    round_to<double> round_net_premium_       ;
+    round_to<double> round_interest_rate_     ;
+    round_to<double> round_interest_credit_   ;
+    round_to<double> round_withdrawal_        ;
+    round_to<double> round_loan_              ;
+    round_to<double> round_corridor_factor_   ;
+    round_to<double> round_surrender_charge_  ;
+    round_to<double> round_irr_               ;
+    round_to<double> round_min_specamt_       ;
+    round_to<double> round_max_specamt_       ;
+    round_to<double> round_min_premium_       ;
+    round_to<double> round_max_premium_       ;
     round_to<double> round_interest_rate_7702_;
 };
 
-inline round_to<double> const& rounding_rules::round_specamt() const
-{
-    return round_specamt_;
-}
-
-inline round_to<double> const& rounding_rules::round_death_benefit() const
-{
-    return round_death_benefit_;
-}
-
-inline round_to<double> const& rounding_rules::round_naar() const
-{
-    return round_naar_;
-}
-
-inline round_to<double> const& rounding_rules::round_coi_rate() const
-{
-    return round_coi_rate_;
-}
-
-inline round_to<double> const& rounding_rules::round_coi_charge() const
-{
-    return round_coi_charge_;
-}
-
-inline round_to<double> const& rounding_rules::round_gross_premium() const
-{
-    return round_gross_premium_;
-}
-
-inline round_to<double> const& rounding_rules::round_net_premium() const
-{
-    return round_net_premium_;
-}
-
-inline round_to<double> const& rounding_rules::round_interest_rate() const
-{
-    return round_interest_rate_;
-}
-
-inline round_to<double> const& rounding_rules::round_interest_credit() const
-{
-    return round_interest_credit_;
-}
-
-inline round_to<double> const& rounding_rules::round_withdrawal() const
-{
-    return round_withdrawal_;
-}
-
-inline round_to<double> const& rounding_rules::round_loan() const
-{
-    return round_loan_;
-}
-
-inline round_to<double> const& rounding_rules::round_corridor_factor() const
-{
-    return round_corridor_factor_;
-}
-
-inline round_to<double> const& rounding_rules::round_surrender_charge() const
-{
-    return round_surrender_charge_;
-}
-
-inline round_to<double> const& rounding_rules::round_irr() const
-{
-    return round_irr_;
-}
-
-inline round_to<double> const& rounding_rules::round_min_specamt() const
-{
-    return round_min_specamt_;
-}
-
-inline round_to<double> const& rounding_rules::round_max_specamt() const
-{
-    return round_max_specamt_;
-}
-
-inline round_to<double> const& rounding_rules::round_min_premium() const
-{
-    return round_min_premium_;
-}
-
-inline round_to<double> const& rounding_rules::round_max_premium() const
-{
-    return round_max_premium_;
-}
-
-inline round_to<double> const& rounding_rules::round_interest_rate_7702() const
-{
-    return round_interest_rate_7702_;
-}
-
 #endif // rounding_rules_hpp
 





reply via email to

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