//! Saving for std::valarray arithmetic types, using binary serialization, if supported template<class Archive, class T> inline typename std::enable_if< traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray<T> const & valarray) { ar(make_size_tag(static_cast<size_type>(valarray.size()))); // number of elements ar(binary_data(&valarray[0], valarray.size() * sizeof(T))); // &valarray[0] ok since guaranteed contiguous }
//! Serialization for bool vector types template <class Archive, class A> inline void save( Archive & ar, std::vector<bool, A> const & vector ) { ar( make_size_tag( static_cast<size_type>(vector.size()) ) ); // number of elements for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar( static_cast<bool>( *it ) ); }
//! Serialization for bool vector types template <class Archive, class A> inline void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::vector<bool, A> const & vector ) { ar( make_size_tag( static_cast<size_type>(vector.size()) ) ); // number of elements for(auto && v : vector) ar( static_cast<bool>(v) ); }
//! @internal template <class Archive, class MapT> inline void save( Archive & ar, MapT const & map ) { ar( make_size_tag( static_cast<size_type>(map.size()) ) ); for( const auto & i : map ) ar( make_map_item(i.first, i.second) ); }
//! Saving for std::valarray all other types template<class Archive, class T> inline typename std::enable_if< !traits::is_output_serializable<BinaryData<T>, Archive>::value || !std::is_arithmetic<T>::value, void>::type CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray<T> const & valarray) { ar(make_size_tag(static_cast<size_type>(valarray.size()))); // number of elements for (auto && v : valarray) ar(v); }
//! Saving for std::deque template <class Archive, class T, class A> inline void save( Archive & ar, std::deque<T, A> const & deque ) { ar( make_size_tag( deque.size() ) ); for( auto const & i : deque ) ar( i ); }
//! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported template <class Archive, class T, class A> inline typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type save( Archive & ar, std::vector<T, A> const & vector ) { ar( make_size_tag( static_cast<size_type>(vector.size()) ) ); // number of elements ar( binary_data( vector.data(), vector.size() * sizeof(T) ) ); }
//! @internal template <class Archive, class SetT> inline void save( Archive & ar, SetT const & set ) { ar( make_size_tag( set.size() ) ); for( const auto & i : set ) ar( i ); }
//! 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( make_size_tag( str.size() ) ); ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); }
//! Saving for std::list template <class Archive, class T, class A> inline void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list<T, A> const & list ) { ar( make_size_tag( static_cast<size_type>(list.size()) ) ); for( auto const & i : list ) ar( i ); }
//! Saving for std::list template <class Archive, class T, class A> inline void save( Archive & ar, std::list<T, A> const & list ) { ar( make_size_tag( static_cast<size_type>(list.size()) ) ); for( auto const & i : list ) ar( i ); }
//! Serialization for non-arithmetic vector types template <class Archive, class T, class A> inline typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>::value || !std::is_arithmetic<T>::value, void>::type save( Archive & ar, std::vector<T, A> const & vector ) { ar( make_size_tag( static_cast<size_type>(vector.size()) ) ); // number of elements for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar( *it ); }
//! 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>::value, void>::type CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str) { size_type size; ar( make_size_tag( size ) ); str.resize(static_cast<std::size_t>(size)); ar( binary_data( const_cast<CharT *>( str.data() ), static_cast<std::size_t>(size) * sizeof(CharT) ) ); }
void CEREAL_LOAD_FUNCTION_NAME(Archive &ar, std::forward_list<T, A> &forward_list) { size_type size; ar(make_size_tag(size)); forward_list.resize(static_cast<size_t>( size )); for (auto &i : forward_list) ar(i); }
//! 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( make_size_tag( size ) ); str.resize(size); ar( binary_data( &(*str.begin()), size * sizeof(CharT) ) ); }
void load( Archive & ar, std::forward_list<T, A> & forward_list ) { size_type size; ar( make_size_tag( size ) ); forward_list.resize( static_cast<size_t>( size ) ); for( auto & i : forward_list ) ar( i ); }
//! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported template <class Archive, class T, class A> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type load( Archive & ar, std::vector<T, A> & vector ) { size_type vectorSize; ar( make_size_tag( vectorSize ) ); vector.resize( static_cast<std::size_t>( vectorSize ) ); ar( binary_data( vector.data(), static_cast<std::size_t>( vectorSize ) * sizeof(T) ) ); }
//! Loading for std::list template <class Archive, class T, class A> inline void load( Archive & ar, std::list<T, A> & list ) { size_type size; ar( make_size_tag( size ) ); list.resize( static_cast<size_t>( size ) ); for( auto & i : list ) ar( i ); }
//! Loading for std::valarray arithmetic types, using binary serialization, if supported template <class Archive, class T> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray<T> & valarray ) { size_type valarraySize; ar( make_size_tag( valarraySize ) ); valarray.resize( static_cast<std::size_t>( valarraySize ) ); ar( binary_data( &valarray[0], static_cast<std::size_t>( valarraySize ) * sizeof(T) ) ); }
//! Loading for std::valarray all other types template<class Archive, class T> inline typename std::enable_if< !traits::is_input_serializable<BinaryData<T>, Archive>::value || !std::is_arithmetic<T>::value, void>::type CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray<T> & valarray) { size_type valarraySize; ar(make_size_tag(valarraySize)); valarray.resize(static_cast<size_t>(valarraySize)); for (auto && v : valarray) ar(v); }
//! 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( make_size_tag( size ) ); deque.resize( size ); for( auto & i : deque ) ar( i ); }
//! Loading for std::list template <class Archive, class T, class A> inline void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list<T, A> & list ) { size_type size; ar( make_size_tag( size ) ); list.resize( static_cast<size_t>( size ) ); for( auto & i : list ) ar( i ); }
//! Serialization for non-arithmetic vector types template <class Archive, class T, class A> inline typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>::value || !std::is_arithmetic<T>::value, void>::type load( Archive & ar, std::vector<T, A> & vector ) { size_type size; ar( make_size_tag( size ) ); vector.resize( static_cast<std::size_t>( size ) ); for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar( *it ); }
inline void CEREAL_SAVE_FUNCTION_NAME(Archive &ar, std::forward_list<T, A> const &forward_list) { // write the size - note that this is slow because we need to traverse // the entire list. there are ways we could avoid this but this was chosen // since it works in the most general fashion with any archive type size_type const size = std::distance(forward_list.begin(), forward_list.end()); ar(make_size_tag(size)); // write the list for (const auto &i : forward_list) ar(i); }
//! Serialization for bool vector types template <class Archive, class A> inline void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::vector<bool, A> & vector ) { size_type size; ar( make_size_tag( size ) ); vector.resize( static_cast<std::size_t>( size ) ); for(auto && v : vector) { bool b; ar( b ); v = b; } }
//! Serialization for bool vector types template <class Archive, class A> inline void load( Archive & ar, std::vector<bool, A> & vector ) { size_type size; ar( make_size_tag( size ) ); vector.resize( static_cast<std::size_t>( size ) ); for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) { bool b; ar( b ); *it = b; } }
//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_type size; ar( make_size_tag( size ) ); set.clear(); set.reserve( size ); for( size_type i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); set.insert( key ); } }
//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_type size; ar( make_size_tag( size ) ); set.clear(); set.reserve( static_cast<std::size_t>( size ) ); for( size_type i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); set.emplace( std::move( key ) ); } }
//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_t size; ar( make_size_tag( size ) ); set.clear(); auto hint = set.begin(); for( size_t i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); hint = set.insert(hint, key ); } }
//! @internal template <class Archive, class MapT> inline void load( Archive & ar, MapT & map ) { size_type size; ar( make_size_tag( size ) ); map.clear(); auto hint = map.begin(); for( size_t i = 0; i < size; ++i ) { typename MapT::key_type key; typename MapT::mapped_type value; ar( make_map_item(key, value) ); hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); } }