Ejemplo n.º 1
0
//! 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
}
Ejemplo n.º 2
0
 //! 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 ) );
 }
Ejemplo n.º 3
0
 //! 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) );
 }
Ejemplo n.º 4
0
    //! @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) );
    }
Ejemplo n.º 5
0
//! 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);
}
Ejemplo n.º 6
0
  //! 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 );
  }
Ejemplo n.º 7
0
 //! 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) ) );
 }
Ejemplo n.º 8
0
    //! @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 );
    }
Ejemplo n.º 9
0
//! 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) ) );
}
Ejemplo n.º 10
0
  //! 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 );
  }
Ejemplo n.º 11
0
  //! 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 );
  }
Ejemplo n.º 12
0
 //! 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 );
 }
Ejemplo n.º 13
0
 //! 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) ) );
 }
Ejemplo n.º 14
0
    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);
    }
Ejemplo n.º 15
0
//! 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) ) );
}
Ejemplo n.º 16
0
  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 );
  }
Ejemplo n.º 17
0
  //! 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) ) );
  }
Ejemplo n.º 18
0
  //! 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 );
  }
Ejemplo n.º 19
0
  //! 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) ) );
  }
Ejemplo n.º 20
0
//! 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);
}
Ejemplo n.º 21
0
  //! 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 );
  }
Ejemplo n.º 22
0
  //! 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 );
  }
Ejemplo n.º 23
0
  //! 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 );
  }
Ejemplo n.º 24
0
    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);
    }
Ejemplo n.º 25
0
  //! 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;
    }
  }
Ejemplo n.º 26
0
  //! 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;
    }
  }
Ejemplo n.º 27
0
    //! @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 );
      }
    }
Ejemplo n.º 28
0
    //! @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 ) );
      }
    }
Ejemplo n.º 29
0
    //! @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 );
      }
    }
Ejemplo n.º 30
0
    //! @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 ) );
      }
    }