renamed FIFOBuffer => BasicFIFOBufer, FIFOBuffer typedef, renamed Bufer::allocated() => Buffer:capacity() to match STL convention

This commit is contained in:
Aleksandar Fabijanic
2012-04-29 02:37:54 +00:00
parent d22ecbaa3e
commit e10566779e
3 changed files with 33 additions and 24 deletions

View File

@@ -59,7 +59,7 @@ class Buffer
{
public:
Buffer(std::size_t size):
_size(size),
_capacity(size),
_used(size),
_ptr(new T[size])
/// Creates and allocates the Buffer.
@@ -72,32 +72,32 @@ public:
delete [] _ptr;
}
void resize(std::size_t newSize, bool preserveContent = true)
void resize(std::size_t newCapacity, bool preserveContent = true)
/// Resizes the buffer. If preserveContent is true,
/// the content of the old buffer is copied over to the
/// new buffer. NewSize can be larger or smaller than
/// the current size, but it must not be 0.
{
poco_assert(newSize);
poco_assert(newCapacity);
if (newSize > _size)
if (newCapacity > _capacity)
{
T* ptr = new T[newSize];
T* ptr = new T[newCapacity];
if (preserveContent)
std::memcpy(ptr, _ptr, newSize);
std::memcpy(ptr, _ptr, newCapacity);
delete [] _ptr;
_ptr = ptr;
_size = newSize;
_capacity = newCapacity;
}
_used = newSize;
_used = newCapacity;
}
std::size_t allocated() const
std::size_t capacity() const
/// Returns the allocated memory size.
{
return _size;
return _capacity;
}
std::size_t size() const
@@ -149,9 +149,9 @@ private:
Buffer(const Buffer&);
Buffer& operator = (const Buffer&);
std::size_t _size;
std::size_t _capacity;
std::size_t _used;
T* _ptr;
T* _ptr;
};

View File

@@ -52,7 +52,7 @@ namespace Poco {
template <class T>
class FIFOBuffer
class BasicFIFOBuffer
/// A simple buffer class with support for re-entrant,
/// FIFO-style read/write operations. as well as
/// empty/full transition notifications. Buffer size
@@ -63,6 +63,8 @@ class FIFOBuffer
/// is needed.
{
public:
typedef T Type;
mutable Poco::BasicEvent<bool> Writable;
/// Event indicating "writeability" of the buffer,
/// triggerred as follows:
@@ -87,7 +89,7 @@ public:
/// Readable event observers are notified, with true value
/// as the argument
FIFOBuffer(std::size_t size, bool notify = false):
BasicFIFOBuffer(std::size_t size, bool notify = false):
_buffer(size),
_begin(0),
_used(0),
@@ -96,7 +98,7 @@ public:
{
}
~FIFOBuffer()
~BasicFIFOBuffer()
/// Destroys the FIFOBuffer.
{
}
@@ -253,9 +255,9 @@ private:
Writable.notify(this, f);
}
FIFOBuffer();
FIFOBuffer(const FIFOBuffer&);
FIFOBuffer& operator = (const FIFOBuffer&);
BasicFIFOBuffer();
BasicFIFOBuffer(const BasicFIFOBuffer&);
BasicFIFOBuffer& operator = (const BasicFIFOBuffer&);
Buffer<T> _buffer;
std::size_t _begin;
@@ -265,6 +267,12 @@ private:
};
//
// We provide an instantiation for char
//
typedef BasicFIFOBuffer<char> FIFOBuffer;
} // namespace Poco