OMToolkit  1.0
The polygonal mesh processing tool.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OMSerializableVector.h
Go to the documentation of this file.
1 //==============================================================================
14 #ifndef _OM_SERIALIZABLE_VECTOR_H_
15 #define _OM_SERIALIZABLE_VECTOR_H_
16 
17 #include <OpenMesh\Core\Utils\BaseProperty.hh>
19 
20 namespace OMToolkit {
21 namespace Types {
22 
26  template <typename T>
27  class OMSerializableVector : public std::vector<T>
28  {
29  }; // class OMSerializableVector
30 
31 } // namespace Types
32 } // namespace OMToolkit
33 
34 namespace OpenMesh{
35 namespace IO{
36 
40  template <class T> struct binary<OMToolkit::Types::OMSerializableVector<T>>
41  {
46 
50  static const bool is_streamable = true;
51 
56  static size_t size_of(void)
57  {
58  return UnknownSize;
59  }
60 
64  static size_t size_of(const value_type& _v)
65  {
66  return _v.size() + sizeof(unsigned int);
67  }
68 
73  static size_t store(std::ostream& _os, const value_type& _v, bool _swap=false)
74  {
75  size_t bytes;
76  unsigned int size = _v.size();
77  bytes = IO::store( _os, size, _swap);
78  for (unsigned int i = 0; i < size; ++i)
79  bytes += IO::store( _os, _v[i], _swap );
80  return _os.good() ? bytes : 0;
81  }
82 
87  static size_t restore( std::istream& _is, value_type& _v, bool _swap=false)
88  {
89  size_t bytes;
90  unsigned int size;
91  bytes = IO::restore( _is, size, _swap );
92  _v.resize(size);
93  for (unsigned int i = 0; i < size && _is.good(); ++i)
94  bytes += IO::restore( _is, _v[i], _swap );
95  return _is.good() ? bytes : 0;
96  }
97  };
98 } // namespace IO
99 } // namespace OpenMesh
100 
101 #endif //_OM_SERIALIZABLE_VECTOR_H_