summaryrefslogtreecommitdiff
path: root/cpp/include/Ice/Buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/include/Ice/Buffer.h')
-rw-r--r--cpp/include/Ice/Buffer.h224
1 files changed, 112 insertions, 112 deletions
diff --git a/cpp/include/Ice/Buffer.h b/cpp/include/Ice/Buffer.h
index a15b9184b53..b780d84d2fa 100644
--- a/cpp/include/Ice/Buffer.h
+++ b/cpp/include/Ice/Buffer.h
@@ -28,122 +28,122 @@ public:
{
public:
- //
- // Standard vector-like operations.
- //
-
- typedef Ice::Byte value_type;
- typedef Ice::Byte* iterator;
- typedef const Ice::Byte* const_iterator;
- typedef Ice::Byte& reference;
- typedef const Ice::Byte& const_reference;
- typedef Ice::Byte* pointer;
- typedef ptrdiff_t difference_type;
- typedef size_t size_type;
-
- Container(size_type maxCapacity);
-
- ~Container();
-
- iterator begin()
- {
- return _buf;
- }
-
- const_iterator begin() const
- {
- return _buf;
- }
-
- iterator end()
- {
- return _buf + _size;
- }
-
- const_iterator end() const
- {
- return _buf + _size;
- }
-
- size_type size() const
- {
- return _size;
- }
-
- bool empty() const
- {
- return !_size;
- }
-
- void swap(Container&);
-
- void clear();
-
- void resize(size_type n) // Inlined for performance reasons.
+ //
+ // Standard vector-like operations.
+ //
+
+ typedef Ice::Byte value_type;
+ typedef Ice::Byte* iterator;
+ typedef const Ice::Byte* const_iterator;
+ typedef Ice::Byte& reference;
+ typedef const Ice::Byte& const_reference;
+ typedef Ice::Byte* pointer;
+ typedef ptrdiff_t difference_type;
+ typedef size_t size_type;
+
+ Container(size_type maxCapacity);
+
+ ~Container();
+
+ iterator begin()
+ {
+ return _buf;
+ }
+
+ const_iterator begin() const
+ {
+ return _buf;
+ }
+
+ iterator end()
+ {
+ return _buf + _size;
+ }
+
+ const_iterator end() const
+ {
+ return _buf + _size;
+ }
+
+ size_type size() const
+ {
+ return _size;
+ }
+
+ bool empty() const
+ {
+ return !_size;
+ }
+
+ void swap(Container&);
+
+ void clear();
+
+ void resize(size_type n) // Inlined for performance reasons.
+ {
+ if(n == 0)
+ {
+ clear();
+ }
+ else if(n > _capacity)
+ {
+ reserve(n);
+ }
+ _size = n;
+ }
+
+ void reset()
+ {
+ if(_size > 0 && _size * 2 < _capacity)
+ {
+ //
+ // If the current buffer size is smaller than the
+ // buffer capacity, we shrink the buffer memory to the
+ // current size. This is to avoid holding on too much
+ // memory if it's not needed anymore.
+ //
+ if(++_shrinkCounter > 2)
+ {
+ reserve(_size);
+ _shrinkCounter = 0;
+ }
+ }
+ else
+ {
+ _shrinkCounter = 0;
+ }
+ _size = 0;
+ }
+
+ void push_back(value_type v)
+ {
+ resize(_size + 1);
+ _buf[_size - 1] = v;
+ }
+
+ reference operator[](size_type n)
+ {
+ assert(n < _size);
+ return _buf[n];
+ }
+
+ const_reference operator[](size_type n) const
{
- if(n == 0)
- {
- clear();
- }
- else if(n > _capacity)
- {
- reserve(n);
- }
- _size = n;
- }
-
- void reset()
- {
- if(_size > 0 && _size * 2 < _capacity)
- {
- //
- // If the current buffer size is smaller than the
- // buffer capacity, we shrink the buffer memory to the
- // current size. This is to avoid holding on too much
- // memory if it's not needed anymore.
- //
- if(++_shrinkCounter > 2)
- {
- reserve(_size);
- _shrinkCounter = 0;
- }
- }
- else
- {
- _shrinkCounter = 0;
- }
- _size = 0;
- }
-
- void push_back(value_type v)
- {
- resize(_size + 1);
- _buf[_size - 1] = v;
- }
-
- reference operator[](size_type n)
- {
- assert(n < _size);
- return _buf[n];
- }
-
- const_reference operator[](size_type n) const
- {
- assert(n < _size);
- return _buf[n];
- }
-
+ assert(n < _size);
+ return _buf[n];
+ }
+
private:
- Container(const Container&);
- void operator=(const Container&);
- void reserve(size_type);
+ Container(const Container&);
+ void operator=(const Container&);
+ void reserve(size_type);
- pointer _buf;
- size_type _size;
- size_type _capacity;
- size_type _maxCapacity;
- int _shrinkCounter;
+ pointer _buf;
+ size_type _size;
+ size_type _capacity;
+ size_type _maxCapacity;
+ int _shrinkCounter;
};
Container b;