[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4864] Mix class xml_serializable into class rounding_rule
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4864] Mix class xml_serializable into class rounding_rules |
Date: |
Mon, 26 Apr 2010 12:40:26 +0000 |
Revision: 4864
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4864
Author: chicares
Date: 2010-04-26 12:40:25 +0000 (Mon, 26 Apr 2010)
Log Message:
-----------
Mix class xml_serializable into class rounding_rules
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/ihs_basicval.cpp
lmi/trunk/my_rnd.cpp
lmi/trunk/rounding_document.cpp
lmi/trunk/rounding_rules.cpp
lmi/trunk/rounding_rules.hpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/ChangeLog 2010-04-26 12:40:25 UTC (rev 4864)
@@ -25062,3 +25062,12 @@
main_cli.cpp
Report elapsed time for system test.
+20100426T1240Z <address@hidden> [755]
+
+ ihs_basicval.cpp
+ my_rnd.cpp
+ rounding_document.cpp
+ rounding_rules.cpp
+ rounding_rules.hpp
+Mix class xml_serializable into class rounding_rules.
+
Modified: lmi/trunk/ihs_basicval.cpp
===================================================================
--- lmi/trunk/ihs_basicval.cpp 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/ihs_basicval.cpp 2010-04-26 12:40:25 UTC (rev 4864)
@@ -842,25 +842,25 @@
void BasicValues::SetRoundingFunctors()
{
- round_specamt_ = RoundingRules_->round_specamt ();
- round_death_benefit_ = RoundingRules_->round_death_benefit ();
- round_naar_ = RoundingRules_->round_naar ();
- round_coi_rate_ = RoundingRules_->round_coi_rate ();
- round_coi_charge_ = RoundingRules_->round_coi_charge ();
- round_gross_premium_ = RoundingRules_->round_gross_premium ();
- round_net_premium_ = RoundingRules_->round_net_premium ();
- round_interest_rate_ = RoundingRules_->round_interest_rate ();
- round_interest_credit_ = RoundingRules_->round_interest_credit ();
- round_withdrawal_ = RoundingRules_->round_withdrawal ();
- round_loan_ = RoundingRules_->round_loan ();
- round_corridor_factor_ = RoundingRules_->round_corridor_factor ();
- round_surrender_charge_ = RoundingRules_->round_surrender_charge ();
- round_irr_ = RoundingRules_->round_irr ();
- round_min_specamt_ = RoundingRules_->round_min_specamt ();
- round_max_specamt_ = RoundingRules_->round_max_specamt ();
- round_min_premium_ = RoundingRules_->round_min_premium ();
- round_max_premium_ = RoundingRules_->round_max_premium ();
- round_interest_rate_7702_ = RoundingRules_->round_interest_rate_7702();
+ round_specamt_ = RoundingRules_->datum("RoundSpecAmt" );
+ round_death_benefit_ = RoundingRules_->datum("RoundDeathBft" );
+ round_naar_ = RoundingRules_->datum("RoundNaar" );
+ round_coi_rate_ = RoundingRules_->datum("RoundCoiRate" );
+ round_coi_charge_ = RoundingRules_->datum("RoundCoiCharge" );
+ round_gross_premium_ = RoundingRules_->datum("RoundGrossPrem" );
+ round_net_premium_ = RoundingRules_->datum("RoundNetPrem" );
+ round_interest_rate_ = RoundingRules_->datum("RoundIntRate" );
+ round_interest_credit_ = RoundingRules_->datum("RoundIntCredit" );
+ round_withdrawal_ = RoundingRules_->datum("RoundWithdrawal" );
+ round_loan_ = RoundingRules_->datum("RoundLoan" );
+ round_corridor_factor_ = RoundingRules_->datum("RoundCorrFactor" );
+ round_surrender_charge_ = RoundingRules_->datum("RoundSurrCharge" );
+ round_irr_ = RoundingRules_->datum("RoundIrr" );
+ round_min_specamt_ = RoundingRules_->datum("RoundMinSpecamt" );
+ round_max_specamt_ = RoundingRules_->datum("RoundMaxSpecamt" );
+ round_min_premium_ = RoundingRules_->datum("RoundMinPrem" );
+ round_max_premium_ = RoundingRules_->datum("RoundMaxPrem" );
+ round_interest_rate_7702_ = RoundingRules_->datum("RoundIntRate7702");
}
//============================================================================
Modified: lmi/trunk/my_rnd.cpp
===================================================================
--- lmi/trunk/my_rnd.cpp 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/my_rnd.cpp 2010-04-26 12:40:25 UTC (rev 4864)
@@ -48,7 +48,7 @@
// Sample product.
rounding_rules sample;
// Not necessary for 'sample' product only, because it's built in.
-// sample.Write(AddDataDir("sample.rounding"));
+// sample.save(AddDataDir("sample.rounding"));
#if 0
// Template for adding another policy form.
@@ -56,7 +56,7 @@
another.round_specamt_ = round_to<double>(0, r_upward );
another.round_death_benefit_ = round_to<double>(2, r_to_nearest);
// ...
- another.Write(AddDataDir("another.rounding"));
+ another.save(AddDataDir("another.rounding"));
#endif // 0
}
Modified: lmi/trunk/rounding_document.cpp
===================================================================
--- lmi/trunk/rounding_document.cpp 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/rounding_document.cpp 2010-04-26 12:40:25 UTC (rev 4864)
@@ -71,7 +71,7 @@
void RoundingDocument::ReadDocument(std::string const& filename)
{
- rounding_rules_.Read(filename);
+ rounding_rules_.load(filename);
if(!GetViews().empty())
{
RoundingView& view = PredominantView();
@@ -102,7 +102,7 @@
*it->second = view.controls()[it->first]->GetValue();
}
}
- rounding_rules_.Write(filename);
+ rounding_rules_.save(filename);
}
RoundingView& RoundingDocument::PredominantView() const
Modified: lmi/trunk/rounding_rules.cpp
===================================================================
--- lmi/trunk/rounding_rules.cpp 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/rounding_rules.cpp 2010-04-26 12:40:25 UTC (rev 4864)
@@ -27,19 +27,20 @@
#endif // __BORLANDC__
#include "rounding_rules.hpp"
+#include "xml_serializable.tpp"
#include "alert.hpp"
#include "assert_lmi.hpp"
-#include "data_directory.hpp"
+#include "data_directory.hpp" // AddDataDir()
#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>
+template class xml_serializable<rounding_rules>;
+
namespace xml_serialize
{
template<> struct xml_io<round_to<double> >
@@ -61,6 +62,30 @@
};
} // namespace xml_serialize
+/// Specialize value_cast<>() to throw an exception.
+///
+/// This is required by
+/// any_member::str()
+/// which is not useful here.
+
+template<> std::string value_cast<std::string>(round_to<double> const&)
+{
+ fatal_error() << "Invalid function call." << LMI_FLUSH;
+ throw "Unreachable--silences a compiler diagnostic.";
+}
+
+/// Specialize value_cast<>() to throw an exception.
+///
+/// This is required by
+/// any_member::operator=(std::string const&)
+/// which is not useful here.
+
+template<> round_to<double> value_cast<round_to<double> >(std::string const&)
+{
+ fatal_error() << "Invalid function call." << LMI_FLUSH;
+ throw "Unreachable--silences a compiler diagnostic.";
+}
+
/// Private default ctor.
rounding_rules::rounding_rules()
@@ -84,6 +109,7 @@
,round_max_premium_ (2, r_downward )
,round_interest_rate_7702_(0, r_not_at_all)
{
+ ascribe_members();
}
/// Construct from filename.
@@ -97,7 +123,10 @@
rounding_rules::rounding_rules(std::string const& filename)
{
- Read(filename);
+ ascribe_members();
+
+ load(filename);
+
LMI_ASSERT(r_not_at_all == round_min_specamt_ .style() || r_upward
== round_min_specamt_ .style());
LMI_ASSERT(r_not_at_all == round_max_specamt_ .style() || r_downward
== round_max_specamt_ .style());
LMI_ASSERT(r_not_at_all == round_min_premium_ .style() || r_upward
== round_min_premium_ .style());
@@ -105,89 +134,81 @@
LMI_ASSERT(r_not_at_all == round_interest_rate_7702_.style() || r_upward
== round_interest_rate_7702_.style());
}
-namespace
+rounding_rules::~rounding_rules()
{
-std::string xml_root_name()
+}
+
+/// Member datum nominated by the given name.
+
+round_to<double> const& rounding_rules::datum(std::string const& name)
{
- return "rounding";
+ return *member_cast<round_to<double> >(operator[](name));
}
-} // Unnamed namespace.
-void rounding_rules::Read(std::string const& filename)
+/// Enregister certain data members for access via any_member<>[].
+
+void rounding_rules::ascribe_members()
{
- if(access(filename.c_str(), R_OK))
- {
- fatal_error()
- << "File '"
- << filename
- << "' is required but could not be found. Try reinstalling."
- << LMI_FLUSH
- ;
- }
+ ascribe("RoundSpecAmt" , &rounding_rules::round_specamt_ );
+ ascribe("RoundDeathBft" , &rounding_rules::round_death_benefit_ );
+ ascribe("RoundNaar" , &rounding_rules::round_naar_ );
+ ascribe("RoundCoiRate" , &rounding_rules::round_coi_rate_ );
+ ascribe("RoundCoiCharge" , &rounding_rules::round_coi_charge_ );
+ ascribe("RoundGrossPrem" , &rounding_rules::round_gross_premium_ );
+ ascribe("RoundNetPrem" , &rounding_rules::round_net_premium_ );
+ ascribe("RoundIntRate" , &rounding_rules::round_interest_rate_ );
+ ascribe("RoundIntCredit" , &rounding_rules::round_interest_credit_ );
+ ascribe("RoundWithdrawal" , &rounding_rules::round_withdrawal_ );
+ ascribe("RoundLoan" , &rounding_rules::round_loan_ );
+ ascribe("RoundCorrFactor" , &rounding_rules::round_corridor_factor_ );
+ ascribe("RoundSurrCharge" , &rounding_rules::round_surrender_charge_ );
+ ascribe("RoundIrr" , &rounding_rules::round_irr_ );
+ ascribe("RoundMinSpecamt" , &rounding_rules::round_min_specamt_ );
+ ascribe("RoundMaxSpecamt" , &rounding_rules::round_max_specamt_ );
+ ascribe("RoundMinPrem" , &rounding_rules::round_min_premium_ );
+ ascribe("RoundMaxPrem" , &rounding_rules::round_max_premium_ );
+ ascribe("RoundIntRate7702", &rounding_rules::round_interest_rate_7702_);
+}
- xml_lmi::dom_parser parser(filename);
- xml::element const& root = parser.root_node(xml_root_name());
+/// Backward-compatibility serial number of this class's xml version.
+///
+/// version 0: 20100407T1144Z
- 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_
);
- xml_serialize::get_element(root, "RoundMinSpecamt" , round_min_specamt_
);
- xml_serialize::get_element(root, "RoundMaxSpecamt" , round_max_specamt_
);
- xml_serialize::get_element(root, "RoundMinPrem" , round_min_premium_
);
- xml_serialize::get_element(root, "RoundMaxPrem" , round_max_premium_
);
- xml_serialize::get_element(root, "RoundIntRate7702",
round_interest_rate_7702_);
+int rounding_rules::class_version() const
+{
+ return 0;
}
-void rounding_rules::Write(std::string const& filename) const
+std::string rounding_rules::xml_root_name() const
{
- xml_lmi::xml_document document(xml_root_name());
- xml::element& root = document.root_node();
+ return "rounding";
+}
- xml_lmi::set_attr(root, "version", "0");
+/// This override doesn't call redintegrate_ex_ante(); that wouldn't
+/// make sense, at least not for now.
- 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_
);
- xml_serialize::set_element(root, "RoundMinSpecamt" , round_min_specamt_
);
- xml_serialize::set_element(root, "RoundMaxSpecamt" , round_max_specamt_
);
- xml_serialize::set_element(root, "RoundMinPrem" , round_min_premium_
);
- xml_serialize::set_element(root, "RoundMaxPrem" , round_max_premium_
);
- xml_serialize::set_element(root, "RoundIntRate7702",
round_interest_rate_7702_);
+void rounding_rules::read_element
+ (xml::element const& e
+ ,std::string const& name
+ ,int // file_version
+ )
+{
+ round_to<double>& r = *member_cast<round_to<double> >(operator[](name));
+ xml_serialize::from_xml(e, r);
+}
- // 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_element
+ (xml::element& parent
+ ,std::string const& name
+ ) const
+{
+ round_to<double> const& r = *member_cast<round_to<double>
>(operator[](name));
+ xml_serialize::set_element(parent, name, r);
}
void rounding_rules::write_rounding_files()
{
rounding_rules sample;
- sample.Write(AddDataDir("sample.rounding"));
+ sample.save(AddDataDir("sample.rounding"));
}
Modified: lmi/trunk/rounding_rules.hpp
===================================================================
--- lmi/trunk/rounding_rules.hpp 2010-04-25 21:31:23 UTC (rev 4863)
+++ lmi/trunk/rounding_rules.hpp 2010-04-26 12:40:25 UTC (rev 4864)
@@ -26,9 +26,14 @@
#include "config.hpp"
+#include "any_member.hpp"
+#include "obstruct_slicing.hpp"
#include "round_to.hpp"
#include "so_attributes.hpp"
+#include "xml_serializable.hpp"
+#include <boost/utility.hpp>
+
#include <string>
/// Product rounding rules.
@@ -53,44 +58,43 @@
/// The 7702 and 7702A interest rate must be rounded up, if at all.
class LMI_SO rounding_rules
+ : private boost::noncopyable
+ ,virtual private obstruct_slicing <rounding_rules>
+ , public xml_serializable <rounding_rules>
+ , public MemberSymbolTable <rounding_rules>
{
friend class RoundingDocument;
- friend class RoundingView;
public:
explicit rounding_rules(std::string const& filename);
+ ~rounding_rules();
+ round_to<double> const& datum(std::string const& name);
+
// 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:
rounding_rules();
- // Legacy functions to be reimplemented soon.
- void Read (std::string const& filename);
- void Write(std::string const& filename) const;
+ void ascribe_members();
+ // xml_serializable required implementation.
+ virtual int class_version() const;
+ virtual std::string xml_root_name() const;
+
+ // xml_serializable overrides.
+ virtual void read_element
+ (xml::element const& e
+ ,std::string const& name
+ ,int file_version
+ );
+ virtual void write_element
+ (xml::element& parent
+ ,std::string const& name
+ ) const;
+
round_to<double> round_specamt_ ;
round_to<double> round_death_benefit_ ;
round_to<double> round_naar_ ;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4864] Mix class xml_serializable into class rounding_rules,
Greg Chicares <=