From cded3bea43f251326351cbbf098445c22ff79351 Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Mon, 8 Jul 2013 10:13:42 -0700 Subject: [PATCH] using BOOST_CHECK_CLOSE for long double comparisons some documentation updates to both xml and util --- include/cereal/archives/xml.hpp | 33 ++++++++++++++++++--------------- include/cereal/details/util.hpp | 4 ++++ unittests.cpp | 3 ++- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/cereal/archives/xml.hpp b/include/cereal/archives/xml.hpp index a227f7b3..96f9f963 100644 --- a/include/cereal/archives/xml.hpp +++ b/include/cereal/archives/xml.hpp @@ -28,8 +28,6 @@ */ #ifndef CEREAL_ARCHIVES_XML_HPP_ #define CEREAL_ARCHIVES_XML_HPP_ -#include - #include #include @@ -253,7 +251,7 @@ namespace cereal }; // NodeInfo private: - std::ostream & itsStream; + std::ostream & itsStream; //!< The output stream rapidxml::xml_document<> itsXML; //!< The XML document std::stack itsNodes; //!< A stack of nodes added to the document std::ostringstream itsOS; //!< Used to format strings internally @@ -265,6 +263,10 @@ namespace cereal /*! This archive uses RapidXML to build an in memory XML tree of the data in the stream it is given before loading any types serialized. + Input XML should have been produced by the XMLOutputArchive. Data can + only be added to dynamically sized containers - the input archive will + determine their size by looking at the number of child nodes. + \ingroup Archives */ class XMLInputArchive : public InputArchive { @@ -285,19 +287,22 @@ namespace cereal } catch( rapidxml::parse_error const & e ) { - std::cout << "-----Original-----" << std::endl; - stream.seekg(0); - std::cout << std::string( std::istreambuf_iterator( stream ), std::istreambuf_iterator() ) << std::endl; + //std::cerr << "-----Original-----" << std::endl; + //stream.seekg(0); + //std::cout << std::string( std::istreambuf_iterator( stream ), std::istreambuf_iterator() ) << std::endl; - std::cout << "-----Error-----" << std::endl; - std::cout << e.what() << std::endl; - std::cout << e.where() << std::endl; + //std::cerr << "-----Error-----" << std::endl; + //std::cerr << e.what() << std::endl; + //std::cerr << e.where() << std::endl; throw Exception("XML Parsing failed - likely due to invalid characters or invalid naming"); } // Parse the root auto root = itsXML.first_node( xml_detail::CEREAL_XML_STRING ); - itsNodes.emplace( root ); + if( root == nullptr ) + throw Exception("Could not detect cereal root node - likely due to empty or invalid input"); + else + itsNodes.emplace( root ); } //! Prepares to start reading the next node @@ -424,10 +429,6 @@ namespace cereal static size_t getNumChildren( rapidxml::xml_node<> * node ) { size_t size = 0; - if( node == nullptr ) - { - std::cerr << "NUM CHILDREN CALLED ON NULL NODE" << std::endl; - } node = node->first_node(); // get first child while( node != nullptr ) @@ -441,6 +442,8 @@ namespace cereal protected: //! A struct that contains metadata about a node + /*! Keeps track of some top level node, its number of + remaining children, and the current active child node */ struct NodeInfo { NodeInfo( rapidxml::xml_node<> * n = nullptr ) : @@ -464,7 +467,7 @@ namespace cereal }; // NodeInfo private: - std::vector itsData; //!< The raw data loaded + std::vector itsData; //!< The raw data loaded rapidxml::xml_document<> itsXML; //!< The XML document std::stack itsNodes; //!< A stack of nodes read from the document }; diff --git a/include/cereal/details/util.hpp b/include/cereal/details/util.hpp index c7f18ba6..4f7ef05b 100644 --- a/include/cereal/details/util.hpp +++ b/include/cereal/details/util.hpp @@ -35,6 +35,8 @@ namespace cereal { namespace util { + //! Demangles the type encoded in a string + /*! @internal */ inline std::string demangle(std::string mangledName) { int status = 0; @@ -49,6 +51,8 @@ namespace cereal return retName; } + //! Gets the demangled name of a type + /*! @internal */ template inline std::string demangledName() { return demangle(typeid(T).name()); } diff --git a/unittests.cpp b/unittests.cpp index 88881b53..4500fcfc 100644 --- a/unittests.cpp +++ b/unittests.cpp @@ -2133,7 +2133,8 @@ void test_complex() BOOST_CHECK_EQUAL( o_float, i_float ); BOOST_CHECK_EQUAL( o_double, i_double ); - BOOST_CHECK_EQUAL( o_ldouble, i_ldouble ); + BOOST_CHECK_CLOSE( o_ldouble.real(), i_ldouble.real(), 1e-5); + BOOST_CHECK_CLOSE( o_ldouble.imag(), i_ldouble.imag(), 1e-5); } }