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:
Alexandra Heuschling
2021-02-26 19:04:20 +01:00
parent cf45a5d3cc
commit 5c0066b490
2 changed files with 25 additions and 6 deletions

View File

@@ -89,18 +89,34 @@ template <typename T> inline
size_t size_of( const T& _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
size_t size_of(void)
{ 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
size_t store( std::ostream& _os, const T& _v, bool _swap=false)
{ 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
size_t restore( std::istream& _is, T& _v, bool _swap=false)
{ 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); }
//@}

View File

@@ -56,6 +56,7 @@
#include <algorithm>
#include <OpenMesh/Core/IO/SR_store.hh>
#include <iostream>
//== NAMESPACES ===============================================================
@@ -149,8 +150,9 @@ public:
virtual size_t store( std::ostream& _ostr, bool _swap ) const override
{
if ( IO::is_streamable<vector_type>() )
return IO::store(_ostr, data_, _swap );
if (IO::is_streamable<vector_type>() && element_size() != IO::UnknownSize)
return IO::store(_ostr, data_, _swap, false); //does not need to store its length
size_t bytes = 0;
for (size_t i=0; i<n_elements(); ++i)
bytes += IO::store( _ostr, data_[i], _swap);
@@ -159,8 +161,9 @@ public:
virtual size_t restore( std::istream& _istr, bool _swap ) override
{
if ( IO::is_streamable<vector_type>() )
return IO::restore(_istr, data_, _swap );
if ( IO::is_streamable<vector_type>() && element_size() != IO::UnknownSize )
return IO::restore(_istr, data_, _swap, false); //does not need to restore its length
size_t bytes = 0;
for (size_t i=0; i<n_elements(); ++i)
bytes += IO::restore( _istr, data_[i], _swap);