[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] [PATCH 2/4] multi-dimensional tables
From: |
Vaclav Slavik |
Subject: |
[lmi] [PATCH 2/4] multi-dimensional tables |
Date: |
Thu, 02 Aug 2012 14:32:21 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
Add xml_actuarial_table::basic_table.
Add a structure for holding the "basic table" with limited SOA-style 1D
or 2D dimensions. For now, the class is functionally identical, it's
only reorganized to hold all the data in basic_table; more changes to
support multidimensional tables will follow.
This breaks soa_stress_test.
---
actuarial_table.cpp | 90 ++++++++++++++++++++++++++++++++++++-----------------
actuarial_table.hpp | 89 ++++++++++++++++++++++++++++++----------------------
2 files changed, 112 insertions(+), 67 deletions(-)
diff --git a/actuarial_table.cpp b/actuarial_table.cpp
index 3fd7d3b..1e6ad6d 100644
--- a/actuarial_table.cpp
+++ b/actuarial_table.cpp
@@ -91,21 +91,11 @@ namespace
} // Unnamed namespace.
xml_actuarial_table::xml_actuarial_table(std::string const& filename)
- :table_type_ (e_table_invalid)
- ,min_age_ (-1)
- ,max_age_ (-1)
- ,select_period_ (-1)
- ,max_select_age_ (-1)
{
load_xml_table(filename);
}
xml_actuarial_table::xml_actuarial_table(std::string const& filename, int
table_number)
- :table_type_ (e_table_invalid)
- ,min_age_ (-1)
- ,max_age_ (-1)
- ,select_period_ (-1)
- ,max_select_age_ (-1)
{
// SOA !! This is temporary code for API compatibility with
soa_actuarial_table.
// It should be changed so that the constructor takes only a single
@@ -135,27 +125,69 @@ void xml_actuarial_table::load_xml_table(std::string
const& filename)
xml_lmi::dom_parser parser(filename);
xml::element root(parser.root_node("table"));
+ table_.load(root);
+}
+
+/// Read a given number of values for a given issue age.
+
+std::vector<double> xml_actuarial_table::values(int issue_age, int length)
const
+{
+ return table_.values(issue_age, length);
+}
+
+/// Read a given number of values for a given issue age, using a
+/// nondefault lookup method.
+///
+/// Assertions require that arguments be sane on entry, regardless of
+/// method: method-specific adjustments are not permitted to render
+/// sane what was insane ab ovo.
+
+std::vector<double> xml_actuarial_table::values_elaborated
+ (int issue_age
+ ,int length
+ ,e_actuarial_table_method method
+ ,int inforce_duration
+ ,int reset_duration
+ ) const
+{
+ return table_.values_elaborated
+ (issue_age
+ ,length
+ ,method
+ ,inforce_duration
+ ,reset_duration
+ );
+}
+
+xml_actuarial_table::basic_table::basic_table()
+ :table_type_ (e_table_invalid)
+ ,min_age_ (-1)
+ ,max_age_ (-1)
+ ,select_period_ (-1)
+ ,max_select_age_ (-1)
+{
+}
+
+void xml_actuarial_table::basic_table::load(xml::element const& root)
+{
// SOA !! Implement loading of multi-dimensional tables as well.
- // SOA !! Upgrade xmlwrapp:
- // XMLWRAPP !! This should be const_iterator, but xmlwrapp < 0.7 lacks the
- // necessary operator!= for comparing const and non-const iterators.
- xml::node::iterator i;
+ xml::node::const_iterator i;
if (root.end() != (i = root.find("aggregate")))
{
- load_xml_aggregate_table(*i);
+ load_aggregate_table(*i);
}
else if (root.end() != (i = root.find("duration")))
{
- load_xml_duration_table(*i);
+ load_duration_table(*i);
}
else if (root.end() != (i = root.find("select")))
{
- load_xml_select_table(*i);
+ load_select_table(*i);
}
else if (root.end() != (i = root.find("select-and-ultimate")))
{
- load_xml_select_and_ultimate_table(*i);
+ load_select_and_ultimate_table(*i);
}
else
{
@@ -166,7 +198,7 @@ void xml_actuarial_table::load_xml_table(std::string const&
filename)
}
}
-void xml_actuarial_table::load_xml_table_with_ages
+void xml_actuarial_table::basic_table::load_table_with_ages
(xml::element const& node
,std::vector<double>& data
,int& min_age
@@ -215,9 +247,9 @@ void xml_actuarial_table::load_xml_table_with_ages
LMI_ASSERT(data.size() == size_t(max_age - min_age + 1));
}
-void xml_actuarial_table::load_xml_aggregate_table(xml::element const& node)
+void xml_actuarial_table::basic_table::load_aggregate_table(xml::element
const& node)
{
- load_xml_table_with_ages
+ load_table_with_ages
(node
,data_
,min_age_
@@ -227,7 +259,7 @@ void
xml_actuarial_table::load_xml_aggregate_table(xml::element const& node)
table_type_ = e_table_aggregate;
}
-void xml_actuarial_table::load_xml_duration_table(xml::element const& node)
+void xml_actuarial_table::basic_table::load_duration_table(xml::element const&
node)
{
xml::const_nodes_view const values = node.elements("value");
@@ -242,7 +274,7 @@ void
xml_actuarial_table::load_xml_duration_table(xml::element const& node)
table_type_ = e_table_duration;
}
-void xml_actuarial_table::load_xml_select_table(xml::element const& node)
+void xml_actuarial_table::basic_table::load_select_table(xml::element const&
node)
{
xml::const_nodes_view const rows = node.elements("row");
@@ -318,12 +350,12 @@ void
xml_actuarial_table::load_xml_select_table(xml::element const& node)
table_type_ = e_table_select_and_ultimate;
}
-void xml_actuarial_table::load_xml_select_and_ultimate_table(xml::element
const& node)
+void
xml_actuarial_table::basic_table::load_select_and_ultimate_table(xml::element
const& node)
{
- load_xml_select_table(*xml_lmi::retrieve_element(node, "select"));
+ load_select_table(*xml_lmi::retrieve_element(node, "select"));
int ultimate_min_age;
- load_xml_table_with_ages
+ load_table_with_ages
(*xml_lmi::retrieve_element(node, "ultimate")
,ultimate_
,ultimate_min_age
@@ -345,7 +377,7 @@ void
xml_actuarial_table::load_xml_select_and_ultimate_table(xml::element const&
table_type_ = e_table_select_and_ultimate;
}
-std::vector<double> xml_actuarial_table::specific_values
+std::vector<double> xml_actuarial_table::basic_table::specific_values
(int issue_age
,int length
) const
@@ -432,7 +464,7 @@ std::vector<double> xml_actuarial_table::specific_values
/// Read a given number of values for a given issue age.
-std::vector<double> xml_actuarial_table::values(int issue_age, int length)
const
+std::vector<double> xml_actuarial_table::basic_table::values(int issue_age,
int length) const
{
return specific_values(issue_age, length);
}
@@ -444,7 +476,7 @@ std::vector<double> xml_actuarial_table::values(int
issue_age, int length) const
/// method: method-specific adjustments are not permitted to render
/// sane what was insane ab ovo.
-std::vector<double> xml_actuarial_table::values_elaborated
+std::vector<double> xml_actuarial_table::basic_table::values_elaborated
(int issue_age
,int length
,e_actuarial_table_method method
diff --git a/actuarial_table.hpp b/actuarial_table.hpp
index 53f699c..7482146 100644
--- a/actuarial_table.hpp
+++ b/actuarial_table.hpp
@@ -153,46 +153,59 @@ class xml_actuarial_table
,int reset_duration
) const;
- char table_type () const {return table_type_ ;}
- int min_age () const {return min_age_ ;}
- int max_age () const {return max_age_ ;}
- int select_period () const {return select_period_ ;}
- int max_select_age () const {return max_select_age_ ;}
-
protected:
- std::vector<double> specific_values(int issue_age, int length) const;
-
- private:
- void load_xml_table (std::string const& filename);
- void load_xml_aggregate_table (xml::element const& node);
- void load_xml_duration_table (xml::element const& node);
- void load_xml_select_table (xml::element const& node);
- void load_xml_select_and_ultimate_table(xml::element const& node);
- void load_xml_table_with_ages
- (xml::element const& node
- ,std::vector<double>& data
- ,int& min_age
- ,int& max_age
- );
-
- // Table parameters, in order read from table header.
- char table_type_ ;
- int min_age_ ;
- int max_age_ ;
- int select_period_ ;
- int max_select_age_ ;
-
- // Table data. For 1D tables (e_table_aggregate and e_table_duration), this
- // is the vector of values from min_age_ to max_age_.
- // For e_table_select_and_ultimate, the content is organized by rows, with
- // select_period_ entries per row, with rows ranging from min_age_ to
- // max_select_age_.
- std::vector<double> data_;
+ void load_xml_table(std::string const& filename);
+
+ class basic_table
+ {
+ public:
+ basic_table();
+ void load(xml::element const& node);
+
+ std::vector<double> values(int issue_age, int length) const;
+ std::vector<double> values_elaborated
+ (int issue_age
+ ,int length
+ ,e_actuarial_table_method method
+ ,int inforce_duration
+ ,int reset_duration
+ ) const;
+
+ private:
+ void load_aggregate_table (xml::element const& node);
+ void load_duration_table (xml::element const& node);
+ void load_select_table (xml::element const& node);
+ void load_select_and_ultimate_table(xml::element const& node);
+ void load_table_with_ages
+ (xml::element const& node
+ ,std::vector<double>& data
+ ,int& min_age
+ ,int& max_age
+ );
+
+ std::vector<double> specific_values(int issue_age, int length) const;
+
+ // Table parameters, in order read from table header.
+ char table_type_ ;
+ int min_age_ ;
+ int max_age_ ;
+ int select_period_ ;
+ int max_select_age_ ;
+
+ // Table data. For 1D tables (e_table_aggregate and e_table_duration),
this
+ // is the vector of values from min_age_ to max_age_.
+ // For e_table_select_and_ultimate, the content is organized by rows,
with
+ // select_period_ entries per row, with rows ranging from min_age_ to
+ // max_select_age_.
+ std::vector<double> data_;
+
+ // For e_table_select_and_ultimate, this vector contains the ultimate
+ // column. The first value, ultimate_[0], is for
min_age_+select_period_,
+ // the last is for max_select_age_.
+ std::vector<double> ultimate_;
+ };
- // For e_table_select_and_ultimate, this vector contains the ultimate
- // column. The first value, ultimate_[0], is for min_age_+select_period_,
- // the last is for max_select_age_.
- std::vector<double> ultimate_;
+ basic_table table_;
};
/// Read a table from a database in the binary format designed by the
--
1.7.11.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi] [PATCH 2/4] multi-dimensional tables,
Vaclav Slavik <=