Make next() use call to begin() instead of _buffer.begin()

This commit is contained in:
Jonathan S
2015-02-24 22:07:28 -05:00
parent 1bbeb9ebd3
commit 3173bddd99

View File

@@ -284,7 +284,7 @@ public:
std::size_t available() const std::size_t available() const
/// Returns the size of the available portion of the buffer. /// Returns the size of the available portion of the buffer.
{ {
return _buffer.size() - _used; return size() - _used;
} }
void drain(std::size_t length = 0) void drain(std::size_t length = 0)
@@ -361,6 +361,9 @@ public:
Mutex::ScopedLock lock(_mutex); Mutex::ScopedLock lock(_mutex);
if (_begin != 0) if (_begin != 0)
{ {
// Move the data to the start of the buffer so begin() and next()
// always return consistent pointers with each other and allow writing
// to the end of the buffer.
std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T)); std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T));
_begin = 0; _begin = 0;
} }
@@ -371,16 +374,7 @@ public:
/// Returns the pointer to the next available position in the buffer. /// Returns the pointer to the next available position in the buffer.
{ {
Mutex::ScopedLock lock(_mutex); Mutex::ScopedLock lock(_mutex);
if (available() == 0) return begin() + _used;
throw InvalidAccessException("Buffer is full.");
if (_begin != 0)
{
std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T));
_begin = 0;
}
return _buffer.begin() + _used;
} }
T& operator [] (std::size_t index) T& operator [] (std::size_t index)