From 25c8229629e582a98a1c6f55c15e57b53af54248 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 25 Dec 2010 02:11:22 +0000 Subject: Remove useless templatification of RingBuffer. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2783 a436a847-0d15-0410-975c-d299462d15a1 --- raul/EventRingBuffer.hpp | 16 ++++++++-------- raul/RingBuffer.hpp | 45 +++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/raul/EventRingBuffer.hpp b/raul/EventRingBuffer.hpp index 418d2af..54e34f7 100644 --- a/raul/EventRingBuffer.hpp +++ b/raul/EventRingBuffer.hpp @@ -31,13 +31,13 @@ namespace Raul { * This packs a timestamp, size, and size bytes of data flat into the buffer. * Useful for MIDI events, OSC messages, etc. */ -class EventRingBuffer : private Raul::RingBuffer { +class EventRingBuffer : private Raul::RingBuffer { public: /** @param capacity Ringbuffer capacity in bytes. */ explicit EventRingBuffer(size_t capacity) - : RingBuffer(capacity) + : RingBuffer(capacity) {} size_t capacity() const { return _size; } @@ -50,11 +50,11 @@ public: inline bool EventRingBuffer::read(TimeStamp* time, size_t* size, uint8_t* buf) { - bool success = RingBuffer::full_read(sizeof(TimeStamp), (uint8_t*)time); + bool success = RingBuffer::full_read(sizeof(TimeStamp), (uint8_t*)time); if (success) - success = RingBuffer::full_read(sizeof(size_t), (uint8_t*)size); + success = RingBuffer::full_read(sizeof(size_t), (uint8_t*)size); if (success) - success = RingBuffer::full_read(*size, buf); + success = RingBuffer::full_read(*size, buf); return success; } @@ -68,9 +68,9 @@ EventRingBuffer::write(TimeStamp time, size_t size, const uint8_t* buf) if (write_space() < (sizeof(TimeStamp) + sizeof(size_t) + size)) { return 0; } else { - RingBuffer::write(sizeof(TimeStamp), (uint8_t*)&time); - RingBuffer::write(sizeof(size_t), (uint8_t*)&size); - RingBuffer::write(size, buf); + RingBuffer::write(sizeof(TimeStamp), (uint8_t*)&time); + RingBuffer::write(sizeof(size_t), (uint8_t*)&size); + RingBuffer::write(size, buf); return size; } } diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp index 31ab222..c0f00ed 100644 --- a/raul/RingBuffer.hpp +++ b/raul/RingBuffer.hpp @@ -32,7 +32,6 @@ namespace Raul { * Read/Write realtime safe. * Single-reader Single-writer thread safe. */ -template class RingBuffer { public: /** @param size Size in bytes. @@ -84,15 +83,15 @@ public: size_t capacity() const { return _size; } - size_t peek(size_t size, T* dst); - bool full_peek(size_t size, T* dst); + size_t peek(size_t size, void* dst); + bool full_peek(size_t size, void* dst); - size_t read(size_t size, T* dst); - bool full_read(size_t size, T* dst); + size_t read(size_t size, void* dst); + bool full_read(size_t size, void* dst); bool skip(size_t size); - void write(size_t size, const T* src); + void write(size_t size, const void* src); protected: mutable int _write_ptr; @@ -109,9 +108,8 @@ protected: * Caller must check return value and call again if necessary, or use the * full_peek method which does this automatically. */ -template -size_t -RingBuffer::peek(size_t size, T* dst) +inline size_t +RingBuffer::peek(size_t size, void* dst) { const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr); @@ -125,9 +123,8 @@ RingBuffer::peek(size_t size, T* dst) } -template -bool -RingBuffer::full_peek(size_t size, T* dst) +inline bool +RingBuffer::full_peek(size_t size, void* dst) { if (read_space() < size) { return false; @@ -136,7 +133,7 @@ RingBuffer::full_peek(size_t size, T* dst) const size_t read_size = peek(size, dst); if (read_size < size) { - peek(size - read_size, dst + read_size); + peek(size - read_size, (char*)dst + read_size); } return true; @@ -149,9 +146,8 @@ RingBuffer::full_peek(size_t size, T* dst) * Caller must check return value and call again if necessary, or use the * full_read method which does this automatically. */ -template -size_t -RingBuffer::read(size_t size, T* dst) +inline size_t +RingBuffer::read(size_t size, void* dst) { const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr); @@ -167,9 +163,8 @@ RingBuffer::read(size_t size, T* dst) } -template -bool -RingBuffer::full_read(size_t size, T* dst) +inline bool +RingBuffer::full_read(size_t size, void* dst) { if (read_space() < size) { return false; @@ -178,16 +173,15 @@ RingBuffer::full_read(size_t size, T* dst) const size_t read_size = read(size, dst); if (read_size < size) { - read(size - read_size, dst + read_size); + read(size - read_size, (char*)dst + read_size); } return true; } -template -bool -RingBuffer::skip(size_t size) +inline bool +RingBuffer::skip(size_t size) { if (read_space() < size) { warn << "Attempt to skip past end of RingBuffer" << std::endl; @@ -201,9 +195,8 @@ RingBuffer::skip(size_t size) } -template inline void -RingBuffer::write(size_t size, const T* src) +RingBuffer::write(size_t size, const void* src) { const size_t priv_write_ptr = g_atomic_int_get(&_write_ptr); @@ -215,7 +208,7 @@ RingBuffer::write(size_t size, const T* src) assert(this_size < size); assert(priv_write_ptr + this_size <= _size); memcpy(&_buf[priv_write_ptr], src, this_size); - memcpy(&_buf[0], src+this_size, size - this_size); + memcpy(&_buf[0], (char*)src + this_size, size - this_size); g_atomic_int_set(&_write_ptr, size - this_size); } } -- cgit v1.2.1