15 #ifndef _OM_STORE_RESTORE_H
16 #define _OM_STORE_RESTORE_H
18 #include <OpenMesh\Core\IO\SR_store.hh>
19 #include <MDSTk/Module/mdsChannel.h>
30 template <
typename T >
struct binaryExt : binary<T>
35 static size_t store( mds::mod::CChannel&,
const value_type&,
bool)
44 static size_t restore( mds::mod::CChannel&, value_type&,
bool)
55 #define SIMPLE_BINARY_EXT( T ) \
56 template <> struct binaryExt< T > \
58 typedef T value_type; \
59 static const bool is_streamable = true; \
61 static size_t size_of(const value_type&) { return sizeof(value_type); } \
62 static size_t size_of(void) { return sizeof(value_type); } \
63 static size_t store(std::ostream& _os, const value_type& _val, bool _swap=false) { \
64 value_type tmp = _val; \
65 if (_swap) reverse_byte_order(tmp); \
66 _os.write( (const char*)&tmp, sizeof(value_type) ); \
67 return _os.good() ? sizeof(value_type) : 0; \
70 static size_t restore( std::istream& _is, value_type& _val, bool _swap=false) { \
71 _is.read( (char*)&_val, sizeof(value_type) ); \
72 if (_swap) reverse_byte_order(_val); \
73 return _is.good() ? sizeof(value_type) : 0; \
76 static size_t store( mds::mod::CChannel& _os, const value_type& _val, bool _swap=false) { \
77 value_type tmp = _val; \
78 if (_swap) reverse_byte_order(tmp); \
79 _os.write( (const char*)&tmp, sizeof(value_type) ); \
80 return sizeof(value_type); \
83 static size_t restore( mds::mod::CChannel& _is, value_type& _val, bool _swap=false) { \
84 _is.read( (char*)&_val, sizeof(value_type) ); \
85 if (_swap) reverse_byte_order(_val); \
86 return sizeof(value_type); \
142 #define VECTORT_BINARY_EXT( T ) \
143 template <> struct binaryExt< T > { \
144 typedef T value_type; \
145 static const bool is_streamable = true; \
146 static size_t size_of(void) { return sizeof(value_type); } \
147 static size_t size_of(const value_type&) { return size_of(); } \
148 static size_t store( std::ostream& _os, const value_type& _val, bool _swap=false) { \
149 value_type tmp = _val; \
150 size_t i, b = size_of(_val), N = value_type::size_; \
151 if (_swap) for (i=0; i<N; ++i) \
152 reverse_byte_order( tmp[i] ); \
153 _os.write( (const char*)&tmp[0], b ); \
154 return _os.good() ? b : 0; \
157 static size_t restore( std::istream& _is, value_type& _val, bool _swap=false) { \
158 size_t i, N=value_type::size_; \
159 size_t b = N * sizeof(value_type::value_type); \
160 _is.read( (char*)&_val[0], b ); \
161 if (_swap) for (i=0; i<N; ++i) \
162 reverse_byte_order( _val[i] ); \
163 return _is.good() ? b : 0; \
166 static size_t store( mds::mod::CChannel& _os, const value_type& _val, bool _swap=false) { \
167 value_type tmp = _val; \
168 size_t i, b = size_of(_val), N = value_type::size_; \
169 if (_swap) for (i=0; i<N; ++i) \
170 reverse_byte_order( tmp[i] ); \
171 _os.write( (const char*)&tmp[0], b ); \
175 static size_t restore( mds::mod::CChannel& _is, value_type& _val, bool _swap=false) { \
176 size_t i, N=value_type::size_; \
177 size_t b = N * sizeof(value_type::value_type); \
178 _is.read( (char*)&_val[0], b ); \
179 if (_swap) for (i=0; i<N; ++i) \
180 reverse_byte_order( _val[i] ); \
188 #define VECTORTS_BINARY_EXT( N ) \
189 VECTORT_BINARY_EXT( Vec##N##c ); \
190 VECTORT_BINARY_EXT( Vec##N##uc ); \
191 VECTORT_BINARY_EXT( Vec##N##s ); \
192 VECTORT_BINARY_EXT( Vec##N##us ); \
193 VECTORT_BINARY_EXT( Vec##N##i ); \
194 VECTORT_BINARY_EXT( Vec##N##ui ); \
195 VECTORT_BINARY_EXT( Vec##N##f ); \
196 VECTORT_BINARY_EXT( Vec##N##d );
231 static const bool is_streamable =
true;
235 static size_t size_of() {
return UnknownSize; }
250 #if defined(OM_CC_GCC) && (OM_CC_VERSION < 30000)
251 if (_v.size() < Utils::NumLimitsT<length_t>::max() )
253 if (_v.size() < std::numeric_limits<length_t>::max() )
257 if (_swap) reverse_byte_order(len);
260 _os.write( _v.data(), len );
263 throw std::runtime_error(
"Cannot store string longer than 64Kb");
278 reverse_byte_order(len);
280 _is.read( const_cast<char*>(_val.data()), len );
290 template <>
struct binaryExt<OpenMesh::Attributes::StatusInfo>
295 static const bool is_streamable =
true;
307 static size_t n_bytes(
size_t _n_elem)