From 06d770d1b4ac804f84803cde9d34e66b10658516 Mon Sep 17 00:00:00 2001 From: Alexandra Heuschling Date: Mon, 15 Mar 2021 01:50:35 +0100 Subject: [PATCH] add support for properties of std::vector... --- .../Core/IO/SR_binary_vector_of_bool.inl | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/OpenMesh/Core/IO/SR_binary_vector_of_bool.inl b/src/OpenMesh/Core/IO/SR_binary_vector_of_bool.inl index 8362cd93..3c9b1143 100644 --- a/src/OpenMesh/Core/IO/SR_binary_vector_of_bool.inl +++ b/src/OpenMesh/Core/IO/SR_binary_vector_of_bool.inl @@ -1,7 +1,6 @@ template <> struct binary< std::vector > { - typedef std::vector< bool > value_type; typedef value_type::value_type elem_type; @@ -10,86 +9,95 @@ template <> struct binary< std::vector > static size_t size_of(bool _store_size = true) { return UnknownSize; } static size_t size_of(const value_type& _v, bool _store_size = true) { - return _v.size() / 8 + ((_v.size() % 8)!=0); + size_t size = _v.size() / 8 + ((_v.size() % 8)!=0); + if(_store_size) + size += binary::size_of(); + return size; } static std::string string_for_value_type(void) { return get_string_for_type(value_type()); } static - size_t store( std::ostream& _ostr, const value_type& _v, bool, bool _store_size = true ) + size_t store( std::ostream& _ostr, const value_type& _v, bool _swap, bool _store_size = true) { size_t bytes = 0; size_t N = _v.size() / 8; size_t R = _v.size() % 8; - size_t idx; // element index + if(_store_size) + { + unsigned int size_N = _v.size(); + bytes += binary::store( _ostr, size_N, _swap ); + } + + size_t idx; // element index + size_t bidx; unsigned char bits; // bitset - for (idx=0; idx < N; ++idx) + for (bidx=idx=0; idx < N; ++idx, bidx+=8) { - bits = static_cast(_v[idx]) - | (static_cast(_v[idx+1]) << 1) - | (static_cast(_v[idx+2]) << 2) - | (static_cast(_v[idx+3]) << 3) - | (static_cast(_v[idx+4]) << 4) - | (static_cast(_v[idx+5]) << 5) - | (static_cast(_v[idx+6]) << 6) - | (static_cast(_v[idx+7]) << 7); + bits = static_cast(_v[bidx]) + | (static_cast(_v[bidx+1]) << 1) + | (static_cast(_v[bidx+2]) << 2) + | (static_cast(_v[bidx+3]) << 3) + | (static_cast(_v[bidx+4]) << 4) + | (static_cast(_v[bidx+5]) << 5) + | (static_cast(_v[bidx+6]) << 6) + | (static_cast(_v[bidx+7]) << 7); _ostr << bits; } - bytes = N; + bytes += N; if (R) { bits = 0; - switch(R) - { - case 7: bits |= (static_cast(_v[idx+6]) << 6); - case 6: bits |= (static_cast(_v[idx+5]) << 5); - case 5: bits |= (static_cast(_v[idx+4]) << 4); - case 4: bits |= (static_cast(_v[idx+3]) << 3); - case 3: bits |= (static_cast(_v[idx+2]) << 2); - case 2: bits |= (static_cast(_v[idx+1]) << 1); - case 1: bits |= static_cast(_v[idx+0]); - } + for (idx=0; idx < R; ++idx) + bits |= static_cast(_v[bidx+idx]) << idx; _ostr << bits; ++bytes; } - - assert( bytes == size_of(_v) ); + assert( bytes == size_of(_v, _store_size) ); return bytes; } static - size_t restore( std::istream& _istr, value_type& _v, bool, bool _restore_size = true ) + size_t restore( std::istream& _istr, value_type& _v, bool _swap, bool _restore_size = true) { size_t bytes = 0; + + if(_restore_size) + { + unsigned int size_of_vec; + bytes += binary::restore(_istr, size_of_vec, _swap); + _v.resize(size_of_vec); + } size_t N = _v.size() / 8; size_t R = _v.size() % 8; size_t idx; // element index + size_t bidx; // unsigned char bits; // bitset - for (idx=0; idx < N; ++idx) + for (bidx=idx=0; idx < N; ++idx, bidx+=8) { _istr >> bits; - _v[idx+0] = ((bits & 0x01)!=0); - _v[idx+1] = ((bits & 0x02)!=0); - _v[idx+2] = ((bits & 0x04)!=0); - _v[idx+3] = ((bits & 0x08)!=0); - _v[idx+4] = ((bits & 0x10)!=0); - _v[idx+5] = ((bits & 0x20)!=0); - _v[idx+6] = ((bits & 0x40)!=0); - _v[idx+7] = ((bits & 0x80)!=0); + _v[bidx+0] = (bits & 0x01) != 0; + _v[bidx+1] = (bits & 0x02) != 0; + _v[bidx+2] = (bits & 0x04) != 0; + _v[bidx+3] = (bits & 0x08) != 0; + _v[bidx+4] = (bits & 0x10) != 0; + _v[bidx+5] = (bits & 0x20) != 0; + _v[bidx+6] = (bits & 0x40) != 0; + _v[bidx+7] = (bits & 0x80) != 0; } - bytes = N; + bytes += N; if (R) { _istr >> bits; - for(; idx < _v.size(); ++idx) - _v[idx] = (bits & (1 << (idx%8)))!=0; + for (idx=0; idx < R; ++idx) + _v[bidx+idx] = (bits & (1<