[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5500] Add a virtual function; refactor
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5500] Add a virtual function; refactor |
Date: |
Mon, 18 Jun 2012 17:12:31 +0000 |
Revision: 5500
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5500
Author: chicares
Date: 2012-06-18 17:12:30 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
Add a virtual function; refactor
Modified Paths:
--------------
lmi/trunk/antediluvian_stubs.cpp
lmi/trunk/product_data.cpp
lmi/trunk/product_data.hpp
lmi/trunk/xml_serializable.hpp
lmi/trunk/xml_serializable.tpp
Modified: lmi/trunk/antediluvian_stubs.cpp
===================================================================
--- lmi/trunk/antediluvian_stubs.cpp 2012-06-17 10:08:26 UTC (rev 5499)
+++ lmi/trunk/antediluvian_stubs.cpp 2012-06-18 17:12:30 UTC (rev 5500)
@@ -108,6 +108,13 @@
return empty_string;
}
+product_data::value_type product_data::fetch_element
+ (xml::element const&
+ ) const
+{
+ return value_type();
+}
+
void product_data::read_element
(xml::element const&
,std::string const&
@@ -135,14 +142,14 @@
void product_data::redintegrate_ex_ante
(int
,std::string const&
- ,std::string &
+ ,value_type &
) const
{}
void product_data::redintegrate_ex_post
(int
- ,std::map<std::string, std::string> const&
- ,std::list<std::string> const&
+ ,std::map<std::string,value_type> const&
+ ,std::list<std::string> const&
)
{}
Modified: lmi/trunk/product_data.cpp
===================================================================
--- lmi/trunk/product_data.cpp 2012-06-17 10:08:26 UTC (rev 5499)
+++ lmi/trunk/product_data.cpp 2012-06-18 17:12:30 UTC (rev 5500)
@@ -296,6 +296,18 @@
return s;
}
+product_data::value_type product_data::fetch_element
+ (xml::element const& e
+ ) const
+{
+ glossed_string r;
+ xml_serialize::from_xml(e, r);
+ // For the nonce, std::string is used as value_type,
+ // so one of {datum,gloss} must arbitrarily be discarded;
+ // choose the one that's less likely to mask a visible error.
+ return r.gloss();
+}
+
/// This override doesn't call redintegrate_ex_ante(); that wouldn't
/// make sense, because the underlying datatype is just a doublet of
/// strings, and strings can legitimately contain anything.
@@ -342,7 +354,7 @@
void product_data::redintegrate_ex_ante
(int file_version
,std::string const& // name
- ,std::string & // value
+ ,value_type & // value
) const
{
if(class_version() == file_version)
@@ -357,9 +369,9 @@
}
void product_data::redintegrate_ex_post
- (int file_version
- ,std::map<std::string, std::string> const& detritus_map
- ,std::list<std::string> const& residuary_names
+ (int file_version
+ ,std::map<std::string,value_type> const& detritus_map
+ ,std::list<std::string> const& residuary_names
)
{
if(class_version() == file_version)
Modified: lmi/trunk/product_data.hpp
===================================================================
--- lmi/trunk/product_data.hpp 2012-06-17 10:08:26 UTC (rev 5499)
+++ lmi/trunk/product_data.hpp 2012-06-18 17:12:30 UTC (rev 5500)
@@ -80,6 +80,9 @@
, public xml_serializable <product_data>
, public MemberSymbolTable <product_data>
{
+ // For the nonce, value_type is guaranteed to be std::string.
+ typedef std::string value_type;
+
friend class PolicyDocument;
public:
@@ -102,6 +105,9 @@
virtual std::string const& xml_root_name() const;
// xml_serializable overrides.
+ virtual value_type fetch_element
+ (xml::element const& e
+ ) const;
virtual void read_element
(xml::element const& e
,std::string const& name
@@ -119,12 +125,12 @@
virtual void redintegrate_ex_ante
(int file_version
,std::string const& name
- ,std::string & value
+ ,value_type & value
) const;
virtual void redintegrate_ex_post
- (int file_version
- ,std::map<std::string, std::string> const& detritus_map
- ,std::list<std::string> const& residuary_names
+ (int file_version
+ ,std::map<std::string,value_type> const& detritus_map
+ ,std::list<std::string> const& residuary_names
);
// Names of files that contain other product data.
Modified: lmi/trunk/xml_serializable.hpp
===================================================================
--- lmi/trunk/xml_serializable.hpp 2012-06-17 10:08:26 UTC (rev 5499)
+++ lmi/trunk/xml_serializable.hpp 2012-06-18 17:12:30 UTC (rev 5500)
@@ -65,6 +65,9 @@
virtual std::string const& xml_root_name() const = 0;
// Reading and writing.
+ virtual value_type fetch_element
+ (xml::element const& e
+ ) const;
virtual void read_element
(xml::element const& e
,std::string const& name
Modified: lmi/trunk/xml_serializable.tpp
===================================================================
--- lmi/trunk/xml_serializable.tpp 2012-06-17 10:08:26 UTC (rev 5499)
+++ lmi/trunk/xml_serializable.tpp 2012-06-18 17:12:30 UTC (rev 5500)
@@ -143,10 +143,9 @@
else if(is_detritus(node_tag))
{
// Hold certain obsolete entities that must be translated.
- // For the nonce, value_type is guaranteed to be std::string.
- value_type e = xml_lmi::get_content(*child);
- redintegrate_ex_ante(file_version, node_tag, e);
- detritus_map[node_tag] = e;
+ value_type v = fetch_element(*child);
+ redintegrate_ex_ante(file_version, node_tag, v);
+ detritus_map[node_tag] = v;
}
else
{
@@ -223,6 +222,17 @@
throw "Unreachable--silences a compiler diagnostic.";
}
+/// Retrieve an xml element's value.
+
+template<typename T>
+typename xml_serializable<T>::value_type xml_serializable<T>::fetch_element
+ (xml::element const& e
+ ) const
+{
+ // For the nonce, value_type is guaranteed to be std::string.
+ return xml_lmi::get_content(e);
+}
+
/// Read an xml element.
///
/// This default implementation is appropriate only for streamable
@@ -244,10 +254,9 @@
,int file_version
)
{
- // For the nonce, value_type is guaranteed to be std::string.
- std::string s = xml_lmi::get_content(e);
- redintegrate_ex_ante(file_version, name, s);
- t()[name] = s;
+ value_type v = fetch_element(e);
+ redintegrate_ex_ante(file_version, name, v);
+ t()[name] = v;
}
/// Write an xml element.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5500] Add a virtual function; refactor,
Greg Chicares <=