From e10566779ec14e290fe2937447dc17828f252ce5 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sun, 29 Apr 2012 02:37:54 +0000 Subject: [PATCH] renamed FIFOBuffer => BasicFIFOBufer, FIFOBuffer typedef, renamed Bufer::allocated() => Buffer:capacity() to match STL convention --- Foundation/include/Poco/Buffer.h | 24 ++++++++++++------------ Foundation/include/Poco/FIFOBuffer.h | 20 ++++++++++++++------ Foundation/testsuite/src/CoreTest.cpp | 13 +++++++------ 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Foundation/include/Poco/Buffer.h b/Foundation/include/Poco/Buffer.h index b80c110e3..e2d9e4a69 100644 --- a/Foundation/include/Poco/Buffer.h +++ b/Foundation/include/Poco/Buffer.h @@ -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; }; diff --git a/Foundation/include/Poco/FIFOBuffer.h b/Foundation/include/Poco/FIFOBuffer.h index 4f057722e..8784c191f 100644 --- a/Foundation/include/Poco/FIFOBuffer.h +++ b/Foundation/include/Poco/FIFOBuffer.h @@ -52,7 +52,7 @@ namespace Poco { template -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 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 _buffer; std::size_t _begin; @@ -265,6 +267,12 @@ private: }; +// +// We provide an instantiation for char +// +typedef BasicFIFOBuffer FIFOBuffer; + + } // namespace Poco diff --git a/Foundation/testsuite/src/CoreTest.cpp b/Foundation/testsuite/src/CoreTest.cpp index f62081330..346da2f51 100644 --- a/Foundation/testsuite/src/CoreTest.cpp +++ b/Foundation/testsuite/src/CoreTest.cpp @@ -57,6 +57,7 @@ using Poco::Environment; using Poco::Thread; using Poco::Runnable; using Poco::Buffer; +using Poco::BasicFIFOBuffer; using Poco::FIFOBuffer; using Poco::AtomicCounter; using Poco::Nullable; @@ -198,7 +199,7 @@ void CoreTest::testBuffer() std::size_t s = 10; Buffer b(s); assert (b.size() == s); - assert (b.allocated() == s); + assert (b.capacity() == s); std::vector v; for (int i = 0; i < s; ++i) v.push_back(i); @@ -214,7 +215,7 @@ void CoreTest::testBuffer() assert (b[i] == i); assert (b.size() == s/2); - assert (b.allocated() == s); + assert (b.capacity() == s); b.resize(s*2); v.clear(); @@ -227,7 +228,7 @@ void CoreTest::testBuffer() assert (b[i] == i); assert (b.size() == s*2); - assert (b.allocated() == s*2); + assert (b.capacity() == s*2); #if ENABLE_BUGCHECK_TEST try { int i = b[s]; fail ("must fail"); } @@ -238,9 +239,9 @@ void CoreTest::testBuffer() void CoreTest::testFIFOBufferChar() { - typedef char T; + typedef FIFOBuffer::Type T; - FIFOBuffer f(20, true); + FIFOBuffer f(20, true); Buffer b(10); std::vector v; @@ -414,7 +415,7 @@ void CoreTest::testFIFOBufferInt() { typedef char T; - FIFOBuffer f(20); + BasicFIFOBuffer f(20); Buffer b(10); std::vector v;