[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5501] Fix defect noted 20120616T1210Z
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5501] Fix defect noted 20120616T1210Z |
Date: |
Mon, 18 Jun 2012 18:35:31 +0000 |
Revision: 5501
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5501
Author: chicares
Date: 2012-06-18 18:35:29 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
Fix defect noted 20120616T1210Z
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/product_data.cpp
lmi/trunk/product_data.hpp
lmi/trunk/xml_serializable.hpp
lmi/trunk/xml_serializable.tpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2012-06-18 17:12:30 UTC (rev 5500)
+++ lmi/trunk/ChangeLog 2012-06-18 18:35:29 UTC (rev 5501)
@@ -30316,3 +30316,20 @@
be stored in a map (supra, at 20120616T1210Z). Privacy had been simply
a default choice that afforded no important protective value.
+20120618T1712Z <address@hidden> [578]
+
+ antediluvian_stubs.cpp
+ product_data.cpp
+ product_data.hpp
+ xml_serializable.hpp
+ xml_serializable.tpp
+Add a virtual function; refactor.
+
+20120618T1835Z <address@hidden> [578]
+
+ product_data.cpp
+ product_data.hpp
+ xml_serializable.hpp
+ xml_serializable.tpp
+Fix defect noted 20120616T1210Z.
+
Modified: lmi/trunk/product_data.cpp
===================================================================
--- lmi/trunk/product_data.cpp 2012-06-18 17:12:30 UTC (rev 5500)
+++ lmi/trunk/product_data.cpp 2012-06-18 18:35:29 UTC (rev 5501)
@@ -300,12 +300,9 @@
(xml::element const& e
) const
{
- glossed_string r;
+ value_type 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();
+ return r;
}
/// This override doesn't call redintegrate_ex_ante(); that wouldn't
Modified: lmi/trunk/product_data.hpp
===================================================================
--- lmi/trunk/product_data.hpp 2012-06-18 17:12:30 UTC (rev 5500)
+++ lmi/trunk/product_data.hpp 2012-06-18 18:35:29 UTC (rev 5501)
@@ -67,6 +67,13 @@
std::string gloss_;
};
+class LMI_SO product_data;
+
+template<> struct deserialized<product_data>
+{
+ typedef glossed_string value_type;
+};
+
/// Product data representable as strings, including filenames.
///
/// This is the "master" product file: it includes the filenames of
@@ -80,8 +87,7 @@
, 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;
+ typedef deserialized<product_data>::value_type value_type;
friend class PolicyDocument;
Modified: lmi/trunk/xml_serializable.hpp
===================================================================
--- lmi/trunk/xml_serializable.hpp 2012-06-18 17:12:30 UTC (rev 5500)
+++ lmi/trunk/xml_serializable.hpp 2012-06-18 18:35:29 UTC (rev 5501)
@@ -35,6 +35,17 @@
#include <map>
#include <string>
+/// Type of a deserialized xml element.
+///
+/// Specialize this if the intended type is not interconvertible with
+/// std::string.
+
+template<typename T>
+struct deserialized
+{
+ typedef std::string value_type;
+};
+
/// Derive from this mixin class to use its xml serialization.
///
/// Implicitly-declared special member functions do the right thing.
@@ -42,8 +53,7 @@
template<typename T>
class LMI_SO xml_serializable
{
- // For the nonce, value_type is guaranteed to be std::string.
- typedef std::string value_type;
+ typedef typename deserialized<T>::value_type value_type;
public:
virtual ~xml_serializable();
Modified: lmi/trunk/xml_serializable.tpp
===================================================================
--- lmi/trunk/xml_serializable.tpp 2012-06-18 17:12:30 UTC (rev 5500)
+++ lmi/trunk/xml_serializable.tpp 2012-06-18 18:35:29 UTC (rev 5501)
@@ -37,6 +37,8 @@
#include <boost/filesystem/convenience.hpp> // basename()
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/utility/enable_if.hpp>
#include <xmlwrapp/nodes_view.h>
@@ -222,6 +224,25 @@
throw "Unreachable--silences a compiler diagnostic.";
}
+template<typename X, typename Y>
+inline Y sfinae_cast
+ (X const& x
+ ,typename boost::enable_if<boost::is_same<X,Y> >::type* = 0
+ )
+{
+ return x;
+}
+
+template<typename X, typename Y>
+inline Y sfinae_cast
+ (X const&
+ ,typename boost::disable_if<boost::is_same<X,Y> >::type* = 0
+ )
+{
+ fatal_error() << "Impermissible type conversion." << LMI_FLUSH;
+ return Y();
+}
+
/// Retrieve an xml element's value.
template<typename T>
@@ -229,8 +250,7 @@
(xml::element const& e
) const
{
- // For the nonce, value_type is guaranteed to be std::string.
- return xml_lmi::get_content(e);
+ return sfinae_cast<std::string,value_type>(xml_lmi::get_content(e));
}
/// Read an xml element.
@@ -242,7 +262,10 @@
/// xml_serialize::from_xml() does nearly the same thing, but in a
/// type-dependent way; thus, it doesn't have the precondition above.
/// However, the datum here has been subject to type erasure and its
-/// type is not readily unerased.
+/// type is not readily unerased. SOMEDAY !! But now that datatype is
+/// available, selectively at least, as value_type...so should
+/// from_xml() be used directly here? Or should this function be kept
+/// for parallelism with write_element()?
///
/// The xml::element argument is the element to be read, which is
/// already available through an iterator in read().
@@ -256,7 +279,7 @@
{
value_type v = fetch_element(e);
redintegrate_ex_ante(file_version, name, v);
- t()[name] = v;
+ t()[name] = sfinae_cast<value_type,std::string>(v);
}
/// Write an xml element.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5501] Fix defect noted 20120616T1210Z,
Greg Chicares <=