summaryrefslogtreecommitdiff
path: root/cppe/src/IceE/Buffer.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
committerDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
commit9b8cc712d4a41d71840416776bc94ee8485bb9b3 (patch)
tree7d467fdd6a66bc2b5878d82070d45adbd5c20414 /cppe/src/IceE/Buffer.cpp
parentcleaning the cache method out of ReferenceFactory (diff)
downloadice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.bz2
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.xz
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.zip
Changed Ice to IceE EVERYWHERE!!!
Diffstat (limited to 'cppe/src/IceE/Buffer.cpp')
-rw-r--r--cppe/src/IceE/Buffer.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/cppe/src/IceE/Buffer.cpp b/cppe/src/IceE/Buffer.cpp
new file mode 100644
index 00000000000..eecb757b1a9
--- /dev/null
+++ b/cppe/src/IceE/Buffer.cpp
@@ -0,0 +1,118 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICEE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceE/Buffer.h>
+#include <IceE/LocalException.h>
+
+using namespace std;
+using namespace IceE;
+using namespace IceEInternal;
+
+void
+IceEInternal::Buffer::swap(Buffer& other)
+{
+#ifdef ICEE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
+ Container::difference_type pos = i - b.begin();
+ Container::difference_type otherPos = other.i - other.b.begin();
+ b.swap(other.b);
+ i = b.begin() + otherPos;
+ other.i = other.b.begin() + pos;
+#else
+ b.swap(other.b);
+ std::swap(i, other.i);
+#endif
+}
+
+void
+IceEInternal::Buffer::Container::swap(Container& other)
+{
+#ifdef ICEE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
+ if(_buf == _fixed)
+ {
+ if(other._buf == other._fixed)
+ {
+ value_type tmp[_fixedSize];
+ memcpy(tmp, _fixed, _size);
+ memcpy(_fixed, other._fixed, other._size);
+ memcpy(other._fixed, tmp, _size);
+ }
+ else
+ {
+ _buf = other._buf;
+ memcpy(other._fixed, _fixed, _size);
+ other._buf = other._fixed;
+ }
+ }
+ else
+ {
+ if(other._buf == other._fixed)
+ {
+ other._buf = _buf;
+ memcpy(_fixed, other._fixed, other._size);
+ _buf = _fixed;
+ }
+ else
+ {
+ std::swap(_buf, other._buf);
+ }
+ }
+#else
+ std::swap(_buf, other._buf);
+#endif
+
+ std::swap(_size, other._size);
+ std::swap(_capacity, other._capacity);
+}
+
+void
+IceEInternal::Buffer::Container::resize(size_type n)
+{
+ if(n == 0)
+ {
+ clear();
+ }
+ else
+ {
+ if(n > _capacity)
+ {
+ _capacity = std::max<size_type>(n, 2 * _capacity);
+ _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity);
+
+#ifdef ICEE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
+ if(_buf != _fixed)
+ {
+ _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity));
+ }
+ else
+ {
+ _buf = reinterpret_cast<pointer>(malloc(_capacity));
+ memcpy(_buf, _fixed, _size);
+ }
+#else
+ if(_buf)
+ {
+ _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity));
+ }
+ else
+ {
+ _buf = reinterpret_cast<pointer>(malloc(_capacity));
+ }
+#endif
+
+ if(!_buf)
+ {
+ SyscallException ex(__FILE__, __LINE__);
+ ex.error = getSystemErrno();
+ throw ex;
+ }
+ }
+
+ _size = n;
+ }
+}