summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/BasicStream.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-01-23 19:18:58 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-01-23 19:18:58 +0000
commitf69bff7f5bb817f972bed3e10ef1b3dd1090ba89 (patch)
tree3f95137dca7ad041a45bccb6604e73e0377f2bb8 /cpp/src/Ice/BasicStream.cpp
parentMerged project files from R3_0_branch (diff)
downloadice-f69bff7f5bb817f972bed3e10ef1b3dd1090ba89.tar.bz2
ice-f69bff7f5bb817f972bed3e10ef1b3dd1090ba89.tar.xz
ice-f69bff7f5bb817f972bed3e10ef1b3dd1090ba89.zip
Changes to support "cpp:array" in IceE (and eventually Ice).
Diffstat (limited to 'cpp/src/Ice/BasicStream.cpp')
-rw-r--r--cpp/src/Ice/BasicStream.cpp96
1 files changed, 58 insertions, 38 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 11a265767ba..69da348ba6e 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -705,32 +705,33 @@ IceInternal::BasicStream::readBlob(Ice::Byte* v, Container::size_type sz)
}
void
-IceInternal::BasicStream::write(const vector<Byte>& v)
+IceInternal::BasicStream::write(const Byte* begin, const Byte* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz);
- memcpy(&b[pos], &v[0], sz);
+ memcpy(&b[pos], begin, sz);
}
}
void
-IceInternal::BasicStream::read(vector<Byte>& v)
+IceInternal::BasicStream::read(pair<const Byte*, const Byte*>& v)
{
Int sz;
readSize(sz);
if(sz > 0)
{
- checkFixedSeq(sz, 1);
- vector<Byte>(i, i + sz).swap(v);
- i += sz;
+ checkFixedSeq(sz, 1);
+ v.first = i;
+ v.second = i + sz;
+ i += sz;
}
else
{
- v.clear();
+ v.first = v.second = i;
}
}
@@ -748,20 +749,40 @@ IceInternal::BasicStream::write(const vector<bool>& v)
}
void
+IceInternal::BasicStream::write(const bool* begin, const bool* end)
+{
+ Int sz = end - begin;
+ 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
+ }
+}
+
+void
IceInternal::BasicStream::read(vector<bool>& v)
{
Int sz;
readSize(sz);
if(sz > 0)
{
- checkFixedSeq(sz, 1);
- v.resize(sz);
- copy(i, i + sz, v.begin());
- i += sz;
+ checkFixedSeq(sz, 1);
+ v.resize(sz);
+ copy(i, i + sz, v.begin());
+ i += sz;
}
else
{
- v.clear();
+ v.clear();
}
}
@@ -783,16 +804,16 @@ IceInternal::BasicStream::write(Short v)
}
void
-IceInternal::BasicStream::write(const vector<Short>& v)
+IceInternal::BasicStream::write(const Short* begin, const Short* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz * sizeof(Short));
#ifdef ICE_BIG_ENDIAN
- const Byte* src = reinterpret_cast<const Byte*>(&v[0]) + sizeof(Short) - 1;
+ const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Short) - 1;
Byte* dest = &(*(b.begin() + pos));
for(int j = 0 ; j < sz ; ++j)
{
@@ -801,7 +822,7 @@ IceInternal::BasicStream::write(const vector<Short>& v)
src += 2 * sizeof(Short);
}
#else
- memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Short));
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Short));
#endif
}
}
@@ -878,16 +899,16 @@ IceInternal::BasicStream::write(Int v)
}
void
-IceInternal::BasicStream::write(const vector<Int>& v)
+IceInternal::BasicStream::write(const Int* begin, const Int* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz * sizeof(Int));
#ifdef ICE_BIG_ENDIAN
- const Byte* src = reinterpret_cast<const Byte*>(&v[0]) + sizeof(Int) - 1;
+ const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Int) - 1;
Byte* dest = &(*(b.begin() + pos));
for(int j = 0 ; j < sz ; ++j)
{
@@ -898,7 +919,7 @@ IceInternal::BasicStream::write(const vector<Int>& v)
src += 2 * sizeof(Int);
}
#else
- memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Int));
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Int));
#endif
}
}
@@ -989,16 +1010,16 @@ IceInternal::BasicStream::write(Long v)
}
void
-IceInternal::BasicStream::write(const vector<Long>& v)
+IceInternal::BasicStream::write(const Long* begin, const Long* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz * sizeof(Long));
#ifdef ICE_BIG_ENDIAN
- const Byte* src = reinterpret_cast<const Byte*>(&v[0]) + sizeof(Long) - 1;
+ const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Long) - 1;
Byte* dest = &(*(b.begin() + pos));
for(int j = 0 ; j < sz ; ++j)
{
@@ -1013,7 +1034,7 @@ IceInternal::BasicStream::write(const vector<Long>& v)
src += 2 * sizeof(Long);
}
#else
- memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Long));
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Long));
#endif
}
}
@@ -1108,16 +1129,16 @@ IceInternal::BasicStream::write(Float v)
}
void
-IceInternal::BasicStream::write(const vector<Float>& v)
+IceInternal::BasicStream::write(const Float* begin, const Float* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz * sizeof(Float));
#ifdef ICE_BIG_ENDIAN
- const Byte* src = reinterpret_cast<const Byte*>(&v[0]) + sizeof(Float) - 1;
+ const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Float) - 1;
Byte* dest = &(*(b.begin() + pos));
for(int j = 0 ; j < sz ; ++j)
{
@@ -1128,7 +1149,7 @@ IceInternal::BasicStream::write(const vector<Float>& v)
src += 2 * sizeof(Float);
}
#else
- memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Float));
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Float));
#endif
}
}
@@ -1219,16 +1240,16 @@ IceInternal::BasicStream::write(Double v)
}
void
-IceInternal::BasicStream::write(const vector<Double>& v)
+IceInternal::BasicStream::write(const Double* begin, const Double* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz * sizeof(Double));
#ifdef ICE_BIG_ENDIAN
- const Byte* src = reinterpret_cast<const Byte*>(&v[0]) + sizeof(Double) - 1;
+ const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Double) - 1;
Byte* dest = &(*(b.begin() + pos));
for(int j = 0 ; j < sz ; ++j)
{
@@ -1243,7 +1264,7 @@ IceInternal::BasicStream::write(const vector<Double>& v)
src += 2 * sizeof(Double);
}
#else
- memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Double));
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Double));
#endif
}
}
@@ -1344,16 +1365,15 @@ IceInternal::BasicStream::write(const string& v)
}
void
-IceInternal::BasicStream::write(const vector<string>& v)
+IceInternal::BasicStream::write(const string* begin, const string* end)
{
- Int sz = static_cast<Int>(v.size());
+ Int sz = end - begin;
writeSize(sz);
if(sz > 0)
{
- vector<string>::const_iterator p;
- for(p = v.begin(); p != v.end(); ++p)
+ for(int i = 0; i < sz; ++i)
{
- write(*p);
+ write(begin[i]);
}
}
}