Moving things into new directories to match generic style now made possible

This commit is contained in:
Shane Grant 2013-06-20 11:12:00 -07:00
parent 27ef76de78
commit bc790ea5ff
22 changed files with 429 additions and 413 deletions

View File

@ -24,8 +24,8 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_BINARY_ARCHIVE_HPP_
#define CEREAL_BINARY_ARCHIVE_BINARY_ARCHIVE_HPP_
#ifndef CEREAL_ARCHIVES_BINARY_HPP_
#define CEREAL_ARCHIVES_BINARY_HPP_
#include <cereal/cereal.hpp>
#include <stack>
@ -128,7 +128,7 @@ namespace cereal
//! Serialization for enum types to binary
template<class Archive, class T> inline
typename std::enable_if<std::is_enum<T>::value &&
typename std::enable_if<std::is_enum<T>::value &&
(std::is_same<Archive, BinaryInputArchive>::value || std::is_same<Archive, BinaryOutputArchive>::value),
void>::type
serialize(Archive & ar, T & t)
@ -179,4 +179,4 @@ namespace cereal
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_BINARY_ARCHIVE_HPP_
#endif // CEREAL_ARCHIVES_BINARY_HPP_

View File

@ -1,100 +0,0 @@
/*
Copyright (c) 2013, Randolph Voorhies, Shane Grant
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_UNORDERED_MAP_HPP_
#define CEREAL_BINARY_ARCHIVE_UNORDERED_MAP_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <unordered_map>
namespace cereal
{
//! Saving for std::unordered_map to binary
template <class K, class T, class H, class KE, class A> inline
void save( BinaryOutputArchive & ar, std::unordered_map<K, T, H, KE, A> const & unordered_map )
{
ar( unordered_map.size() );
for( const auto & i : unordered_map )
{
ar( i.first,
i.second );
}
}
//! Loading for std::unordered_map to binary
template <class K, class T, class H, class KE, class A> inline
void load( BinaryInputArchive & ar, std::unordered_map<K, T, H, KE, A> & unordered_map )
{
size_t size;
ar( size );
unordered_map.reserve( size );
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar( key, value );
unordered_map.insert( {key, value} );
}
}
//! Saving for std::unordered_multimap to binary
template <class K, class T, class H, class KE, class A> inline
void save( BinaryOutputArchive & ar, std::unordered_multimap<K, T, H, KE, A> const & unordered_multimap )
{
ar( unordered_multimap.size() );
for( const auto & i : unordered_multimap )
{
ar( i.first,
i.second );
}
}
//! Loading for std::unordered_multimap to binary
template <class K, class T, class H, class KE, class A> inline
void load( BinaryInputArchive & ar, std::unordered_multimap<K, T, H, KE, A> & unordered_multimap )
{
size_t size;
ar( size );
unordered_multimap.reserve( size );
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar( key, value );
unordered_multimap.insert( {key, value} );
}
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_UNORDERED_MAP_HPP_

View File

@ -131,6 +131,19 @@ namespace cereal
Base * base_ptr;
};
// ######################################################################
//! Called before a type is serialized to set up any special archive state
//! for processing some type
template <class Archive, class T>
void prologue( Archive & ar, T const & data )
{ }
//! Called before a type is serialized to tear down any special archive state
//! for processing some type
template <class Archive, class T>
void epilogue( Archive & ar, T const & data )
{ }
// ######################################################################
//! Special flags for archives
enum Flags { AllowEmptyClassElision = 1 };
@ -173,13 +186,15 @@ namespace cereal
template <class T> inline
void process( T && head )
{
prologue( *self, head );
(*self) & head;
epilogue( *self, head );
}
template <class T, class ... Other> inline
void process( T && head, Other && ... tail )
{
(*self) & head;
process( std::forward<T>( head ) );
process( std::forward<Other>( tail )... );
}
@ -326,13 +341,15 @@ namespace cereal
template <class T> inline
void process( T && head )
{
prologue( *self, head );
(*self) & head;
epilogue( *self, head );
}
template <class T, class ... Other> inline
void process( T && head, Other && ... tail )
{
(*self) & head;
process( std::forward<T>( head ) );
process( std::forward<Other>( tail )... );
}

View File

@ -24,30 +24,32 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_ARRAY_HPP_
#define CEREAL_BINARY_ARCHIVE_ARRAY_HPP_
#ifndef CEREAL_TYPES_ARRAY_HPP_
#define CEREAL_TYPES_ARRAY_HPP_
#include <cereal/cereal.hpp>
#include <array>
namespace cereal
{
//! Saving for std::array primitive types to binary
//! Saving for std::array primitive types
//! using binary serialization, if supported
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
save( Archive & ar, std::array<T, N> const & array )
{
ar( make_nvp( "data", binary_data( array.data(), N * sizeof(T) ) ) );
ar( binary_data( array.data(), N * sizeof(T) ) );
}
//! Loading for std::array primitive types to binary
//! Loading for std::array primitive types
//! using binary serialization, if supported
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
load( Archive & ar, std::array<T, N> & array )
{
ar( make_nvp( "data", binary_data( array.data(), N * sizeof(T) ) ) );
ar( binary_data( array.data(), N * sizeof(T) ) );
}
//! Saving for std::array all other types to binary
@ -57,7 +59,7 @@ namespace cereal
save( Archive & ar, std::array<T, N> const & array )
{
for( auto const & i : array )
ar( make_nvp( "item", i ) );
ar( i );
}
//! Loading for std::array all other types to binary
@ -67,8 +69,8 @@ namespace cereal
load( Archive & ar, std::array<T, N> & array )
{
for( auto & i : array )
ar( make_nvp( "item", i ) );
ar( i );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_ARRAY_HPP_
#endif // CEREAL_TYPES_ARRAY_HPP_

View File

@ -24,8 +24,8 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_BITSET_HPP_
#define CEREAL_BINARY_ARCHIVE_BITSET_HPP_
#ifndef CEREAL_TYPES_BITSET_HPP_
#define CEREAL_TYPES_BITSET_HPP_
#include <cereal/cereal.hpp>
#include <bitset>
@ -42,59 +42,59 @@ namespace cereal
};
}
//! Serializing (save) for std::bitset to binary
//! Serializing (save) for std::bitset
template <class Archive, size_t N> inline
void save( Archive & ar, std::bitset<N> const & bits )
{
try
{
auto const b = bits.to_ulong();
ar( make_nvp( "type", bitset_detail::type::ulong ) );
ar( make_nvp( "data", b ) );
ar( bitset_detail::type::ulong );
ar( b );
}
catch( std::overflow_error const & e )
{
try
{
auto const b = bits.to_ullong();
ar( make_nvp( "type", bitset_detail::type::ullong ) );
ar( make_nvp( "data", b ) );
ar( bitset_detail::type::ullong );
ar( b );
}
catch( std::overflow_error const & e )
{
ar( make_nvp( "type", bitset_detail::type::string ) );
ar( make_nvp( "data", bits.to_string() ) );
ar( bitset_detail::type::string );
ar( bits.to_string() );
}
}
}
//! Serializing (load) for std::bitset to binary
//! Serializing (load) for std::bitset
template <class Archive, size_t N> inline
void load( Archive & ar, std::bitset<N> & bits )
{
bitset_detail::type t;
ar( make_nvp( "type", t ) );
ar( t );
switch( t )
{
case bitset_detail::type::ulong:
{
unsigned long b;
ar( make_nvp( "data", b ) );
ar( b );
bits = std::bitset<N>( b );
break;
}
case bitset_detail::type::ullong:
{
unsigned long long b;
ar( make_nvp( "data", b ) );
ar( b );
bits = std::bitset<N>( b );
break;
}
case bitset_detail::type::string:
{
std::string b;
ar( make_nvp( "data", b ) );
ar( b );
bits = std::bitset<N>( b );
break;
}
@ -104,4 +104,4 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_BITSET_HPP_
#endif // CEREAL_TYPES_BITSET_HPP_

View File

@ -24,8 +24,8 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_BOOST_VARIANT_HPP_
#define CEREAL_BINARY_ARCHIVE_BOOST_VARIANT_HPP_
#ifndef CEREAL_TYPES_BOOST_VARIANT_HPP_
#define CEREAL_TYPES_BOOST_VARIANT_HPP_
#include <cereal/cereal.hpp>
#include <boost/variant.hpp>
@ -43,7 +43,7 @@ namespace cereal
template<class T>
void operator()(T const & value) const
{
ar( CEREAL_NVP(value) );
ar( value );
}
Archive & ar;
@ -63,7 +63,7 @@ namespace cereal
if(N == target)
{
H value;
ar( CEREAL_NVP(value) );
ar( value );
variant = value;
}
else
@ -72,24 +72,24 @@ namespace cereal
} // namespace binary_detail
//! Saving for boost::variant to binary
//! Saving for boost::variant
template <class Archive, typename... VariantTypes> inline
void save( Archive & ar, boost::variant<VariantTypes...> const & variant )
{
int32_t which = variant.which();
ar( CEREAL_NVP(which) );
ar( which );
binary_detail::variant_save_visitor<Archive> visitor(ar);
variant.apply_visitor(visitor);
}
//! Loading for boost::variant from binary
//! Loading for boost::variant
template <class Archive, typename... VariantTypes> inline
void load( Archive & ar, boost::variant<VariantTypes...> & variant )
{
typedef typename boost::variant<VariantTypes...>::types types;
int32_t which;
ar( CEREAL_NVP(which) );
ar( which );
if(which >= boost::mpl::size<types>::value)
throw Exception("Invalid 'which' selector when deserializing boost::variant");
@ -97,4 +97,4 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_BOOST_VARIANT_HPP_
#endif // CEREAL_TYPES_BOOST_VARIANT_HPP_

View File

@ -24,48 +24,48 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_CHRONO_HPP_
#define CEREAL_BINARY_ARCHIVE_CHRONO_HPP_
#ifndef CEREAL_TYPES_CHRONO_HPP_
#define CEREAL_TYPES_CHRONO_HPP_
#include <cereal/cereal.hpp>
#include <chrono>
namespace cereal
{
//! Saving duration
//! Saving std::chrono::duration
template <class Archive, class R, class P> inline
void save( Archive & ar, std::chrono::duration<R, P> const & dur )
{
ar( make_nvp("count", dur.count()) );
ar( dur.count() );
}
//! Loading duration
//! Loading std::chrono::duration
template <class Archive, class R, class P> inline
void load( Archive & ar, std::chrono::duration<R, P> & dur )
{
R count;
ar( CEREAL_NVP(count) );
ar( count );
dur = std::chrono::duration<R, P>{count};
}
//! Saving duration
//! Saving std::chrono::time_point
template <class Archive, class C, class D> inline
void save( Archive & ar, std::chrono::time_point<C, D> const & dur )
{
ar( make_nvp("elapsed", dur.time_since_epoch()) );
ar( dur.time_since_epoch() );
}
//! Loading duration
//! Loading std::chrono::time_point
template <class Archive, class C, class D> inline
void load( Archive & ar, std::chrono::time_point<C, D> & dur )
{
D elapsed;
ar( CEREAL_NVP(elapsed) );
ar( elapsed );
dur = std::chrono::time_point<C, D>{elapsed};
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_CHRONO_HPP_
#endif // CEREAL_TYPES_CHRONO_HPP_

View File

@ -24,30 +24,30 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_COMPLEX_HPP_
#define CEREAL_BINARY_ARCHIVE_COMPLEX_HPP_
#ifndef CEREAL_TYPES_COMPLEX_HPP_
#define CEREAL_TYPES_COMPLEX_HPP_
#include <cereal/cereal.hpp>
#include <complex>
namespace cereal
{
//! Serializing (save) for std::complex to binary
//! Serializing (save) for std::complex
template <class Archive, class T> inline
void save( Archive & ar, std::complex<T> const & comp )
{
ar( make_nvp("real", comp.real()),
make_nvp("imag", comp.imag()) );
ar( comp.real(),
comp.imag() );
}
//! Serializing (load) for std::complex to binary
//! Serializing (load) for std::complex
template <class Archive, class T> inline
void load( Archive & ar, std::complex<T> & bits )
{
T real, imag;
ar( CEREAL_NVP(real), CEREAL_NVP(imag) );
ar( real, imag );
bits = {real, imag};
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_COMPLEX_HPP_
#endif // CEREAL_TYPES_COMPLEX_HPP_

View File

@ -24,36 +24,36 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_DEQUE_HPP_
#define CEREAL_BINARY_ARCHIVE_DEQUE_HPP_
#ifndef CEREAL_TYPES_DEQUE_HPP_
#define CEREAL_TYPES_DEQUE_HPP_
#include <cereal/cereal.hpp>
#include <deque>
namespace cereal
{
//! Saving for std::deque to binary
//! Saving for std::deque
template <class Archive, class T, class A> inline
void save( Archive & ar, std::deque<T, A> const & deque )
{
ar( make_nvp("size", deque.size()) );
ar( deque.size() );
for( auto const & i : deque )
ar( make_nvp("item", i) );
ar( i );
}
//! Loading for std::deque to binary
//! Loading for std::deque
template <class Archive, class T, class A> inline
void load( Archive & ar, std::deque<T, A> & deque )
{
size_t size;
ar( CEREAL_NVP(size) );
ar( size );
deque.resize( size );
for( auto & i : deque )
ar( make_nvp("item", i) );
ar( i );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_DEQUE_HPP_
#endif // CEREAL_TYPES_DEQUE_HPP_

View File

@ -24,15 +24,15 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_
#define CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_
#ifndef CEREAL_TYPES_FORWARD_LIST_HPP_
#define CEREAL_TYPES_FORWARD_LIST_HPP_
#include <cereal/cereal.hpp>
#include <forward_list>
namespace cereal
{
//! Saving for std::forward_list all other types to binary
//! Saving for std::forward_list all other types
template <class Archive, class T, class A> inline
void save( Archive & ar, std::forward_list<T, A> const & forward_list )
{
@ -43,28 +43,28 @@ namespace cereal
size_t size = 0;
for( const auto & i : forward_list )
{
ar( make_nvp("item", i) );
ar( i );
++size;
}
// write the size
ar.popPosition();
ar( CEREAL_NVP(size) );
ar( size );
ar.resetPosition();
}
//! Loading for std::forward_list all other types from binary
//! Loading for std::forward_list all other types from
template <class Archive, class T, class A>
void load( Archive & ar, std::forward_list<T, A> & forward_list )
{
size_t size;
ar( CEREAL_NVP(size) );
ar( size );
forward_list.resize( size );
for( auto & i : forward_list )
ar( make_nvp("item", i) );
ar( i );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_
#endif // CEREAL_TYPES_FORWARD_LIST_HPP_

View File

@ -24,17 +24,17 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_LIST_HPP_
#define CEREAL_BINARY_ARCHIVE_LIST_HPP_
#ifndef CEREAL_TYPES_LIST_HPP_
#define CEREAL_TYPES_LIST_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <list>
namespace cereal
{
//! Saving for std::list to binary
template <class T, class A> inline
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
//! Saving for std::list
template <class Archive, class T, class A> inline
void save( Archive & ar, std::list<T, A> const & list )
{
ar( list.size() );
@ -42,7 +42,7 @@ namespace cereal
ar( i );
}
//! Loading for std::list to binary
//! Loading for std::list
template <class T, class A> inline
void load( BinaryInputArchive & ar, std::list<T, A> & list )
{
@ -56,4 +56,4 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_LIST_HPP_
#endif // CEREAL_TYPES_LIST_HPP_

View File

@ -24,73 +24,69 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_MAP_HPP_
#define CEREAL_BINARY_ARCHIVE_MAP_HPP_
#ifndef CEREAL_TYPES_MAP_HPP_
#define CEREAL_TYPES_MAP_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <map>
namespace cereal
{
//! Saving for std::map to binary
template <class K, class T, class C, class A> inline
void save( BinaryOutputArchive & ar, std::map<K, T, C, A> const & map )
namespace map_detail
{
ar( map.size() );
for( const auto & i : map )
template <class Archive, class MapT> inline
void load( Archive & ar, MapT & map )
{
ar( i.first,
i.second );
size_t size;
ar( size );
for( size_t i = 0; i < size; ++i )
{
typename MapT::key_type key;
typename MapT::mapped_type value;
ar( key, value );
map.insert( {key, value} );
}
}
template <class Archive, class MapT> inline
void save( Archive & ar, MapT const & map )
{
ar( map.size() );
for( const auto & i : map )
ar( i.first, i.second );
}
}
//! Saving for std::map to binary
template <class Archive, class K, class T, class C, class A> inline
void save( Archive & ar, std::map<K, T, C, A> const & map )
{
map_detail::save( ar, map );
}
//! Loading for std::map to binary
template <class K, class T, class C, class A> inline
void load( BinaryInputArchive & ar, std::map<K, T, C, A> & map )
template <class Archive, class K, class T, class C, class A> inline
void load( Archive & ar, std::map<K, T, C, A> & map )
{
size_t size;
ar( size );
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar( key, value );
map.insert( {key, value} );
}
map_detail::load( ar, map );
}
//! Saving for std::multimap to binary
template <class K, class T, class C, class A> inline
void save( BinaryOutputArchive & ar, std::multimap<K, T, C, A> const & multimap )
template <class Archive, class K, class T, class C, class A> inline
void save( Archive & ar, std::multimap<K, T, C, A> const & multimap )
{
ar( multimap.size() );
for( const auto & i : multimap )
{
ar( i.first,
i.second );
}
map_detail::save( ar, multimap );
}
//! Loading for std::multimap to binary
template <class K, class T, class C, class A> inline
void load( BinaryInputArchive & ar, std::multimap<K, T, C, A> & multimap )
template <class Archive, class K, class T, class C, class A> inline
void load( Archive & ar, std::multimap<K, T, C, A> & multimap )
{
size_t size;
ar( size );
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar( key, value );
multimap.insert( {key, value} );
}
map_detail::load( ar, multimap );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_MAP_HPP_
#endif // CEREAL_TYPES_MAP_HPP_

View File

@ -24,17 +24,17 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_SHARED_PTR_HPP_
#define CEREAL_BINARY_ARCHIVE_SHARED_PTR_HPP_
#ifndef CEREAL_TYPES_SHARED_PTR_HPP_
#define CEREAL_TYPES_SHARED_PTR_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <memory>
namespace cereal
{
//! Saving std::shared_ptr to binary
template <class T> inline
void save( BinaryOutputArchive & ar, std::shared_ptr<T> const & ptr )
//! Saving std::shared_ptr
template <class Archive, class T> inline
void save( Archive & ar, std::shared_ptr<T> const & ptr )
{
uint32_t id = ar.registerSharedPointer( ptr.get() );
ar( id );
@ -45,10 +45,10 @@ namespace cereal
}
}
//! Loading std::shared_ptr to binary, case when user load and allocate
template <class T> inline
//! Loading std::shared_ptr, case when user load and allocate
template <class Archive, class T> inline
typename std::enable_if<traits::has_load_and_allocate<T, BinaryInputArchive>(), void>::type
load( BinaryInputArchive & ar, std::shared_ptr<T> & ptr )
load( Archive & ar, std::shared_ptr<T> & ptr )
{
uint32_t id;
@ -65,10 +65,10 @@ namespace cereal
}
}
//! Loading std::shared_ptr to binary, case when no user load and allocate
template <class T> inline
//! Loading std::shared_ptr, case when no user load and allocate
template <class Archive, class T> inline
typename std::enable_if<!traits::has_load_and_allocate<T, BinaryInputArchive>(), void>::type
load( BinaryInputArchive & ar, std::shared_ptr<T> & ptr )
load( Archive & ar, std::shared_ptr<T> & ptr )
{
uint32_t id;
@ -86,7 +86,7 @@ namespace cereal
}
}
//! Saving std::weak_ptr to binary
//! Saving std::weak_ptr
template <class T> inline
void save( BinaryOutputArchive & ar, std::weak_ptr<T> const & ptr )
{
@ -94,7 +94,7 @@ namespace cereal
ar( sptr );
}
//! Loading std::weak_ptr from binary
//! Loading std::weak_ptr
template <class T> inline
void load( BinaryInputArchive & ar, std::weak_ptr<T> & ptr )
{
@ -103,25 +103,25 @@ namespace cereal
ptr = sptr;
}
//! Saving std::unique_ptr to binary
//! Saving std::unique_ptr
template <class T, class D> inline
void save( BinaryOutputArchive & ar, std::unique_ptr<T, D> const & ptr )
{
ar( *ptr );
}
//! Loading std::unique_ptr from binary, case when user provides load_and_allocate
template <class T, class D> inline
//! Loading std::unique_ptr, case when user provides load_and_allocate
template <class Archive, class T, class D> inline
typename std::enable_if<traits::has_load_and_allocate<T, BinaryInputArchive>(), void>::type
load( BinaryInputArchive & ar, std::unique_ptr<T, D> & ptr )
{
ptr.reset( detail::Load<T, BinaryInputArchive>::load_andor_allocate( ar ) );
}
//! Loading std::unique_ptr from binary, case when no load_and_allocate
template <class T, class D> inline
//! Loading std::unique_ptr, case when no load_and_allocate
template <class Archive, class T, class D> inline
typename std::enable_if<!traits::has_load_and_allocate<T, BinaryInputArchive>(), void>::type
load( BinaryInputArchive & ar, std::unique_ptr<T, D> & ptr )
load( Archive & ar, std::unique_ptr<T, D> & ptr )
{
ptr.reset( detail::Load<T, BinaryInputArchive>::load_andor_allocate( ar ) );
ar( *ptr );
@ -129,5 +129,4 @@ namespace cereal
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_SHARED_PTR_HPP_
#endif // CEREAL_TYPES_SHARED_PTR_HPP_

View File

@ -24,10 +24,10 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_QUEUE_HPP_
#define CEREAL_BINARY_ARCHIVE_QUEUE_HPP_
#ifndef CEREAL_TYPES_QUEUE_HPP_
#define CEREAL_TYPES_QUEUE_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <queue>
namespace cereal
@ -80,33 +80,33 @@ namespace cereal
}
}
//! Saving for std::queue to binary
template <class T, class C> inline
void save( BinaryOutputArchive & ar, std::queue<T, C> const & queue )
//! Saving for std::queue
template <class Archive, class T, class C> inline
void save( Archive & ar, std::queue<T, C> const & queue )
{
ar( queue_detail::container( queue ) );
}
//! Loading for std::queue to binary
template <class T, class C> inline
void load( BinaryInputArchive & ar, std::queue<T, C> & queue )
//! Loading for std::queue
template <class Archive, class T, class C> inline
void load( Archive & ar, std::queue<T, C> & queue )
{
C container;
ar( container );
queue = std::queue<T, C>( std::move( container ) );
}
//! Saving for std::priority_queue to binary
template <class T, class C, class Comp> inline
void save( BinaryOutputArchive & ar, std::priority_queue<T, C, Comp> const & priority_queue )
//! Saving for std::priority_queue
template <class Archive, class T, class C, class Comp> inline
void save( Archive & ar, std::priority_queue<T, C, Comp> const & priority_queue )
{
ar( queue_detail::comparator( priority_queue ) );
ar( queue_detail::container( priority_queue ) );
}
//! Loading for std::priority_queue to binary
template <class T, class C, class Comp> inline
void load( BinaryInputArchive & ar, std::priority_queue<T, C, Comp> & priority_queue )
//! Loading for std::priority_queue
template <class Archive, class T, class C, class Comp> inline
void load( Archive & ar, std::priority_queue<T, C, Comp> & priority_queue )
{
Comp comparator;
ar( comparator );
@ -118,4 +118,4 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_QUEUE_HPP_
#endif // CEREAL_TYPES_QUEUE_HPP_

View File

@ -24,65 +24,68 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_SET_HPP_
#define CEREAL_BINARY_ARCHIVE_SET_HPP_
#ifndef CEREAL_TYPES_SET_HPP_
#define CEREAL_TYPES_SET_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <set>
namespace cereal
{
//! Saving for std::set to binary
template <class K, class C, class A> inline
void save( BinaryOutputArchive & ar, std::set<K, C, A> const & set )
namespace set_detail
{
ar( set.size() );
for( const auto & i : set )
ar( i );
}
//! Loading for std::set to binary
template <class K, class C, class A> inline
void load( BinaryInputArchive & ar, std::set<K, C, A> & set )
{
size_t size;
ar( size );
for( size_t i = 0; i < size; ++i )
template <class Archive, class SetT> inline
void save( Archive & ar, SetT const & set )
{
K key;
ar( set.size() );
ar( key );
set.insert( key );
for( const auto & i : set )
ar( i );
}
template <class Archive, class SetT> inline
void load( Archive & ar, SetT & set )
{
size_t size;
ar( size );
for( size_t i = 0; i < size; ++i )
{
typename SetT::key_type key;
ar( key );
set.insert( key );
}
}
}
//! Saving for std::multiset to binary
template <class K, class C, class A> inline
void save( BinaryOutputArchive & ar, std::multiset<K, C, A> const & multiset )
//! Saving for std::set
template <class Archive, class K, class C, class A> inline
void save( Archive & ar, std::set<K, C, A> const & set )
{
ar( multiset.size() );
for( const auto & i : multiset )
ar( i );
set_detail::save( ar, set );
}
//! Loading for std::multiset to binary
template <class K, class C, class A> inline
void load( BinaryInputArchive & ar, std::multiset<K, C, A> & multiset )
//! Loading for std::set
template <class Archive, class K, class C, class A> inline
void load( Archive & ar, std::set<K, C, A> & set )
{
size_t size;
ar( size );
set_detail::load( ar, set );
}
for( size_t i = 0; i < size; ++i )
{
K key;
//! Saving for std::multiset
template <class Archive, class K, class C, class A> inline
void save( Archive & ar, std::multiset<K, C, A> const & multiset )
{
set_detail::save( ar, multiset );
}
ar( key );
multiset.insert( key );
}
//! Loading for std::multiset
template <class Archive, class K, class C, class A> inline
void load( Archive & ar, std::multiset<K, C, A> & multiset )
{
set_detail::load( ar, multiset );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_SET_HPP_
#endif // CEREAL_TYPES_SET_HPP_

View File

@ -24,10 +24,10 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_STACK_HPP_
#define CEREAL_BINARY_ARCHIVE_STACK_HPP_
#ifndef CEREAL_TYPES_STACK_HPP_
#define CEREAL_TYPES_STACK_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <stack>
namespace cereal
@ -50,16 +50,16 @@ namespace cereal
}
}
//! Saving for std::stack to binary
template <class T, class C> inline
void save( BinaryOutputArchive & ar, std::stack<T, C> const & stack )
//! Saving for std::stack
template <class Archive, class T, class C> inline
void save( Archive & ar, std::stack<T, C> const & stack )
{
ar( stack_detail::container( stack ) );
}
//! Loading for std::stack to binary
template <class T, class C> inline
void load( BinaryInputArchive & ar, std::stack<T, C> & stack )
//! Loading for std::stack
template <class Archive, class T, class C> inline
void load( Archive & ar, std::stack<T, C> & stack )
{
C container;
ar( container );
@ -67,4 +67,4 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_STACK_HPP_
#endif // CEREAL_TYPES_STACK_HPP_

View File

@ -24,26 +24,28 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_STRING_HPP_
#define CEREAL_BINARY_ARCHIVE_STRING_HPP_
#ifndef CEREAL_TYPES_STRING_HPP_
#define CEREAL_TYPES_STRING_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <string>
namespace cereal
{
//! Serialization for basic_string types to binary
template<class CharT, class Traits, class Alloc> inline
void save(BinaryOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
//! Serialization for basic_string types, if binary data is supported
template<class Archive, class CharT, class Traits, class Alloc> inline
typename std::enable_if<traits::is_output_serializable<BinaryData<CharT>, Archive>(), void>::type
save(Archive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
{
// Save number of chars + the data
ar( str.size() );
ar( binary_data( str.data(), str.size() * sizeof(CharT) ) );
}
//! Serialization for basic_string types from binary
template<class CharT, class Traits, class Alloc> inline
void load(BinaryInputArchive & ar, std::basic_string<CharT, Traits, Alloc> & str)
//! Serialization for basic_string types, if binary data is supported
template<class Archive, class CharT, class Traits, class Alloc> inline
typename std::enable_if<traits::is_input_serializable<BinaryData<CharT>, Archive>(), void>::type
load(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str)
{
size_t size;
ar( size );
@ -52,5 +54,5 @@ namespace cereal
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_STRING_HPP_
#endif // CEREAL_TYPES_STRING_HPP_

View File

@ -24,10 +24,10 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_TUPLE_HPP_
#define CEREAL_BINARY_ARCHIVE_TUPLE_HPP_
#ifndef CEREAL_TYPES_TUPLE_HPP_
#define CEREAL_TYPES_TUPLE_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <tuple>
namespace cereal
@ -56,13 +56,12 @@ namespace cereal
};
}
//! Serializing for std::tuple to binary
//! Serializing for std::tuple
template <class Archive, class ... Types> inline
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
serialize( Archive & ar, std::tuple<Types...> & tuple )
void serialize( Archive & ar, std::tuple<Types...> & tuple )
{
tuple_detail::serialize<std::tuple_size<std::tuple<Types...>>::value>::template apply( ar, tuple );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_TUPLE_HPP_
#endif // CEREAL_TYPES_TUPLE_HPP_

View File

@ -0,0 +1,94 @@
/*
Copyright (c) 2013, Randolph Voorhies, Shane Grant
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_
#define CEREAL_TYPES_UNORDERED_MAP_HPP_
#include <cereal/cereal.hpp>
#include <unordered_map>
namespace cereal
{
namespace unordered_map_detail
{
template <class Archive, class MapT> inline
void load( Archive & ar, MapT & map )
{
size_t size;
ar( size );
map.reserve( size );
for( size_t i = 0; i < size; ++i )
{
typename MapT::key_type key;
typename MapT::mapped_type value;
ar( key, value );
map.insert( {key, value} );
}
}
template <class Archive, class MapT> inline
void save( Archive & ar, MapT const & map )
{
ar( map.size() );
for( const auto & i : map )
ar( i.first, i.second );
}
}
//! Saving for std::unordered_map
template <class Archive, class K, class T, class H, class KE, class A> inline
void save( Archive & ar, std::unordered_map<K, T, H, KE, A> const & unordered_map )
{
unordered_map_detail::save( ar, unordered_map );
}
//! Loading for std::unordered_map
template <class Archive, class K, class T, class H, class KE, class A> inline
void load( Archive & ar, std::unordered_map<K, T, H, KE, A> & unordered_map )
{
unordered_map_detail::load( ar, unordered_map );
}
//! Saving for std::unordered_multimap
template <class Archive, class K, class T, class H, class KE, class A> inline
void save( Archive & ar, std::unordered_multimap<K, T, H, KE, A> const & unordered_multimap )
{
unordered_map_detail::save( ar, unordered_multimap );
}
//! Loading for std::unordered_multimap
template <class Archive, class K, class T, class H, class KE, class A> inline
void load( Archive & ar, std::unordered_multimap<K, T, H, KE, A> & unordered_multimap )
{
unordered_map_detail::load( ar, unordered_multimap );
}
} // namespace cereal
#endif // CEREAL_TYPES_UNORDERED_MAP_HPP_

View File

@ -24,69 +24,70 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_
#define CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_
#ifndef CEREAL_TYPES_UNORDERED_SET_HPP_
#define CEREAL_TYPES_UNORDERED_SET_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <unordered_set>
namespace cereal
{
//! Saving for std::unordered_set to binary
template <class K, class H, class KE, class A> inline
void save( BinaryOutputArchive & ar, std::unordered_set<K, H, KE, A> const & unordered_set )
namespace unordered_set_detail
{
ar( unordered_set.size() );
for( const auto & i : unordered_set )
ar( i );
}
//! Loading for std::unordered_set to binary
template <class K, class H, class KE, class A> inline
void load( BinaryInputArchive & ar, std::unordered_set<K, H, KE, A> & unordered_set )
{
size_t size;
ar( size );
unordered_set.reserve( size );
for( size_t i = 0; i < size; ++i )
template <class Archive, class SetT> inline
void save( Archive & ar, SetT const & set )
{
K key;
ar( set.size() );
ar( key );
unordered_set.insert( key );
for( const auto & i : set )
ar( i );
}
template <class Archive, class SetT> inline
void load( Archive & ar, SetT & set )
{
size_t size;
ar( size );
set.reserve( size );
for( size_t i = 0; i < size; ++i )
{
typename SetT::key_type key;
ar( key );
set.insert( key );
}
}
}
//! Saving for std::unordered_multiset to binary
template <class K, class H, class KE, class A> inline
void save( BinaryOutputArchive & ar, std::unordered_multiset<K, H, KE, A> const & unordered_multiset )
//! Saving for std::unordered_set
template <class Archive, class K, class H, class KE, class A> inline
void save( Archive & ar, std::unordered_set<K, H, KE, A> const & unordered_set )
{
ar( unordered_multiset.size() );
for( const auto & i : unordered_multiset )
ar( i );
unordered_set_detail::save( ar, unordered_set );
}
//! Loading for std::unordered_multiset to binary
template <class K, class H, class KE, class A> inline
void load( BinaryInputArchive & ar, std::unordered_multiset<K, H, KE, A> & unordered_multiset )
//! Loading for std::unordered_set
template <class Archive, class K, class H, class KE, class A> inline
void load( Archive & ar, std::unordered_set<K, H, KE, A> & unordered_set )
{
size_t size;
ar( size );
unordered_set_detail::load( ar, unordered_set );
}
unordered_multiset.reserve( size );
//! Saving for std::unordered_multiset
template <class Archive, class K, class H, class KE, class A> inline
void save( Archive & ar, std::unordered_multiset<K, H, KE, A> const & unordered_multiset )
{
unordered_set_detail::save( ar, unordered_multiset );
}
for( size_t i = 0; i < size; ++i )
{
K key;
ar( key );
unordered_multiset.insert( key );
}
//! Loading for std::unordered_multiset
template <class Archive, class K, class H, class KE, class A> inline
void load( Archive & ar, std::unordered_multiset<K, H, KE, A> & unordered_multiset )
{
unordered_set_detail::load( ar, unordered_multiset );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_
#endif // CEREAL_TYPES_UNORDERED_SET_HPP_

View File

@ -24,22 +24,21 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_UTILITY_HPP_
#define CEREAL_BINARY_ARCHIVE_UTILITY_HPP_
#ifndef CEREAL_TYPES_UTILITY_HPP_
#define CEREAL_TYPES_UTILITY_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <cereal/cereal.hpp>
#include <utility>
namespace cereal
{
//! Serializing for std::pair to binary
//! Serializing for std::pair
template <class Archive, class T1, class T2> inline
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
serialize( Archive & ar, std::pair<T1, T2> & pair )
void serialize( Archive & ar, std::pair<T1, T2> & pair )
{
ar( pair.first,
pair.second );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_UTILITY_HPP_
#endif // CEREAL_TYPES_UTILITY_HPP_

View File

@ -24,26 +24,28 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_BINARY_ARCHIVE_VECTOR_HPP_
#define CEREAL_BINARY_ARCHIVE_VECTOR_HPP_
#ifndef CEREAL_TYPES_VECTOR_HPP_
#define CEREAL_TYPES_VECTOR_HPP_
#include <cereal/cereal.hpp>
#include <vector>
namespace cereal
{
//! Serialization for std::vectors of arithmetic (but not bool) types to binary, default allocator
//! Serialization for std::vectors of arithmetic (but not bool), default allocator
//! using binary serialization, if supported
template <class Archive, class T, class A> inline
typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>()
&& std::is_arithmetic<T>::value && !std::is_same<T, bool>::value
&& std::is_same<A, std::allocator<T>>::value, void>::type
save( Archive & ar, std::vector<T, A> const & vector )
{
ar( make_nvp( "size", vector.size() ) ); // number of elements
ar( make_nvp( "data", binary_data( vector.data(), vector.size() * sizeof(T) ) ) );
ar( vector.size() ); // number of elements
ar( binary_data( vector.data(), vector.size() * sizeof(T) ) );
}
//! Serialization for std::vectors of arithmetic (but not bool) types to binary, default allocator
//! Serialization for std::vectors of arithmetic (but not bool), default allocator
//! using binary serialization, if supported
template <class Archive, class T, class A> inline
typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>()
&& std::is_arithmetic<T>::value && !std::is_same<T, bool>::value
@ -51,13 +53,14 @@ namespace cereal
load( Archive & ar, std::vector<T, A> & vector )
{
size_t vectorSize;
ar( make_nvp( "size", vectorSize) );
ar( vectorSize );
vector.resize( vectorSize );
ar( make_nvp( "data", binary_data( vector.data(), vectorSize * sizeof(T) ) ) );
ar( binary_data( vector.data(), vectorSize * sizeof(T) ) );
}
//! Serialization for std::vectors of arithmetic (but not bool) types to binary, special allocator
//! Serialization for std::vectors of arithmetic (but not bool), special allocator
//! using binary serialization, if supported
template <class Archive, class T, class A> inline
typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>()
&& std::is_arithmetic<T>::value && !std::is_same<T, bool>::value
@ -66,12 +69,13 @@ namespace cereal
{
size_t const dataSize = std::addressof(vector.back()) - std::addressof(vector.front()) + 1;
ar( make_nvp( "size", vector.size() ) ); // number of elements
ar( make_nvp( "datasize", dataSize) ); // size of data (may be larger due to allocator strategy)
ar( make_nvp( "data", binary_data( vector.data(), dataSize * sizeof(T) ) ) );
ar( vector.size() ); // number of elements
ar( dataSize ); // size of data (may be larger due to allocator strategy)
ar( binary_data( vector.data(), dataSize * sizeof(T) ) );
}
//! Serialization for std::vectors of arithmetic (but not bool) types to binary, special allocator
//! Serialization for std::vectors of arithmetic (but not bool), special allocator
//! using binary serialization, if supported
template <class Archive, class T, class A> inline
typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>()
&& std::is_arithmetic<T>::value && !std::is_same<T, bool>::value
@ -80,27 +84,27 @@ namespace cereal
{
size_t vectorSize;
size_t dataSize;
ar( make_nvp( "size", vectorSize ),
make_nvp( "datasize", dataSize ) );
ar( vectorSize,
dataSize );
vector.resize( vectorSize );
ar( binary_data( vector.data(), dataSize * sizeof(T) ) );
}
//! Serialization for non-arithmetic (and bool) vector types to binary
//! Serialization for non-arithmetic (and bool) vector types
template <class Archive, class T, class A> inline
typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value
|| std::is_same<T, bool>::value, void>::type
save( Archive & ar, std::vector<T, A> const & vector )
{
ar( make_nvp( "size", vector.size() ) ); // number of elements
ar( vector.size() ); // number of elements
for( auto it = vector.begin(), end = vector.end(); it != end; ++it )
ar( make_nvp( "item", *it) );
ar( *it );
}
//! Serialization for non-arithmetic (and bool) vector types from binary
//! Serialization for non-arithmetic (and bool) vector types
template <class Archive, class T, class A> inline
typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>()
|| !std::is_arithmetic<T>::value
@ -108,12 +112,12 @@ namespace cereal
load( Archive & ar, std::vector<T, A> & vector )
{
size_t size;
ar( CEREAL_NVP(size) );
ar( size );
vector.resize( size );
for( auto it = vector.begin(), end = vector.end(); it != end; ++it )
ar( make_nvp( "item", *it) );
ar( *it );
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_VECTOR_HPP_
#endif // CEREAL_TYPES_VECTOR_HPP_