diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-03-02 01:56:54 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-03-02 01:56:54 +0000 |
commit | 808c24f0bc4a56e9ea801f6c31ed4f48fd9c5be9 (patch) | |
tree | b6421e3c977490e7ce8e9bd80548da7257774518 /cpp/src | |
parent | Minor edit (diff) | |
download | ice-808c24f0bc4a56e9ea801f6c31ed4f48fd9c5be9.tar.bz2 ice-808c24f0bc4a56e9ea801f6c31ed4f48fd9c5be9.tar.xz ice-808c24f0bc4a56e9ea801f6c31ed4f48fd9c5be9.zip |
fixed custom marshaling with apple.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 1db2a1c2ac2..a10f1336d79 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -723,6 +723,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) { @@ -732,14 +758,7 @@ IceInternal::BasicStream::write(const bool* begin, const bool* end) { 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 + BasicStreamWriteBoolHelper<sizeof(bool)>::write(begin, pos, b, sz); } } @@ -761,28 +780,48 @@ IceInternal::BasicStream::read(vector<bool>& v) } } -void -IceInternal::BasicStream::read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b) +namespace { - Int sz; - readSize(sz); - if(sz > 0) + +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) { - checkFixedSeq(sz, 1); -#if defined(__APPLE__) bool* array = new bool[sz]; - for(int idx; idx < sz; ++idx) + for(int idx = 0; idx < sz; ++idx) { - array[idx] = (bool)*(i + idx); + array[idx] = static_cast<bool>(*(i + idx)); } v.first = array; v.second = array + sz; b.reset(array); -#else - assert(sizeof(bool) == 1); + } +}; + +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; -#endif + } +}; + +} + +void +IceInternal::BasicStream::read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b) +{ + Int sz; + readSize(sz); + if(sz > 0) + { + checkFixedSeq(sz, 1); + BasicStreamReadBoolHelper<sizeof(bool)>::read(v, b, sz, i); i += sz; } else |