[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4843] Refactor, simplifying the xml_serializable API
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4843] Refactor, simplifying the xml_serializable API |
Date: |
Mon, 19 Apr 2010 20:44:47 +0000 |
Revision: 4843
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4843
Author: chicares
Date: 2010-04-19 20:44:46 +0000 (Mon, 19 Apr 2010)
Log Message:
-----------
Refactor, simplifying the xml_serializable API
Modified Paths:
--------------
lmi/trunk/input.hpp
lmi/trunk/input_xml_io.cpp
lmi/trunk/product_data.cpp
lmi/trunk/product_data.hpp
lmi/trunk/xml_serializable.hpp
lmi/trunk/xml_serializable.tpp
Modified: lmi/trunk/input.hpp
===================================================================
--- lmi/trunk/input.hpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/input.hpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -174,7 +174,7 @@
// xml_serializable overrides.
virtual bool is_detritus(std::string const&) const;
- virtual bool redintegrate_ex_ante
+ virtual void redintegrate_ex_ante
(int file_version
,std::string const& name
,std::string & value
Modified: lmi/trunk/input_xml_io.cpp
===================================================================
--- lmi/trunk/input_xml_io.cpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/input_xml_io.cpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -116,7 +116,7 @@
return v.end() != std::find(v.begin(), v.end(), s);
}
-bool Input::redintegrate_ex_ante
+void Input::redintegrate_ex_ante
(int file_version
,std::string const& name
,std::string & value
@@ -124,7 +124,7 @@
{
if(class_version() == file_version)
{
- return false;
+ return;
}
// Prior to version 3, 'SolveType' distinguished:
@@ -268,8 +268,6 @@
;
}
}
-
- return true;
}
void Input::redintegrate_ex_post
Modified: lmi/trunk/product_data.cpp
===================================================================
--- lmi/trunk/product_data.cpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/product_data.cpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -299,7 +299,6 @@
void product_data::read_element
(xml::element const& parent
,std::string const& name
- ,product_data& // t [actually superfluous]
,int // file_version
)
{
@@ -310,7 +309,6 @@
void product_data::write_element
(xml::element& parent
,std::string const& name
- ,product_data const& // t [actually superfluous]
) const
{
glossed_string const& r = *member_cast<glossed_string>(operator[](name));
Modified: lmi/trunk/product_data.hpp
===================================================================
--- lmi/trunk/product_data.hpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/product_data.hpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -107,13 +107,11 @@
virtual void read_element
(xml::element const& parent
,std::string const& name
- ,product_data&
,int file_version
);
virtual void write_element
(xml::element& parent
,std::string const& name
- ,product_data const&
) const;
virtual bool is_detritus(std::string const&) const;
Modified: lmi/trunk/xml_serializable.hpp
===================================================================
--- lmi/trunk/xml_serializable.hpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/xml_serializable.hpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -53,6 +53,8 @@
private:
// Private non-virtuals.
+ T & t() ;
+ T const& t() const;
void immit_members_into(xml::element&) const;
// Class (T) identification.
@@ -63,18 +65,16 @@
virtual void read_element
(xml::element const& parent
,std::string const& name
- ,T&
,int file_version
);
virtual void write_element
(xml::element& parent
,std::string const& name
- ,T const&
) const;
// Backward compatibility.
virtual bool is_detritus(std::string const&) const;
- virtual bool redintegrate_ex_ante
+ virtual void redintegrate_ex_ante
(int file_version
,std::string const& name
,std::string & value
Modified: lmi/trunk/xml_serializable.tpp
===================================================================
--- lmi/trunk/xml_serializable.tpp 2010-04-18 21:19:22 UTC (rev 4842)
+++ lmi/trunk/xml_serializable.tpp 2010-04-19 20:44:46 UTC (rev 4843)
@@ -47,8 +47,8 @@
xml_serializable<T>::~xml_serializable()
{
// Assert that static_cast<T cv&> doesn't engender undefined
- // behavior, and that the base class provides the expected
- // operator[]() and member_names() functions.
+ // behavior, and that class T provides the expected operator[]()
+ // and member_names() functions.
//
// Double parentheses: don't parse comma as a macro parameter separator.
BOOST_STATIC_ASSERT
@@ -87,8 +87,6 @@
template<typename T>
void xml_serializable<T>::read(xml::element const& x)
{
- T& t = static_cast<T&>(*this);
-
if(xml_root_name() != x.get_name())
{
fatal_error()
@@ -122,8 +120,8 @@
std::list<std::string> residuary_names;
std::copy
- (t.member_names().begin()
- ,t.member_names().end()
+ (t().member_names().begin()
+ ,t().member_names().end()
,std::back_inserter(residuary_names)
);
std::list<std::string>::iterator current_member;
@@ -140,7 +138,7 @@
);
if(residuary_names.end() != current_member)
{
- read_element(x, node_tag, t, file_version);
+ read_element(x, node_tag, file_version);
residuary_names.erase(current_member);
}
else if(is_detritus(node_tag))
@@ -172,19 +170,39 @@
x.push_back(root);
}
+/// The associated instance of class T.
+///
+/// This member function is 'inline' because it wouldn't make sense
+/// for any external file to call it.
+
template<typename T>
+inline T& xml_serializable<T>::t()
+{
+ return static_cast<T&>(*this);
+}
+
+/// The associated instance of class T.
+///
+/// This member function is 'inline' because it wouldn't make sense
+/// for any external file to call it.
+
+template<typename T>
+inline T const& xml_serializable<T>::t() const
+{
+ return static_cast<T const&>(*this);
+}
+
+template<typename T>
void xml_serializable<T>::immit_members_into(xml::element& root) const
{
- T const& t = static_cast<T const&>(*this);
-
// 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());
std::vector<std::string>::const_iterator i;
- for(i = t.member_names().begin(); i != t.member_names().end(); ++i)
+ for(i = t().member_names().begin(); i != t().member_names().end(); ++i)
{
- write_element(root, *i, t);
+ write_element(root, *i);
}
}
@@ -224,14 +242,13 @@
void xml_serializable<T>::read_element
(xml::element const& parent
,std::string const& name
- ,T& t
,int file_version
)
{
xml::node::const_iterator i = xml_lmi::retrieve_element(parent, name);
std::string s = xml_lmi::get_content(*i);
redintegrate_ex_ante(file_version, name, s);
- t[name] = s;
+ t()[name] = s;
}
/// Write an xml element.
@@ -251,10 +268,9 @@
void xml_serializable<T>::write_element
(xml::element& parent
,std::string const& name
- ,T const& t
) const
{
- parent.push_back(xml::element(name.c_str(), t[name].str().c_str()));
+ parent.push_back(xml::element(name.c_str(), t()[name].str().c_str()));
}
/// Ascertain whether an element-tag is obsolete.
@@ -291,12 +307,10 @@
/// This transformation avoids attempting to assign 'M' to a 'gender'
/// enumeration, which would elicit a runtime error.
///
-/// The element's text contents are given as a string argument; the
-/// return value is 'true' if the string was modified, and 'false'
-/// otherwise.
+/// The element's text contents are given as a modifiable reference.
template<typename T>
-bool xml_serializable<T>::redintegrate_ex_ante
+void xml_serializable<T>::redintegrate_ex_ante
(int file_version
,std::string const& // name
,std::string & // value
@@ -304,17 +318,14 @@
{
if(class_version() == file_version)
{
- return false;
+ return;
}
- else
- {
- fatal_error()
- << "Incompatible file version."
- << " An explicit override is necessary."
- << LMI_FLUSH
- ;
- return true; // Stifle compiler warning.
- }
+
+ fatal_error()
+ << "Incompatible file version."
+ << " An explicit override is necessary."
+ << LMI_FLUSH
+ ;
}
/// Provide for backward compatibility after assigning values.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4843] Refactor, simplifying the xml_serializable API,
Greg Chicares <=