[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4977] Refactor, deriving stratified_charges from xml_seri
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4977] Refactor, deriving stratified_charges from xml_serializable |
Date: |
Tue, 08 Jun 2010 12:41:33 +0000 |
Revision: 4977
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4977
Author: chicares
Date: 2010-06-08 12:41:33 +0000 (Tue, 08 Jun 2010)
Log Message:
-----------
Refactor, deriving stratified_charges from xml_serializable
Modified Paths:
--------------
lmi/trunk/dbdict.cpp
lmi/trunk/dbdict.hpp
Modified: lmi/trunk/dbdict.cpp
===================================================================
--- lmi/trunk/dbdict.cpp 2010-06-06 23:21:21 UTC (rev 4976)
+++ lmi/trunk/dbdict.cpp 2010-06-08 12:41:33 UTC (rev 4977)
@@ -27,6 +27,7 @@
#endif // __BORLANDC__
#include "dbdict.hpp"
+#include "xml_serializable.tpp"
#include "alert.hpp"
#include "assert_lmi.hpp"
@@ -47,6 +48,8 @@
#include <limits>
+template class xml_serializable<DBDictionary>;
+
std::string DBDictionary::cached_filename_;
namespace xml_serialize
@@ -391,14 +394,6 @@
ascribe("SecondaryHurdle" , &DBDictionary::SecondaryHurdle );
}
-namespace
-{
-std::string xml_root_name()
-{
- return "database";
-}
-} // Unnamed namespace.
-
/// Read and cache a database file.
///
/// Perform the expensive operation of reading the dictionary from
@@ -412,25 +407,15 @@
return;
}
- cached_filename_ = filename;
-
- if(access(filename.c_str(), R_OK))
+ try
{
- InvalidateCache();
- fatal_error()
- << "File '"
- << filename
- << "' is required but could not be found. Try reinstalling."
- << LMI_FLUSH
- ;
+ cached_filename_ = filename;
+ load(filename);
}
-
- xml_lmi::dom_parser parser(filename);
- xml::element const& root = parser.root_node(xml_root_name());
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
+ catch(...)
{
- xml_serialize::get_element(root, *i, datum(*i));
+ InvalidateCache();
+ report_exception();
}
}
@@ -445,29 +430,53 @@
cached_filename_.clear();
}
-void DBDictionary::WriteDB(std::string const& filename)
+/// Save file, invalidating the cache.
+///
+/// If data are modified (by the GUI product editor) and saved under a
+/// new name, the cache must be invalidated. Otherwise, calling Init()
+/// with the name of the intact original file would fail to reload the
+/// unmodified data.
+
+void DBDictionary::WriteDB(std::string const& filename) const
{
InvalidateCache();
+ save(filename);
+}
- xml_lmi::xml_document document(xml_root_name());
- xml::element& root = document.root_node();
+/// Backward-compatibility serial number of this class's xml version.
+///
+/// version 0: 20100608T1241Z
- xml_lmi::set_attr(root, "version", "0");
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
- {
- xml_serialize::set_element(root, *i, datum(*i));
- }
+int DBDictionary::class_version() const
+{
+ return 0;
+}
- // Instead of this:
-// document.save(filename);
- // for the nonce, explicitly change the extension, in order to
- // force external product-file code to use the new extension.
- fs::path path(filename, fs::native);
- path = fs::change_extension(path, ".database");
- document.save(path.string());
+std::string DBDictionary::xml_root_name() const
+{
+ return "database";
}
+/// This override doesn't call redintegrate_ex_ante(); that wouldn't
+/// make sense, at least not for now.
+
+void DBDictionary::read_element
+ (xml::element const& e
+ ,std::string const& name
+ ,int // file_version
+ )
+{
+ xml_serialize::from_xml(e, datum(name));
+}
+
+void DBDictionary::write_element
+ (xml::element& parent
+ ,std::string const& name
+ ) const
+{
+ xml_serialize::set_element(parent, name, datum(name));
+}
+
/// Set a value. (The historical name "Add" is now misleading.)
void DBDictionary::Add(database_entity const& e)
Modified: lmi/trunk/dbdict.hpp
===================================================================
--- lmi/trunk/dbdict.hpp 2010-06-06 23:21:21 UTC (rev 4976)
+++ lmi/trunk/dbdict.hpp 2010-06-08 12:41:33 UTC (rev 4977)
@@ -30,6 +30,7 @@
#include "dbvalue.hpp"
#include "obstruct_slicing.hpp"
#include "so_attributes.hpp"
+#include "xml_serializable.hpp"
#include <boost/utility.hpp>
@@ -40,6 +41,7 @@
class LMI_SO DBDictionary
: private boost::noncopyable
,virtual private obstruct_slicing <DBDictionary>
+ , public xml_serializable <DBDictionary>
, public MemberSymbolTable <DBDictionary>
{
friend class DatabaseDocument;
@@ -65,12 +67,27 @@
database_entity& datum(std::string const&);
- void WriteDB(std::string const& filename);
+ void WriteDB(std::string const& filename) const;
void Add(database_entity const&);
void InitDB();
static void InvalidateCache();
+ // xml_serializable required implementation.
+ virtual int class_version() const;
+ virtual std::string xml_root_name() const;
+
+ // xml_serializable overrides.
+ virtual void read_element
+ (xml::element const& e
+ ,std::string const& name
+ ,int file_version
+ );
+ virtual void write_element
+ (xml::element& parent
+ ,std::string const& name
+ ) const;
+
static std::string cached_filename_;
database_entity MinIssAge ;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4977] Refactor, deriving stratified_charges from xml_serializable,
Greg Chicares <=