diff --git a/include/cereal/archives/binary.hpp b/include/cereal/archives/binary.hpp index cc739f7d..f9a67d1a 100644 --- a/include/cereal/archives/binary.hpp +++ b/include/cereal/archives/binary.hpp @@ -105,7 +105,7 @@ namespace cereal //! Serializing NVP types to binary template inline - CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive) + CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) serialize( Archive & ar, NameValuePair & t ) { ar( t.value ); @@ -113,7 +113,7 @@ namespace cereal //! Serializing SizeTags to binary template inline - CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive) + CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) serialize( Archive & ar, SizeTag & t ) { ar( t.size ); diff --git a/include/cereal/archives/xml.hpp b/include/cereal/archives/xml.hpp index 862d8fd0..a5299fa9 100644 --- a/include/cereal/archives/xml.hpp +++ b/include/cereal/archives/xml.hpp @@ -43,6 +43,11 @@ namespace cereal { + namespace xml_detail + { + static const char * CEREAL_XML_STRING = "cereal"; + } + // ###################################################################### //! An output archive designed to save data to XML class XMLOutputArchive : public OutputArchive @@ -65,7 +70,7 @@ namespace cereal itsXML.append_node( node ); // allocate root node - auto root = itsXML.allocate_node( rapidxml::node_element, "cereal" ); + auto root = itsXML.allocate_node( rapidxml::node_element, xml_detail::CEREAL_XML_STRING ); itsXML.append_node( root ); itsNodes.emplace( root ); @@ -165,6 +170,7 @@ namespace cereal finishNode(); }; + protected: //! A struct that contains metadata about a node struct NodeInfo { @@ -216,7 +222,6 @@ namespace cereal @param stream The stream to read from. Can be a stringstream or a file. */ XMLInputArchive( std::istream & stream ) : InputArchive( this ), - itsStream( stream ), itsData( std::istreambuf_iterator( stream ), std::istreambuf_iterator() ) { try @@ -229,12 +234,29 @@ namespace cereal //std::cout << e.what() << std::endl; //std::cout << e.where() << std::endl; } + + // Parse the root + auto root = itsXML.first_node( xml_detail::CEREAL_XML_STRING ); + itsNodes.emplace( root ); } - //private: - std::istream & itsStream; + protected: + //! A struct that contains metadata about a node + struct NodeInfo + { + NodeInfo( rapidxml::xml_node<> * n = nullptr ) : + node( n ), + counter( 0 ) + { } + + rapidxml::xml_node<> * node; //!< A pointer to this node + size_t counter; //!< The counter for naming child nodes + }; // NodeInfo + + private: 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 }; // ###################################################################### @@ -287,7 +309,7 @@ namespace cereal //! Serializing NVP types to XML template inline - CEREAL_ARCHIVE_RESTRICT_SERIALIZE(XMLInputArchive, XMLOutputArchive) + CEREAL_ARCHIVE_RESTRICT(XMLInputArchive, XMLOutputArchive) serialize( Archive & ar, NameValuePair & t ) { ar.setNextName( t.name ); @@ -296,7 +318,7 @@ namespace cereal //! Serializing SizeTags to XML template inline - CEREAL_ARCHIVE_RESTRICT_SERIALIZE(XMLInputArchive, XMLOutputArchive) + CEREAL_ARCHIVE_RESTRICT(XMLInputArchive, XMLOutputArchive) serialize( Archive & ar, SizeTag & ) { } diff --git a/include/cereal/details/traits.hpp b/include/cereal/details/traits.hpp index 7ebe2769..98c1e392 100644 --- a/include/cereal/details/traits.hpp +++ b/include/cereal/details/traits.hpp @@ -260,14 +260,14 @@ namespace cereal @code{.cpp} template - CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive) + CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) serialize( Archive & ar, MyCoolType & m ) { ar & m; } @endcode */ - #define CEREAL_ARCHIVE_RESTRICT_SERIALIZE(INTYPE, OUTTYPE) \ + #define CEREAL_ARCHIVE_RESTRICT(INTYPE, OUTTYPE) \ typename std::enable_if::value || std::is_same::value, void>::type } // namespace traits diff --git a/sandbox.cpp b/sandbox.cpp index 6bcbbe70..2ab7bce8 100644 --- a/sandbox.cpp +++ b/sandbox.cpp @@ -333,8 +333,10 @@ int main() { std::ifstream is("out.xml"); - cereal::XMLInputArchive oar( is ); - std::cout << oar.itsData.size() << std::endl; + cereal::XMLInputArchive iar( is ); + + //int z; + //iar( cereal::make_nvp("hello", z) ); }