[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] [PATCH 3/4] Split actuarial_table into base class and SOA implemen
From: |
Vaclav Slavik |
Subject: |
[lmi] [PATCH 3/4] Split actuarial_table into base class and SOA implementation. |
Date: |
Thu, 17 May 2012 17:27:05 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
Split actuarial_table into base class and SOA implementation.
Use actuarial_base for shared code (mainly metadata and
values_elaborated()). Move implementation of SOA binary format loading
into soa_actuarial_table.
---
actuarial_table.cpp | 66 +++++++++++++++++++++++---------------------
actuarial_table.hpp | 76 +++++++++++++++++++++++++++++++++------------------
2 files changed, 84 insertions(+), 58 deletions(-)
diff --git a/actuarial_table.cpp b/actuarial_table.cpp
index b535f4e..b875dac 100644
--- a/actuarial_table.cpp
+++ b/actuarial_table.cpp
@@ -83,39 +83,18 @@ namespace
}
} // Unnamed namespace.
-actuarial_table::actuarial_table(std::string const& filename, int table_number)
- :filename_ (filename)
- ,table_number_ (table_number)
- ,table_type_ (-1)
+actuarial_table_base::actuarial_table_base()
+ :table_type_ (-1)
,min_age_ (-1)
,max_age_ (-1)
,select_period_ (-1)
,max_select_age_ (-1)
- ,table_offset_ (-1)
-{
- if(table_number_ <= 0)
- {
- fatal_error()
- << "There is no table number "
- << table_number_
- << " in file '"
- << filename_
- << "'."
- << LMI_FLUSH
- ;
- }
-
- find_table();
- parse_table();
-}
-
-actuarial_table::~actuarial_table()
{
}
/// Read a given number of values for a given issue age.
-std::vector<double> actuarial_table::values(int issue_age, int length) const
+std::vector<double> actuarial_table_base::values(int issue_age, int length)
const
{
return specific_values(issue_age, length);
}
@@ -127,7 +106,7 @@ std::vector<double> 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> actuarial_table::values_elaborated
+std::vector<double> actuarial_table_base::values_elaborated
(int issue_age
,int length
,e_actuarial_table_method method
@@ -192,6 +171,31 @@ std::vector<double> actuarial_table::values_elaborated
}
}
+soa_actuarial_table::soa_actuarial_table(std::string const& filename, int
table_number)
+ :filename_ (filename)
+ ,table_number_ (table_number)
+ ,table_offset_ (-1)
+{
+ if(table_number_ <= 0)
+ {
+ fatal_error()
+ << "There is no table number "
+ << table_number_
+ << " in file '"
+ << filename_
+ << "'."
+ << LMI_FLUSH
+ ;
+ }
+
+ find_table();
+ parse_table();
+}
+
+soa_actuarial_table::~soa_actuarial_table()
+{
+}
+
/// Find the table specified by table_number_.
///
/// SOA documentation does not specify the domain of table numbers,
@@ -207,7 +211,7 @@ std::vector<double> actuarial_table::values_elaborated
/// Asserting that the table number is nonzero makes it safe to use
/// zero as a sentry.
-void actuarial_table::find_table()
+void soa_actuarial_table::find_table()
{
LMI_ASSERT(0 != table_number_);
@@ -302,7 +306,7 @@ void actuarial_table::find_table()
/// 15 2-byte integer: Maximum select age (if zero, then it's max age)
/// 17 8-byte doubles: Table values
-void actuarial_table::parse_table()
+void soa_actuarial_table::parse_table()
{
LMI_ASSERT(-1 == table_type_ );
LMI_ASSERT(-1 == min_age_ );
@@ -447,7 +451,7 @@ void actuarial_table::parse_table()
/// taken as unlimited, so its value should be max_age_; this
/// implementation makes it so after the fact.
-void actuarial_table::read_values(std::istream& is, int nominal_length)
+void soa_actuarial_table::read_values(std::istream& is, int nominal_length)
{
if('S' != table_type_)
{
@@ -504,7 +508,7 @@ void actuarial_table::read_values(std::istream& is, int
nominal_length)
/// considered preferable to throw an exception, in case permitting
/// issue age to exceed max_select_age_ is an inadvertent mistake.
-std::vector<double> actuarial_table::specific_values
+std::vector<double> soa_actuarial_table::specific_values
(int issue_age
,int length
) const
@@ -583,7 +587,7 @@ std::vector<double> actuarial_table_rates
,int length
)
{
- actuarial_table z(table_filename, table_number);
+ soa_actuarial_table z(table_filename, table_number);
return z.values(issue_age, length);
}
@@ -597,7 +601,7 @@ std::vector<double> actuarial_table_rates_elaborated
,int reset_duration
)
{
- actuarial_table z(table_filename, table_number);
+ soa_actuarial_table z(table_filename, table_number);
return z.values_elaborated
(issue_age
,length
diff --git a/actuarial_table.hpp b/actuarial_table.hpp
index 0d29549..94ec3e4 100644
--- a/actuarial_table.hpp
+++ b/actuarial_table.hpp
@@ -115,28 +115,14 @@ enum e_actuarial_table_method
,e_reenter_upon_rate_reset = 2
};
-/// Read a table from a database in the binary format designed by the
-/// Society of Actuaries (SOA) and used for the tables SOA publishes.
-///
-/// Do not check CRCs of these tables as the SOA software does. Tests
-/// show that CRC checking makes the illustration system considerably
-/// slower. Data should generally be validated against published
-/// checksums when acquired (e.g., downloaded), not before each use.
-/// CRC checking was useful for guarding against transmission errors
-/// when the first SOA tables were published, prior to the internet
-/// revolution, but today it's a relic of a bygone era, and lmi uses a
-/// stronger algorithm for data authentication already. Besides, the
-/// CRCs in the SOA's tables have always been incorrect, and the SOA
-/// has apparently chosen to leave them that way for backward
-/// compatibility.
-class actuarial_table
- : private lmi::uncopyable <actuarial_table>
- ,virtual private obstruct_slicing<actuarial_table>
+/// Base class for actuarial tables, both XML and binary.
+// SOA !! This is only temporary, merge with xml_actuarial_table into
+// single class once we remove binary SOA format support
+class actuarial_table_base
{
public:
- actuarial_table(std::string const& filename, int table_number);
- ~actuarial_table();
+ actuarial_table_base();
std::vector<double> values(int issue_age, int length) const;
std::vector<double> values_elaborated
@@ -147,13 +133,53 @@ class actuarial_table
,int reset_duration
) const;
- std::string const& filename () const {return filename_ ;}
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:
+ virtual std::vector<double> specific_values(int issue_age, int length)
const = 0;
+
+ // Table parameters, in order read from table header.
+ char table_type_ ;
+ int min_age_ ;
+ int max_age_ ;
+ int select_period_ ;
+ int max_select_age_ ;
+};
+
+/// Read a table from a database in the binary format designed by the
+/// Society of Actuaries (SOA) and used for the tables SOA publishes.
+///
+/// This is deprecated, old format, this class' code is left in only
+/// temporarily for the purpose of validating the new XML-based format
+/// loader's correctness.
+///
+/// Do not check CRCs of these tables as the SOA software does. Tests
+/// show that CRC checking makes the illustration system considerably
+/// slower. Data should generally be validated against published
+/// checksums when acquired (e.g., downloaded), not before each use.
+/// CRC checking was useful for guarding against transmission errors
+/// when the first SOA tables were published, prior to the internet
+/// revolution, but today it's a relic of a bygone era, and lmi uses a
+/// stronger algorithm for data authentication already. Besides, the
+/// CRCs in the SOA's tables have always been incorrect, and the SOA
+/// has apparently chosen to leave them that way for backward
+/// compatibility.
+
+class soa_actuarial_table
+ : public actuarial_table_base
+ , private lmi::uncopyable <soa_actuarial_table>
+ ,virtual private obstruct_slicing<soa_actuarial_table>
+{
+ public:
+ soa_actuarial_table(std::string const& filename, int table_number);
+ ~soa_actuarial_table();
+
+ std::string const& filename() const {return filename_ ;}
+
private:
void find_table();
void parse_table();
@@ -164,18 +190,14 @@ class actuarial_table
std::string filename_ ;
int table_number_ ;
- // 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.
std::vector<double> data_;
std::streampos table_offset_;
};
+typedef soa_actuarial_table actuarial_table;
+
/// Convenience function: read particular values from a table stored
/// in the SOA table-manager format.
--
1.7.10.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi] [PATCH 3/4] Split actuarial_table into base class and SOA implementation.,
Vaclav Slavik <=