lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [4824] Add file functions; set default name-check policy


From: Greg Chicares
Subject: [lmi-commits] [4824] Add file functions; set default name-check policy
Date: Fri, 02 Apr 2010 01:54:19 +0000

Revision: 4824
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4824
Author:   chicares
Date:     2010-04-02 01:54:18 +0000 (Fri, 02 Apr 2010)
Log Message:
-----------
Add file functions; set default name-check policy

Modified Paths:
--------------
    lmi/trunk/generate_product_files.cpp
    lmi/trunk/product_file_test.cpp
    lmi/trunk/xml_serializable.hpp
    lmi/trunk/xml_serializable.tpp

Modified: lmi/trunk/generate_product_files.cpp
===================================================================
--- lmi/trunk/generate_product_files.cpp        2010-04-01 03:00:51 UTC (rev 
4823)
+++ lmi/trunk/generate_product_files.cpp        2010-04-02 01:54:18 UTC (rev 
4824)
@@ -30,6 +30,7 @@
 #include "ihs_funddata.hpp"
 #include "ihs_rnddata.hpp"
 #include "main_common.hpp"
+#include "path_utility.hpp" // initialize_filesystem()
 #include "product_data.hpp"
 #include "stratified_charges.hpp"
 
@@ -38,6 +39,8 @@
 
 int try_main(int, char*[])
 {
+    initialize_filesystem();
+
     std::cout << "Generating product files." << std::endl;
 
     DBDictionary::instance() .WriteSampleDBFile                  ();

Modified: lmi/trunk/product_file_test.cpp
===================================================================
--- lmi/trunk/product_file_test.cpp     2010-04-01 03:00:51 UTC (rev 4823)
+++ lmi/trunk/product_file_test.cpp     2010-04-02 01:54:18 UTC (rev 4824)
@@ -29,6 +29,7 @@
 #include "ihs_dbdict.hpp"
 #include "ihs_funddata.hpp"
 #include "ihs_rnddata.hpp"
+#include "path_utility.hpp" // initialize_filesystem()
 #include "product_data.hpp"
 #include "stratified_charges.hpp"
 
@@ -42,6 +43,7 @@
   public:
     static void test()
         {
+        initialize_filesystem();
         write_all_files();
         assay_speed();
         }

Modified: lmi/trunk/xml_serializable.hpp
===================================================================
--- lmi/trunk/xml_serializable.hpp      2010-04-01 03:00:51 UTC (rev 4823)
+++ lmi/trunk/xml_serializable.hpp      2010-04-02 01:54:18 UTC (rev 4824)
@@ -29,6 +29,8 @@
 #include "so_attributes.hpp"
 #include "xml_lmi_fwd.hpp"
 
+#include <boost/filesystem/path.hpp>
+
 #include <list>
 #include <map>
 #include <string>
@@ -43,10 +45,15 @@
   public:
     virtual ~xml_serializable();
 
+    void load(fs::path const&);
+    void save(fs::path const&) const;
+
     void read (xml::element const&);
     void write(xml::element&) const;
 
   private:
+    void immit_members_into(xml::element&) const;
+
     virtual int         class_version() const = 0;
     virtual std::string xml_root_name() const = 0;
     virtual bool        is_detritus(std::string const&) const = 0;

Modified: lmi/trunk/xml_serializable.tpp
===================================================================
--- lmi/trunk/xml_serializable.tpp      2010-04-01 03:00:51 UTC (rev 4823)
+++ lmi/trunk/xml_serializable.tpp      2010-04-02 01:54:18 UTC (rev 4824)
@@ -30,15 +30,12 @@
 
 #include "alert.hpp"
 #include "any_member.hpp" // MemberSymbolTable<>
+#include "platform_dependent.hpp" // access()
 #include "value_cast.hpp"
 #include "xml_lmi.hpp"
 
-#if !defined __BORLANDC__
-#   include <boost/static_assert.hpp>
-#   include <boost/type_traits.hpp>
-#else  // defined __BORLANDC__
-#   define BOOST_STATIC_ASSERT(deliberately_ignored) class IgNoRe
-#endif // defined __BORLANDC__
+#include <boost/static_assert.hpp>
+#include <boost/type_traits.hpp>
 
 #include <xmlwrapp/nodes_view.h>
 
@@ -62,6 +59,32 @@
 }
 
 template<typename T>
+void xml_serializable<T>::load(fs::path const& path)
+{
+    if(access(path.string().c_str(), R_OK))
+        {
+        fatal_error()
+            << "File '"
+            << path.string()
+            << "' is required but could not be found. Try reinstalling."
+            << LMI_FLUSH
+            ;
+        }
+
+    xml_lmi::dom_parser parser(path.string());
+    xml::element const& root = parser.root_node(xml_root_name());
+    read(root);
+}
+
+template<typename T>
+void xml_serializable<T>::save(fs::path const& path) const
+{
+    xml_lmi::xml_document document(xml_root_name());
+    immit_members_into(document.root_node());
+    document.save(path.string());
+}
+
+template<typename T>
 void xml_serializable<T>::read(xml::element const& x)
 {
     T& t = static_cast<T&>(*this);
@@ -148,10 +171,16 @@
 template<typename T>
 void xml_serializable<T>::write(xml::element& x) const
 {
+    xml::element root(xml_root_name().c_str());
+    immit_members_into(root);
+    x.push_back(root);
+}
+
+template<typename T>
+void xml_serializable<T>::immit_members_into(xml::element& root) const
+{
     T const& t = static_cast<T const&>(*this);
 
-    xml::element root(xml_root_name().c_str());
-
 // XMLWRAPP !! There's no way to set an integer attribute.
     std::string const version(value_cast<std::string>(class_version()));
     xml_lmi::set_attr(root, "version", version.c_str());
@@ -163,7 +192,5 @@
         std::string value = t[node_tag].str();
         root.push_back(xml::element(node_tag.c_str(), value.c_str()));
         }
-
-    x.push_back(root);
 }
 





reply via email to

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