SR_binary_vector_of_string.inl 1.11 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

template <> struct binary< std::vector< std::string > >
{
  // struct binary interface

  typedef std::vector< std::string > value_type;
  typedef value_type::value_type     elem_type;

  static const bool is_streamable = true;

  // Helper

  struct Sum
  {
    size_t operator() ( size_t _v1, const elem_type& _s2 )
    { return _v1 + binary<elem_type>::size_of(_s2); }
  };

  // struct binary interface

  static size_t size_of(void) { return UnknownSize; }

  static size_t size_of(const value_type& _v)
  { return std::accumulate( _v.begin(), _v.end(), 0u, Sum() ); }

  static 
  size_t store(std::ostream& _os, const value_type& _v, bool _swap=false)
  {
    return std::accumulate( _v.begin(), _v.end(), 0, 
			    FunctorStore<elem_type>(_os, _swap) );
  }                                                        
                                                             
  static
  size_t restore(std::istream& _is, value_type& _v, bool _swap=false) 
  {
    return std::accumulate( _v.begin(), _v.end(), 0, 
			    FunctorRestore<elem_type>(_is, _swap) );
  }                                                        
};