/usr/include/IceE/Buffer.h is in libicee-dev 1.2.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | // **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice-E is licensed to you under the terms described in the
// ICEE_LICENSE file included in this distribution.
//
// **********************************************************************
#ifndef ICEE_BUFFER_H
#define ICEE_BUFFER_H
#include <IceE/Config.h>
#include <cstdlib>
#define ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
#define ICE_BUFFER_FIXED_SIZE 64
namespace IceInternal
{
class Buffer : private IceUtil::noncopyable
{
public:
Buffer(size_t maxCapacity) : b(maxCapacity), i(b.begin()) { }
virtual ~Buffer() { }
ICE_API void swap(Buffer&);
class Container : private IceUtil::noncopyable
{
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 int difference_type;
typedef size_t size_type;
#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
Container(size_type maxCapacity) :
_buf(_fixed),
_size(0),
_capacity(ICE_BUFFER_FIXED_SIZE),
_maxCapacity(maxCapacity)
{
}
#else
Container(size_type maxCapacity) :
_buf(0),
_size(0),
_capacity(0),
_maxCapacity(maxCapacity)
{
}
#endif
~Container()
{
#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
if(_buf != _fixed)
{
free(_buf);
}
#else
free(_buf);
#endif
}
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;
}
ICE_API void swap(Container&);
ICE_API 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
{
assert(n < _size);
return _buf[n];
}
private:
ICE_API Container(const Container&);
ICE_API void operator=(const Container&);
ICE_API void reserve(size_type);
pointer _buf;
size_type _size;
size_type _capacity;
size_type _maxCapacity;
int _shrinkCounter;
#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
//
// For small buffers, we stack-allocate the memory. Only when
// a buffer size larger than _fixedSize is requested, we
// allocate memory dynamically.
//
value_type _fixed[ICE_BUFFER_FIXED_SIZE];
#endif
};
Container b;
Container::iterator i;
};
}
#endif
|