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
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
to its parent field. */
/*! \ingroup Archives */
to its parent field.
\ingroup Archives */
class XMLOutputArchive : public OutputArchive<XMLOutputArchive>
{
public:
@@ -212,9 +212,12 @@ namespace cereal
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:
@@ -259,7 +262,10 @@ namespace cereal
// ######################################################################
//! 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>
{
public:
@@ -497,7 +503,7 @@ namespace cereal
template <class T>
void prologue( XMLOutputArchive & ar, SizeTag<T> const & )
{
ar.markDynamicSize();
ar.appendAttribute( "size", "dynamic" );
}
template <class T>

View File

@@ -55,7 +55,7 @@ namespace cereal
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
typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value, void>::type
@@ -65,7 +65,7 @@ namespace cereal
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
typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value, void>::type

View File

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

View File

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

View File

@@ -111,6 +111,7 @@ namespace cereal
// Pointer wrapper implementations follow below
//! Saving std::shared_ptr (wrapper implementation)
/*! @internal */
template <class Archive, class T> inline
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)
/*! @internal */
template <class Archive, class T> inline
typename std::enable_if<traits::has_load_and_allocate<T, Archive>(), void>::type
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)
/*! @internal */
template <class Archive, class T> inline
typename std::enable_if<!traits::has_load_and_allocate<T, Archive>(), void>::type
load( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper )
@@ -171,6 +174,7 @@ namespace cereal
}
//! Saving std::unique_ptr (wrapper implementation)
/*! @internal */
template <class Archive, class T, class D> inline
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)
/*! @internal */
template <class Archive, class T, class D> inline
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 )
@@ -206,6 +211,7 @@ namespace cereal
}
//! Loading std::unique_ptr, case when no load_and_allocate (wrapper implementation)
/*! @internal */
template <class Archive, class T, class D> inline
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 )

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,6 +37,7 @@ namespace cereal
{
namespace unordered_set_detail
{
//! @internal
template <class Archive, class SetT> inline
void save( Archive & ar, SetT const & set )
{
@@ -46,6 +47,7 @@ namespace cereal
ar( i );
}
//! @internal
template <class Archive, class SetT> inline
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_MODULE Cereal
#include <boost/test/unit_test.hpp>
@@ -1072,11 +1080,10 @@ BOOST_AUTO_TEST_CASE( binary_priority_queue )
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 )
//{
// test_priority_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
//}
BOOST_AUTO_TEST_CASE( xml_priority_queue )
{
test_priority_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
}
// ######################################################################
template <class IArchive, class OArchive>