adapt store/restore functions as well as size of, so that
for std::vector the size is stored if desired
This commit is contained in:
@@ -89,18 +89,34 @@ template <typename T> inline
|
|||||||
size_t size_of( const T& _v )
|
size_t size_of( const T& _v )
|
||||||
{ return binary< T >::size_of(_v); }
|
{ return binary< T >::size_of(_v); }
|
||||||
|
|
||||||
|
template <typename T> inline
|
||||||
|
size_t size_of( const std::vector<T> & _v, bool _store_size = true)
|
||||||
|
{ return binary< std::vector<T> >::size_of(_v, _store_size); }
|
||||||
|
|
||||||
template <typename T> inline
|
template <typename T> inline
|
||||||
size_t size_of(void)
|
size_t size_of(void)
|
||||||
{ return binary< T >::size_of(); }
|
{ return binary< T >::size_of(); }
|
||||||
|
|
||||||
|
template <typename T> inline
|
||||||
|
size_t size_of(bool _store_size)
|
||||||
|
{ return binary< std::vector<T> >::size_of(_store_size); }
|
||||||
|
|
||||||
template <typename T> inline
|
template <typename T> inline
|
||||||
size_t store( std::ostream& _os, const T& _v, bool _swap=false)
|
size_t store( std::ostream& _os, const T& _v, bool _swap=false)
|
||||||
{ return binary< T >::store( _os, _v, _swap ); }
|
{ return binary< T >::store( _os, _v, _swap ); }
|
||||||
|
|
||||||
|
template <typename T> inline
|
||||||
|
size_t store( std::ostream& _os, const std::vector<T>& _v, bool _swap=false, bool _store_size = true)
|
||||||
|
{ return binary< std::vector<T> >::store( _os, _v, _swap, _store_size); }
|
||||||
|
|
||||||
template <typename T> inline
|
template <typename T> inline
|
||||||
size_t restore( std::istream& _is, T& _v, bool _swap=false)
|
size_t restore( std::istream& _is, T& _v, bool _swap=false)
|
||||||
{ return binary< T >::restore( _is, _v, _swap ); }
|
{ return binary< T >::restore( _is, _v, _swap ); }
|
||||||
|
|
||||||
|
template <typename T> inline
|
||||||
|
size_t restore( std::istream& _is, std::vector<T>& _v, bool _swap=false, bool _restore_size = true)
|
||||||
|
{ return binary< std::vector<T> >::restore( _is, _v, _swap, _restore_size); }
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <OpenMesh/Core/IO/SR_store.hh>
|
#include <OpenMesh/Core/IO/SR_store.hh>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
//== NAMESPACES ===============================================================
|
//== NAMESPACES ===============================================================
|
||||||
@@ -149,8 +150,9 @@ public:
|
|||||||
|
|
||||||
virtual size_t store( std::ostream& _ostr, bool _swap ) const override
|
virtual size_t store( std::ostream& _ostr, bool _swap ) const override
|
||||||
{
|
{
|
||||||
if ( IO::is_streamable<vector_type>() )
|
if (IO::is_streamable<vector_type>() && element_size() != IO::UnknownSize)
|
||||||
return IO::store(_ostr, data_, _swap );
|
return IO::store(_ostr, data_, _swap, false); //does not need to store its length
|
||||||
|
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
for (size_t i=0; i<n_elements(); ++i)
|
for (size_t i=0; i<n_elements(); ++i)
|
||||||
bytes += IO::store( _ostr, data_[i], _swap);
|
bytes += IO::store( _ostr, data_[i], _swap);
|
||||||
@@ -159,8 +161,9 @@ public:
|
|||||||
|
|
||||||
virtual size_t restore( std::istream& _istr, bool _swap ) override
|
virtual size_t restore( std::istream& _istr, bool _swap ) override
|
||||||
{
|
{
|
||||||
if ( IO::is_streamable<vector_type>() )
|
if ( IO::is_streamable<vector_type>() && element_size() != IO::UnknownSize )
|
||||||
return IO::restore(_istr, data_, _swap );
|
return IO::restore(_istr, data_, _swap, false); //does not need to restore its length
|
||||||
|
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
for (size_t i=0; i<n_elements(); ++i)
|
for (size_t i=0; i<n_elements(); ++i)
|
||||||
bytes += IO::restore( _istr, data_[i], _swap);
|
bytes += IO::restore( _istr, data_[i], _swap);
|
||||||
|
|||||||
Reference in New Issue
Block a user