lmi
[Top][All Lists]
Advanced

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

[lmi] [PATCH 3/4] multi-dimensional tables


From: Vaclav Slavik
Subject: [lmi] [PATCH 3/4] multi-dimensional tables
Date: Thu, 02 Aug 2012 14:32:25 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0

Pass the node with data to basic_table loading function,
not its parent.

(This will simplify loading of multi-dim files in the 4th patch.)

---
 actuarial_table.cpp | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/actuarial_table.cpp b/actuarial_table.cpp
index 1e6ad6d..4fda41f 100644
--- a/actuarial_table.cpp
+++ b/actuarial_table.cpp
@@ -125,7 +125,25 @@ 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);
+    xml::const_nodes_view const children = root.elements();
+    xml::const_nodes_view::const_iterator child = children.begin();
+
+    // we have no use for the description element, skip it:
+    if(child != children.end() && strcmp(child->get_name(), "description") == 
0)
+        child++;
+
+    if(child == children.end())
+        {
+        fatal_error()
+            << "Empty"
+            << "Table file '"
+            << filename
+            << "' doesn't contain any data."
+            << LMI_FLUSH
+            ;
+        }
+
+    table_.load(*child);
 }
 
 /// Read a given number of values for a given issue age.
@@ -171,28 +189,30 @@ xml_actuarial_table::basic_table::basic_table()
 void xml_actuarial_table::basic_table::load(xml::element const& root)
 {
     // SOA !! Implement loading of multi-dimensional tables as well.
-    xml::node::const_iterator i;
+    std::string const name(root.get_name());
 
-    if (root.end() != (i = root.find("aggregate")))
+    if (name == "aggregate")
         {
-        load_aggregate_table(*i);
+        load_aggregate_table(root);
         }
-    else if (root.end() != (i = root.find("duration")))
+    else if (name == "duration")
         {
-        load_duration_table(*i);
+        load_duration_table(root);
         }
-    else if (root.end() != (i = root.find("select")))
+    else if (name == "select")
         {
-        load_select_table(*i);
+        load_select_table(root);
         }
-    else if (root.end() != (i = root.find("select-and-ultimate")))
+    else if (name == "select-and-ultimate")
         {
-        load_select_and_ultimate_table(*i);
+        load_select_and_ultimate_table(root);
         }
     else
         {
         fatal_error()
-            << "Required data element not found."
+            << "Unknown data element '"
+            << name
+            << "'."
             << LMI_FLUSH
             ;
         }
-- 
1.7.11.3




reply via email to

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