mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
using BOOST_CHECK_CLOSE for long double comparisons
some documentation updates to both xml and util
This commit is contained in:
@@ -28,8 +28,6 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef CEREAL_ARCHIVES_XML_HPP_
|
#ifndef CEREAL_ARCHIVES_XML_HPP_
|
||||||
#define CEREAL_ARCHIVES_XML_HPP_
|
#define CEREAL_ARCHIVES_XML_HPP_
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <cereal/cereal.hpp>
|
#include <cereal/cereal.hpp>
|
||||||
#include <cereal/details/util.hpp>
|
#include <cereal/details/util.hpp>
|
||||||
|
|
||||||
@@ -253,7 +251,7 @@ namespace cereal
|
|||||||
}; // NodeInfo
|
}; // NodeInfo
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream & itsStream;
|
std::ostream & itsStream; //!< The output stream
|
||||||
rapidxml::xml_document<> itsXML; //!< The XML document
|
rapidxml::xml_document<> itsXML; //!< The XML document
|
||||||
std::stack<NodeInfo> itsNodes; //!< A stack of nodes added to the document
|
std::stack<NodeInfo> itsNodes; //!< A stack of nodes added to the document
|
||||||
std::ostringstream itsOS; //!< Used to format strings internally
|
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
|
/*! 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.
|
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 */
|
\ingroup Archives */
|
||||||
class XMLInputArchive : public InputArchive<XMLInputArchive>
|
class XMLInputArchive : public InputArchive<XMLInputArchive>
|
||||||
{
|
{
|
||||||
@@ -285,19 +287,22 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
catch( rapidxml::parse_error const & e )
|
catch( rapidxml::parse_error const & e )
|
||||||
{
|
{
|
||||||
std::cout << "-----Original-----" << std::endl;
|
//std::cerr << "-----Original-----" << std::endl;
|
||||||
stream.seekg(0);
|
//stream.seekg(0);
|
||||||
std::cout << std::string( std::istreambuf_iterator<char>( stream ), std::istreambuf_iterator<char>() ) << std::endl;
|
//std::cout << std::string( std::istreambuf_iterator<char>( stream ), std::istreambuf_iterator<char>() ) << std::endl;
|
||||||
|
|
||||||
std::cout << "-----Error-----" << std::endl;
|
//std::cerr << "-----Error-----" << std::endl;
|
||||||
std::cout << e.what() << std::endl;
|
//std::cerr << e.what() << std::endl;
|
||||||
std::cout << e.where<char>() << std::endl;
|
//std::cerr << e.where<char>() << std::endl;
|
||||||
throw Exception("XML Parsing failed - likely due to invalid characters or invalid naming");
|
throw Exception("XML Parsing failed - likely due to invalid characters or invalid naming");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the root
|
// Parse the root
|
||||||
auto root = itsXML.first_node( xml_detail::CEREAL_XML_STRING );
|
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
|
//! Prepares to start reading the next node
|
||||||
@@ -424,10 +429,6 @@ namespace cereal
|
|||||||
static size_t getNumChildren( rapidxml::xml_node<> * node )
|
static size_t getNumChildren( rapidxml::xml_node<> * node )
|
||||||
{
|
{
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if( node == nullptr )
|
|
||||||
{
|
|
||||||
std::cerr << "NUM CHILDREN CALLED ON NULL NODE" << std::endl;
|
|
||||||
}
|
|
||||||
node = node->first_node(); // get first child
|
node = node->first_node(); // get first child
|
||||||
|
|
||||||
while( node != nullptr )
|
while( node != nullptr )
|
||||||
@@ -441,6 +442,8 @@ namespace cereal
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! A struct that contains metadata about a node
|
//! 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
|
struct NodeInfo
|
||||||
{
|
{
|
||||||
NodeInfo( rapidxml::xml_node<> * n = nullptr ) :
|
NodeInfo( rapidxml::xml_node<> * n = nullptr ) :
|
||||||
@@ -464,7 +467,7 @@ namespace cereal
|
|||||||
}; // NodeInfo
|
}; // NodeInfo
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char> itsData; //!< The raw data loaded
|
std::vector<char> itsData; //!< The raw data loaded
|
||||||
rapidxml::xml_document<> itsXML; //!< The XML document
|
rapidxml::xml_document<> itsXML; //!< The XML document
|
||||||
std::stack<NodeInfo> itsNodes; //!< A stack of nodes read from the document
|
std::stack<NodeInfo> itsNodes; //!< A stack of nodes read from the document
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ namespace cereal
|
|||||||
{
|
{
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
//! Demangles the type encoded in a string
|
||||||
|
/*! @internal */
|
||||||
inline std::string demangle(std::string mangledName)
|
inline std::string demangle(std::string mangledName)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@@ -49,6 +51,8 @@ namespace cereal
|
|||||||
return retName;
|
return retName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Gets the demangled name of a type
|
||||||
|
/*! @internal */
|
||||||
template<class T> inline
|
template<class T> inline
|
||||||
std::string demangledName()
|
std::string demangledName()
|
||||||
{ return demangle(typeid(T).name()); }
|
{ return demangle(typeid(T).name()); }
|
||||||
|
|||||||
@@ -2133,7 +2133,8 @@ void test_complex()
|
|||||||
|
|
||||||
BOOST_CHECK_EQUAL( o_float, i_float );
|
BOOST_CHECK_EQUAL( o_float, i_float );
|
||||||
BOOST_CHECK_EQUAL( o_double, i_double );
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user