mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
RingBufferHistory handles unique_ptr
This commit is contained in:
parent
9cfa422ef8
commit
fa43c62722
1 changed files with 13 additions and 1 deletions
|
@ -53,6 +53,18 @@ public:
|
|||
_numEntries++;
|
||||
}
|
||||
}
|
||||
|
||||
// std::unique_ptr need to be passed as an rvalue ref and moved into the vector
|
||||
void insert(T&& entry) {
|
||||
// increment newest entry index cyclically
|
||||
_newestEntryAtIndex = (_newestEntryAtIndex == _size - 1) ? 0 : _newestEntryAtIndex + 1;
|
||||
|
||||
// insert new entry
|
||||
_buffer[_newestEntryAtIndex] = std::move(entry);
|
||||
if (_numEntries < _capacity) {
|
||||
_numEntries++;
|
||||
}
|
||||
}
|
||||
|
||||
// 0 retrieves the most recent entry, _numEntries - 1 retrieves the oldest.
|
||||
// returns NULL if entryAge not within [0, _numEntries-1]
|
||||
|
@ -88,7 +100,7 @@ private:
|
|||
int _capacity;
|
||||
int _newestEntryAtIndex;
|
||||
int _numEntries;
|
||||
QVector<T> _buffer;
|
||||
std::vector<T> _buffer;
|
||||
|
||||
public:
|
||||
class Iterator : public std::iterator < std::random_access_iterator_tag, T > {
|
||||
|
|
Loading…
Reference in a new issue