Documentation updates and priority_queue now tested for XML

This commit is contained in:
Shane Grant
2013-07-07 18:23:21 -07:00
parent 8fcb6389e8
commit 0912411844
11 changed files with 48 additions and 13 deletions

View File

@@ -76,8 +76,8 @@ namespace cereal
and instead infer it from the number of children for a node. This means that data and instead infer it from the number of children for a node. This means that data
can be hand edited for dynamic sized structures and will still be readable. This can be hand edited for dynamic sized structures and will still be readable. This
is accomplished through the cereal::SizeTag object, which will also add an attribute is accomplished through the cereal::SizeTag object, which will also add an attribute
to its parent field. */ to its parent field.
/*! \ingroup Archives */ \ingroup Archives */
class XMLOutputArchive : public OutputArchive<XMLOutputArchive> class XMLOutputArchive : public OutputArchive<XMLOutputArchive>
{ {
public: public:
@@ -212,9 +212,12 @@ namespace cereal
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "type", namePtr ) ); itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "type", namePtr ) );
} }
void markDynamicSize() //! Appends an attribute to the current top level node
void appendAttribute( const char * name, const char * value )
{ {
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "size", "dynamic" ) ); auto namePtr = itsXML.allocate_string( name );
auto valuePtr = itsXML.allocate_string( value );
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( namePtr, valuePtr ) );
} }
protected: protected:
@@ -259,7 +262,10 @@ namespace cereal
// ###################################################################### // ######################################################################
//! An output archive designed to save data to XML //! An output archive designed to save data to XML
/*! \ingroup Archives */ /*! 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.
\ingroup Archives */
class XMLInputArchive : public InputArchive<XMLInputArchive> class XMLInputArchive : public InputArchive<XMLInputArchive>
{ {
public: public:
@@ -497,7 +503,7 @@ namespace cereal
template <class T> template <class T>
void prologue( XMLOutputArchive & ar, SizeTag<T> const & ) void prologue( XMLOutputArchive & ar, SizeTag<T> const & )
{ {
ar.markDynamicSize(); ar.appendAttribute( "size", "dynamic" );
} }
template <class T> template <class T>

View File

@@ -55,7 +55,7 @@ namespace cereal
ar( binary_data( array.data(), N * sizeof(T) ) ); ar( binary_data( array.data(), N * sizeof(T) ) );
} }
//! Saving for std::array all other types to binary //! Saving for std::array all other types
template <class Archive, class T, size_t N> inline template <class Archive, class T, size_t N> inline
typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>() typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value, void>::type || !std::is_arithmetic<T>::value, void>::type
@@ -65,7 +65,7 @@ namespace cereal
ar( i ); ar( i );
} }
//! Loading for std::array all other types to binary //! Loading for std::array all other types
template <class Archive, class T, size_t N> inline template <class Archive, class T, size_t N> inline
typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>() typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value, void>::type || !std::is_arithmetic<T>::value, void>::type

View File

@@ -37,6 +37,8 @@ namespace cereal
{ {
namespace bitset_detail namespace bitset_detail
{ {
//! The type the bitset is encoded with
/*! @internal */
enum class type : uint8_t enum class type : uint8_t
{ {
ulong, ulong,

View File

@@ -38,6 +38,7 @@ namespace cereal
{ {
namespace binary_detail namespace binary_detail
{ {
//! @internal
template <class Archive> template <class Archive>
struct variant_save_visitor : boost::static_visitor<> struct variant_save_visitor : boost::static_visitor<>
{ {
@@ -52,6 +53,7 @@ namespace cereal
Archive & ar; Archive & ar;
}; };
//! @internal
template<int N, class Variant, class ... Args, class Archive> template<int N, class Variant, class ... Args, class Archive>
typename std::enable_if<N == boost::mpl::size<typename Variant::types>::value, void>::type typename std::enable_if<N == boost::mpl::size<typename Variant::types>::value, void>::type
load_variant(Archive & ar, int target, Variant & variant) load_variant(Archive & ar, int target, Variant & variant)
@@ -59,6 +61,7 @@ namespace cereal
throw ::cereal::Exception("Error traversing variant during load"); throw ::cereal::Exception("Error traversing variant during load");
} }
//! @internal
template<int N, class Variant, class H, class ... T, class Archive> template<int N, class Variant, class H, class ... T, class Archive>
typename std::enable_if<N < boost::mpl::size<typename Variant::types>::value, void>::type typename std::enable_if<N < boost::mpl::size<typename Variant::types>::value, void>::type
load_variant(Archive & ar, int target, Variant & variant) load_variant(Archive & ar, int target, Variant & variant)

View File

@@ -111,6 +111,7 @@ namespace cereal
// Pointer wrapper implementations follow below // Pointer wrapper implementations follow below
//! Saving std::shared_ptr (wrapper implementation) //! Saving std::shared_ptr (wrapper implementation)
/*! @internal */
template <class Archive, class T> inline template <class Archive, class T> inline
void save( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> const &> const & wrapper ) void save( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> const &> const & wrapper )
{ {
@@ -126,6 +127,7 @@ namespace cereal
} }
//! Loading std::shared_ptr, case when user load and allocate (wrapper implementation) //! Loading std::shared_ptr, case when user load and allocate (wrapper implementation)
/*! @internal */
template <class Archive, class T> inline template <class Archive, class T> inline
typename std::enable_if<traits::has_load_and_allocate<T, Archive>(), void>::type typename std::enable_if<traits::has_load_and_allocate<T, Archive>(), void>::type
load( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper ) load( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper )
@@ -148,6 +150,7 @@ namespace cereal
} }
//! Loading std::shared_ptr, case when no user load and allocate (wrapper implementation) //! Loading std::shared_ptr, case when no user load and allocate (wrapper implementation)
/*! @internal */
template <class Archive, class T> inline template <class Archive, class T> inline
typename std::enable_if<!traits::has_load_and_allocate<T, Archive>(), void>::type typename std::enable_if<!traits::has_load_and_allocate<T, Archive>(), void>::type
load( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper ) load( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper )
@@ -171,6 +174,7 @@ namespace cereal
} }
//! Saving std::unique_ptr (wrapper implementation) //! Saving std::unique_ptr (wrapper implementation)
/*! @internal */
template <class Archive, class T, class D> inline template <class Archive, class T, class D> inline
void save( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> const &> const & wrapper ) void save( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> const &> const & wrapper )
{ {
@@ -190,6 +194,7 @@ namespace cereal
} }
//! Loading std::unique_ptr, case when user provides load_and_allocate (wrapper implementation) //! Loading std::unique_ptr, case when user provides load_and_allocate (wrapper implementation)
/*! @internal */
template <class Archive, class T, class D> inline template <class Archive, class T, class D> inline
typename std::enable_if<traits::has_load_and_allocate<T, Archive>(), void>::type typename std::enable_if<traits::has_load_and_allocate<T, Archive>(), void>::type
load( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper ) load( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper )
@@ -206,6 +211,7 @@ namespace cereal
} }
//! Loading std::unique_ptr, case when no load_and_allocate (wrapper implementation) //! Loading std::unique_ptr, case when no load_and_allocate (wrapper implementation)
/*! @internal */
template <class Archive, class T, class D> inline template <class Archive, class T, class D> inline
typename std::enable_if<!traits::has_load_and_allocate<T, Archive>(), void>::type typename std::enable_if<!traits::has_load_and_allocate<T, Archive>(), void>::type
load( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper ) load( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper )

View File

@@ -38,6 +38,7 @@ namespace cereal
namespace queue_detail namespace queue_detail
{ {
//! Allows access to the protected container in queue //! Allows access to the protected container in queue
/*! @internal */
template <class T, class C> inline template <class T, class C> inline
C const & container( std::queue<T, C> const & queue ) C const & container( std::queue<T, C> const & queue )
{ {
@@ -53,6 +54,7 @@ namespace cereal
} }
//! Allows access to the protected container in priority queue //! Allows access to the protected container in priority queue
/*! @internal */
template <class T, class C, class Comp> inline template <class T, class C, class Comp> inline
C const & container( std::priority_queue<T, C, Comp> const & priority_queue ) C const & container( std::priority_queue<T, C, Comp> const & priority_queue )
{ {
@@ -68,6 +70,7 @@ namespace cereal
} }
//! Allows access to the protected comparator in priority queue //! Allows access to the protected comparator in priority queue
/*! @internal */
template <class T, class C, class Comp> inline template <class T, class C, class Comp> inline
Comp const & comparator( std::priority_queue<T, C, Comp> const & priority_queue ) Comp const & comparator( std::priority_queue<T, C, Comp> const & priority_queue )
{ {

View File

@@ -37,6 +37,7 @@ namespace cereal
{ {
namespace set_detail namespace set_detail
{ {
//! @internal
template <class Archive, class SetT> inline template <class Archive, class SetT> inline
void save( Archive & ar, SetT const & set ) void save( Archive & ar, SetT const & set )
{ {
@@ -46,6 +47,7 @@ namespace cereal
ar( i ); ar( i );
} }
//! @internal
template <class Archive, class SetT> inline template <class Archive, class SetT> inline
void load( Archive & ar, SetT & set ) void load( Archive & ar, SetT & set )
{ {

View File

@@ -38,6 +38,7 @@ namespace cereal
namespace tuple_detail namespace tuple_detail
{ {
// unwinds a tuple to save it // unwinds a tuple to save it
//! @internal
template <size_t Height> template <size_t Height>
struct serialize struct serialize
{ {
@@ -50,6 +51,7 @@ namespace cereal
}; };
// Zero height specialization - nothing to do here // Zero height specialization - nothing to do here
//! @internal
template <> template <>
struct serialize<0> struct serialize<0>
{ {

View File

@@ -37,6 +37,7 @@ namespace cereal
{ {
namespace unordered_map_detail namespace unordered_map_detail
{ {
//! @internal
template <class Archive, class MapT> inline template <class Archive, class MapT> inline
void save( Archive & ar, MapT const & map ) void save( Archive & ar, MapT const & map )
{ {
@@ -46,6 +47,7 @@ namespace cereal
ar( make_map_item(i.first, i.second) ); ar( make_map_item(i.first, i.second) );
} }
//! @internal
template <class Archive, class MapT> inline template <class Archive, class MapT> inline
void load( Archive & ar, MapT & map ) void load( Archive & ar, MapT & map )
{ {

View File

@@ -37,6 +37,7 @@ namespace cereal
{ {
namespace unordered_set_detail namespace unordered_set_detail
{ {
//! @internal
template <class Archive, class SetT> inline template <class Archive, class SetT> inline
void save( Archive & ar, SetT const & set ) void save( Archive & ar, SetT const & set )
{ {
@@ -46,6 +47,7 @@ namespace cereal
ar( i ); ar( i );
} }
//! @internal
template <class Archive, class SetT> inline template <class Archive, class SetT> inline
void load( Archive & ar, SetT & set ) void load( Archive & ar, SetT & set )
{ {

View File

@@ -59,6 +59,14 @@ namespace boost
} }
} }
namespace cereal
{
template <class Archive, class T>
void serialize( Archive &, std::less<T> & )
{ }
}
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Cereal #define BOOST_TEST_MODULE Cereal
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
@@ -1072,11 +1080,10 @@ BOOST_AUTO_TEST_CASE( binary_priority_queue )
test_priority_queue<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>(); test_priority_queue<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
} }
// TODO: xml doesn't do empty classes by default, need std::less BOOST_AUTO_TEST_CASE( xml_priority_queue )
//BOOST_AUTO_TEST_CASE( xml_priority_queue ) {
//{ test_priority_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
// test_priority_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>(); }
//}
// ###################################################################### // ######################################################################
template <class IArchive, class OArchive> template <class IArchive, class OArchive>