[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4962] Refactor, deriving stratified_charges from xml_seri
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4962] Refactor, deriving stratified_charges from xml_serializable |
Date: |
Tue, 25 May 2010 21:54:34 +0000 |
Revision: 4962
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4962
Author: chicares
Date: 2010-05-25 21:54:34 +0000 (Tue, 25 May 2010)
Log Message:
-----------
Refactor, deriving stratified_charges from xml_serializable
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/stratified_charges.cpp
lmi/trunk/stratified_charges.hpp
lmi/trunk/tier_document.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-25 21:17:56 UTC (rev 4961)
+++ lmi/trunk/ChangeLog 2010-05-25 21:54:34 UTC (rev 4962)
@@ -25851,3 +25851,15 @@
tier_document.cpp
Refactor, using symbolic member names in class stratified_charges.
+20100525T2117Z <address@hidden> [704]
+
+ stratified_charges.cpp
+Rearrange.
+
+20100525T2154Z <address@hidden> [704]
+
+ stratified_charges.cpp
+ stratified_charges.hpp
+ tier_document.cpp
+Refactor, deriving stratified_charges from xml_serializable.
+
Modified: lmi/trunk/stratified_charges.cpp
===================================================================
--- lmi/trunk/stratified_charges.cpp 2010-05-25 21:17:56 UTC (rev 4961)
+++ lmi/trunk/stratified_charges.cpp 2010-05-25 21:54:34 UTC (rev 4962)
@@ -27,23 +27,24 @@
#endif // __BORLANDC__
#include "stratified_charges.hpp"
+#include "xml_serializable.tpp"
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "contains.hpp"
#include "data_directory.hpp"
#include "miscellany.hpp" // minmax<T>()
-#include "platform_dependent.hpp" // access()
#include "stratified_algorithms.hpp"
#include "xml_lmi.hpp"
#include "xml_serialize.hpp"
-#include <boost/filesystem/convenience.hpp>
#include <boost/static_assert.hpp>
#include <algorithm>
#include <cfloat> // DBL_MAX
+template class xml_serializable<stratified_charges>;
+
namespace xml_serialize
{
template<>
@@ -181,11 +182,12 @@
stratified_charges::stratified_charges(std::string const& filename)
{
ascribe_members();
- read(filename);
+ load(filename);
}
stratified_charges::stratified_charges(stratified_charges const& z)
:obstruct_slicing <stratified_charges>()
+ ,xml_serializable <stratified_charges>()
,MemberSymbolTable <stratified_charges>()
{
ascribe_members();
@@ -531,44 +533,38 @@
}
}
-void stratified_charges::read(std::string const& filename)
+/// Backward-compatibility serial number of this class's xml version.
+///
+/// version 0: 20100525T2154Z
+
+int stratified_charges::class_version() const
{
- if(access(filename.c_str(), R_OK))
- {
- fatal_error()
- << "File '"
- << filename
- << "' is required but could not be found. Try reinstalling."
- << LMI_FLUSH
- ;
- }
+ return 0;
+}
- xml_lmi::dom_parser parser(filename);
- xml::element const& root = parser.root_node("strata");
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
- {
- xml_serialize::get_element(root, *i, datum(*i));
- }
+std::string stratified_charges::xml_root_name() const
+{
+ return "strata";
}
-void stratified_charges::write(std::string const& filename) const
+/// This override doesn't call redintegrate_ex_ante(); that wouldn't
+/// make sense, at least not for now.
+
+void stratified_charges::read_element
+ (xml::element const& e
+ ,std::string const& name
+ ,int // file_version
+ )
{
- xml_lmi::xml_document document("strata");
- xml::element& root = document.root_node();
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
- {
- xml_serialize::set_element(root, *i, datum(*i));
- }
+ xml_serialize::from_xml(e, datum(name));
+}
- // Instead of this:
-// document.save_to_file(filename.c_str());
- // 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, ".strata");
- document.save(path.string());
+void stratified_charges::write_element
+ (xml::element& parent
+ ,std::string const& name
+ ) const
+{
+ xml_serialize::set_element(parent, name, datum(name));
}
void stratified_charges::write_stratified_files()
@@ -621,7 +617,7 @@
foo.datum("TieredSDPremTax").limits_.push_back(DBL_MAX);
foo.datum("TieredSDPremTax").gloss_ = "SD 10-4-22(2) (see also 58-6-70)";
- foo.write(AddDataDir("sample.strata"));
+ foo.save(AddDataDir("sample.strata"));
}
/// Determine whether a double is in effect the highest representable.
Modified: lmi/trunk/stratified_charges.hpp
===================================================================
--- lmi/trunk/stratified_charges.hpp 2010-05-25 21:17:56 UTC (rev 4961)
+++ lmi/trunk/stratified_charges.hpp 2010-05-25 21:54:34 UTC (rev 4962)
@@ -31,6 +31,7 @@
#include "obstruct_slicing.hpp"
#include "so_attributes.hpp"
#include "xml_lmi_fwd.hpp"
+#include "xml_serializable.hpp"
#include <string>
#include <vector>
@@ -100,6 +101,7 @@
class LMI_SO stratified_charges
:virtual private obstruct_slicing <stratified_charges>
+ , public xml_serializable <stratified_charges>
, public MemberSymbolTable <stratified_charges>
{
friend class TierDocument;
@@ -159,9 +161,21 @@
// Deprecated: for backward compatibility only. Prefer datum().
stratified_entity& raw_entity(e_stratified);
- void read (std::string const& filename);
- void write(std::string const& filename) const;
+ // 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;
+
double banded_curr_sepacct_load
(double assets
,double premium
Modified: lmi/trunk/tier_document.cpp
===================================================================
--- lmi/trunk/tier_document.cpp 2010-05-25 21:17:56 UTC (rev 4961)
+++ lmi/trunk/tier_document.cpp 2010-05-25 21:54:34 UTC (rev 4962)
@@ -67,12 +67,12 @@
void TierDocument::ReadDocument(std::string const& filename)
{
- charges_.read(filename);
+ charges_.load(filename);
}
void TierDocument::WriteDocument(std::string const& filename)
{
- charges_.write(filename);
+ charges_.save(filename);
}
stratified_entity& TierDocument::get_stratified_entity(e_stratified index)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4962] Refactor, deriving stratified_charges from xml_serializable,
Greg Chicares <=