diff options
Diffstat (limited to 'cppe/src/IceE/BasicStream.cpp')
-rw-r--r-- | cppe/src/IceE/BasicStream.cpp | 91 |
1 files changed, 65 insertions, 26 deletions
diff --git a/cppe/src/IceE/BasicStream.cpp b/cppe/src/IceE/BasicStream.cpp index 139e7d2b731..c0347f9af7a 100644 --- a/cppe/src/IceE/BasicStream.cpp +++ b/cppe/src/IceE/BasicStream.cpp @@ -391,6 +391,32 @@ IceInternal::BasicStream::write(const vector<bool>& v) } } +namespace +{ + +template<size_t boolSize> +struct BasicStreamWriteBoolHelper +{ + static void write(const bool* begin, BasicStream::Container::size_type pos, BasicStream::Container& b, Int sz) + { + for(int idx = 0; idx < sz; ++idx) + { + b[pos + idx] = static_cast<Ice::Byte>(*(begin + idx)); + } + } +}; + +template<> +struct BasicStreamWriteBoolHelper<1> +{ + static void write(const bool* begin, BasicStream::Container::size_type pos, BasicStream::Container& b, Int sz) + { + memcpy(&b[pos], begin, sz); + } +}; + +} + void IceInternal::BasicStream::write(const bool* begin, const bool* end) { @@ -398,16 +424,9 @@ IceInternal::BasicStream::write(const bool* begin, const bool* end) writeSize(sz); if(sz > 0) { - Container::size_type pos = b.size(); - resize(pos + sz); -#if defined(__APPLE__) - for(int idx = 0; idx < sz; ++idx) - { - b[pos + idx] = static_cast<Ice::Byte>(*(begin + idx)); - } -#else - memcpy(&b[pos], begin, sz); -#endif + Container::size_type pos = b.size(); + resize(pos + sz); + BasicStreamWriteBoolHelper<sizeof(bool)>::write(begin, pos, b, sz); } } @@ -429,6 +448,39 @@ IceInternal::BasicStream::read(vector<bool>& v) } } +namespace +{ + +template<size_t boolSize> +struct BasicStreamReadBoolHelper +{ + static void read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b, + Int sz, BasicStream::Container::iterator& i) + { + bool* array = new bool[sz]; + for(int idx = 0; idx < sz; ++idx) + { + array[idx] = static_cast<bool>(*(i + idx)); + } + v.first = array; + v.second = array + sz; + b.reset(array); + } +}; + +template<> +struct BasicStreamReadBoolHelper<1> +{ + static void read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b, + Int sz, BasicStream::Container::iterator& i) + { + v.first = reinterpret_cast<bool*>(i); + v.second = reinterpret_cast<bool*>(i) + sz; + } +}; + +} + void IceInternal::BasicStream::read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b) { @@ -436,22 +488,9 @@ IceInternal::BasicStream::read(pair<const bool*, const bool*>& v, IceUtil::auto_ readSize(sz); if(sz > 0) { - checkFixedSeq(sz, 1); -#if defined(__APPLE__) - bool* array = new bool[sz]; - for(int idx = 0; idx < sz; ++idx) - { - array[idx] = (bool)*(i + idx); - } - v.first = array; - v.second = array + sz; - b.reset(array); -#else - assert(sizeof(bool) == 1); - v.first = reinterpret_cast<bool*>(i); - v.second = reinterpret_cast<bool*>(i) + sz; -#endif - i += sz; + checkFixedSeq(sz, 1); + BasicStreamReadBoolHelper<sizeof(bool)>::read(v, b, sz, i); + i += sz; } else { |