15 #ifndef OM_FORMAT_EXT_H
16 #define OM_FORMAT_EXT_H
18 #include <OpenMesh\Core\IO\OMFormat.hh>
36 size_t store( mds::mod::CChannel& _os,
bool _swap )
const
38 _os.write( (
char*)
this, 4);
52 size_t restore( mds::mod::CChannel& _is,
bool _swap )
54 if (_is.read( (
char*)
this, 4 ) == 0)
74 template <
typename T>
inline
75 size_t store( mds::mod::CChannel& _os,
const T& _v,
bool _swap=
false)
87 template <
typename T>
inline
88 size_t restore( mds::mod::CChannel& _is, T& _v,
bool _swap=
false)
103 return _hdr.
store( _os, _swap );
116 return _hdr.
restore( _is, _swap );
128 size_t store( mds::mod::CChannel& _os,
const OMFormat::Chunk::Header& _hdr,
bool _swap)
130 OMFormat::uint16 val; val << _hdr;
142 size_t restore( mds::mod::CChannel& _is, OMFormat::Chunk::Header& _hdr,
bool _swap )
144 OMFormat::uint16 val;
165 template<
typename T >
size_t store( mds::mod::CChannel& _os,
const T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap, t_signed);
176 template<
typename T >
size_t store( mds::mod::CChannel& _os,
const T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap, t_unsigned);
186 template<
typename T >
inline size_t store( mds::mod::CChannel& _os,
const T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap)
188 assert( OMFormat::is_integer( _val ) );
189 if ( OMFormat::is_signed( _val ) )
190 return store( _os, _val, _b, _swap, t_signed() );
191 return store( _os, _val, _b, _swap, t_unsigned() );
203 template<
typename T >
inline size_t restore( mds::mod::CChannel& _is, T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap, t_signed);
214 template<
typename T >
inline size_t restore( mds::mod::CChannel& _is, T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap, t_unsigned);
224 template<
typename T >
inline size_t restore( mds::mod::CChannel& _is, T& _val, OMFormat::Chunk::Integer_Size _b,
bool _swap)
226 assert( OMFormat::is_integer( _val ) );
228 if ( OMFormat::is_signed( _val ) )
229 return restore( _is, _val, _b, _swap, t_signed() );
230 return restore( _is, _val, _b, _swap, t_unsigned() );
245 template <
typename VecT>
inline size_t store( mds::mod::CChannel& _os,
const VecT& _vec, GenProg::Int2Type<2>,
bool _swap )
247 size_t bytes =
store( _os, _vec[0], _swap );
248 bytes +=
store( _os, _vec[1], _swap );
259 template <
typename VecT>
inline size_t store( mds::mod::CChannel& _os,
const VecT& _vec, GenProg::Int2Type<3>,
bool _swap )
261 size_t bytes =
store( _os, _vec[0], _swap );
262 bytes +=
store( _os, _vec[1], _swap );
263 bytes +=
store( _os, _vec[2], _swap );
274 template <
typename VecT>
inline size_t store( mds::mod::CChannel& _os,
const VecT& _vec, GenProg::Int2Type<4>,
bool _swap )
276 size_t bytes =
store( _os, _vec[0], _swap );
277 bytes +=
store( _os, _vec[1], _swap );
278 bytes +=
store( _os, _vec[2], _swap );
279 bytes +=
store( _os, _vec[3], _swap );
290 template <
typename VecT>
inline size_t store( mds::mod::CChannel& _os,
const VecT& _vec, GenProg::Int2Type<1>,
bool _swap )
292 return store( _os, _vec[0], _swap );
302 template <
typename VecT>
inline size_t vector_store(mds::mod::CChannel& _os,
const VecT& _vec,
bool _swap )
304 return store( _os, _vec, GenProg::Int2Type< vector_traits<VecT>::size_ >(), _swap );
317 template <
typename VecT>
inline size_t restore( mds::mod::CChannel& _is, VecT& _vec, GenProg::Int2Type<2>,
bool _swap )
319 size_t bytes =
restore( _is, _vec[0], _swap );
320 bytes +=
restore( _is, _vec[1], _swap );
331 template <
typename VecT>
inline size_t restore( mds::mod::CChannel& _is, VecT& _vec, GenProg::Int2Type<3>,
bool _swap )
333 typedef typename vector_traits<VecT>::value_type scalar_type;
349 template <
typename VecT>
inline size_t restore( mds::mod::CChannel& _is, VecT& _vec, GenProg::Int2Type<4>,
bool _swap )
351 typedef typename vector_traits<VecT>::value_type scalar_type;
368 template <
typename VecT>
inline size_t restore( mds::mod::CChannel& _is, VecT& _vec, GenProg::Int2Type<1>,
bool _swap )
370 return restore( _is, _vec[0], _swap );
380 template <
typename VecT>
inline size_t vector_restore( mds::mod::CChannel& _is, VecT& _vec,
bool _swap )
382 return restore( _is, _vec, GenProg::Int2Type< vector_traits<VecT>::size_ >(), _swap );
395 template <>
inline size_t store( mds::mod::CChannel& _os,
const OMFormat::Chunk::PropertyName& _pn,
bool _swap )
397 store( _os, _pn.size(), OMFormat::Chunk::Integer_8, _swap );
399 _os.write( _pn.c_str(), _pn.size() );
400 return _pn.size() + 1;
410 template <>
inline size_t restore( mds::mod::CChannel& _is, OMFormat::Chunk::PropertyName& _pn,
bool _swap )
414 restore( _is, size, OMFormat::Chunk::Integer_8, _swap);
416 assert( OMFormat::Chunk::PropertyName::is_valid( size ) );
421 _is.read( buf, size );