lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [4808] Reimplement 'policy' product files (VS)


From: Greg Chicares
Subject: [lmi-commits] [4808] Reimplement 'policy' product files (VS)
Date: Wed, 24 Mar 2010 01:20:24 +0000

Revision: 4808
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4808
Author:   chicares
Date:     2010-03-24 01:20:23 +0000 (Wed, 24 Mar 2010)
Log Message:
-----------
Reimplement 'policy' product files (VS)

Modified Paths:
--------------
    lmi/trunk/ihs_proddata.cpp
    lmi/trunk/main_wx.cpp
    lmi/trunk/my_prod.cpp
    lmi/trunk/objects.make
    lmi/trunk/product_names.cpp

Modified: lmi/trunk/ihs_proddata.cpp
===================================================================
--- lmi/trunk/ihs_proddata.cpp  2010-03-23 17:13:58 UTC (rev 4807)
+++ lmi/trunk/ihs_proddata.cpp  2010-03-24 01:20:23 UTC (rev 4808)
@@ -42,11 +42,11 @@
 #include "assert_lmi.hpp"
 #include "data_directory.hpp"
 #include "platform_dependent.hpp" // access()
+#include "xml_serialize.hpp"
 
 #include <boost/filesystem/convenience.hpp>
 #include <boost/filesystem/path.hpp>
 
-#include <fstream>
 #include <string>
 
 //============================================================================
@@ -70,10 +70,18 @@
 {
     fs::path path(a_Filename);
     LMI_ASSERT(a_Filename == path.leaf());
-    path = fs::change_extension(path, ".pol");
+    path = fs::change_extension(path, ".policy");
     Read(AddDataDir(path.string()));
 }
 
+namespace
+{
+std::string xml_root_name()
+{
+    return "policy";
+}
+} // Unnamed namespace.
+
 //============================================================================
 void TProductData::Read(std::string const& a_Filename)
 {
@@ -86,10 +94,12 @@
             << LMI_FLUSH
             ;
         }
-    std::ifstream is(a_Filename.c_str());
 
-#   define GET_ELEMENT(name) std::getline(is, name, '\n')
+    xml_lmi::dom_parser parser(a_Filename);
+    xml::element const& root = parser.root_node(xml_root_name());
 
+#   define GET_ELEMENT(name) xml_serialize::get_element(root, #name, name)
+
     GET_ELEMENT(DatabaseFilename              );
     GET_ELEMENT(FundFilename                  );
     GET_ELEMENT(CorridorFilename              );
@@ -192,38 +202,18 @@
     GET_ELEMENT(MonthlyChargesPaymentFootnote );
 
 #   undef GET_ELEMENT
-
-    bool okay = is.good();
-    if(!okay)
-        {
-        fatal_error()
-            << "Unexpected end of product data file '"
-            << a_Filename
-            << "'. Try reinstalling."
-            << LMI_FLUSH
-            ;
-        }
-    std::string dummy;
-    is >> dummy;
-    okay = is.eof();
-    if(!okay)
-        {
-        fatal_error()
-            << "Data past expected end of product data file '"
-            << a_Filename
-            << "'. Try reinstalling."
-            << LMI_FLUSH
-            ;
-        }
 }
 
 //============================================================================
 void TProductData::Write(std::string const& a_Filename) const
 {
-    std::ofstream os(a_Filename.c_str());
+    xml_lmi::xml_document document(xml_root_name());
+    xml::element& root = document.root_node();
 
-#   define SET_ELEMENT(name) os << name << '\n'
+    xml_lmi::set_attr(root, "version", "0");
 
+#   define SET_ELEMENT(name) xml_serialize::set_element(root, #name, name)
+
     SET_ELEMENT(DatabaseFilename              );
     SET_ELEMENT(FundFilename                  );
     SET_ELEMENT(CorridorFilename              );
@@ -327,15 +317,13 @@
 
 #   undef SET_ELEMENT
 
-    if(!os.good())
-        {
-        fatal_error()
-            << "Unable to write product data file '"
-            << a_Filename
-            << "'."
-            << LMI_FLUSH
-            ;
-        }
+    // Instead of this:
+//    document.save(a_Filename);
+    // for the nonce, explicitly change the extension, in order to
+    // force external product-file code to use the new extension.
+    fs::path path(a_Filename, fs::native);
+    path = fs::change_extension(path, ".policy");
+    document.save(path.string());
 }
 
 //============================================================================
@@ -445,6 +433,6 @@
     foo.RoundingFilename = "sample.rnd";
     foo.TierFilename     = "sample.tir";
 
-    foo.Write(AddDataDir("sample.pol"));
+    foo.Write(AddDataDir("sample.policy"));
 }
 

Modified: lmi/trunk/main_wx.cpp
===================================================================
--- lmi/trunk/main_wx.cpp       2010-03-23 17:13:58 UTC (rev 4807)
+++ lmi/trunk/main_wx.cpp       2010-03-24 01:20:23 UTC (rev 4808)
@@ -374,9 +374,9 @@
     new(wx) wxDocTemplate
         (doc_manager_
         ,"Policy"
-        ,"*.pol"
+        ,"*.policy"
         ,""
-        ,"pol"
+        ,"policy"
         ,"Policy document"
         ,"Policy view"
         ,CLASSINFO(PolicyDocument)

Modified: lmi/trunk/my_prod.cpp
===================================================================
--- lmi/trunk/my_prod.cpp       2010-03-23 17:13:58 UTC (rev 4807)
+++ lmi/trunk/my_prod.cpp       2010-03-24 01:20:23 UTC (rev 4808)
@@ -156,7 +156,7 @@
     foo.RoundingFilename  = "sample.rnd";
     foo.TierFilename      = "sample.tir";
 
-    foo.Write(AddDataDir("sample.pol"));
+    foo.Write(AddDataDir("sample.policy"));
 
     // Another policy form....
 }

Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make      2010-03-23 17:13:58 UTC (rev 4807)
+++ lmi/trunk/objects.make      2010-03-24 01:20:23 UTC (rev 4808)
@@ -772,6 +772,7 @@
 product_file_test$(EXEEXT): \
   $(boost_filesystem_objects) \
   $(common_test_objects) \
+  $(xmlwrapp_objects) \
   data_directory.o \
   dbnames.o \
   expm1.o \
@@ -789,6 +790,7 @@
   rounding_rules.o \
   stratified_charges.o \
   timer.o \
+  xml_lmi.o \
 
 progress_meter_test$(EXEEXT): \
   $(common_test_objects) \

Modified: lmi/trunk/product_names.cpp
===================================================================
--- lmi/trunk/product_names.cpp 2010-03-23 17:13:58 UTC (rev 4807)
+++ lmi/trunk/product_names.cpp 2010-03-24 01:20:23 UTC (rev 4808)
@@ -44,7 +44,7 @@
     fs::directory_iterator end_i;
     for(; i != end_i; ++i)
         {
-        if(is_directory(*i) || ".pol" != fs::extension(*i))
+        if(is_directory(*i) || ".policy" != fs::extension(*i))
             {
             continue;
             }





reply via email to

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