|
|
@ -201,19 +201,25 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
ring_buffer() = default;
|
|
|
|
ring_buffer() = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
|
|
|
|
void construct_from(const U &other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32 cap = round_up_size((uint32)other.size());
|
|
|
|
|
|
|
|
this->data.reset(MallocT<byte>(cap * sizeof(T)));
|
|
|
|
|
|
|
|
this->mask = cap - 1;
|
|
|
|
|
|
|
|
this->head = 0;
|
|
|
|
|
|
|
|
this->count = (uint32)other.size();
|
|
|
|
|
|
|
|
byte *ptr = this->data.get();
|
|
|
|
|
|
|
|
for (const T &item : other) {
|
|
|
|
|
|
|
|
new (ptr) T(item);
|
|
|
|
|
|
|
|
ptr += sizeof(T);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ring_buffer(const ring_buffer &other)
|
|
|
|
ring_buffer(const ring_buffer &other)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!other.empty()) {
|
|
|
|
if (!other.empty()) {
|
|
|
|
uint32 cap = round_up_size(other.count);
|
|
|
|
this->construct_from(other);
|
|
|
|
this->data.reset(MallocT<byte>(cap * sizeof(T)));
|
|
|
|
|
|
|
|
this->mask = cap - 1;
|
|
|
|
|
|
|
|
this->head = 0;
|
|
|
|
|
|
|
|
this->count = other.size();
|
|
|
|
|
|
|
|
byte *ptr = this->data.get();
|
|
|
|
|
|
|
|
for (const T &item : other) {
|
|
|
|
|
|
|
|
new (ptr) T(item);
|
|
|
|
|
|
|
|
ptr += sizeof(T);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -225,6 +231,13 @@ public:
|
|
|
|
std::swap(this->mask, other.mask);
|
|
|
|
std::swap(this->mask, other.mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ring_buffer(std::initializer_list<T> init)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (init.size() > 0) {
|
|
|
|
|
|
|
|
this->construct_from(init);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ring_buffer& operator =(const ring_buffer &other)
|
|
|
|
ring_buffer& operator =(const ring_buffer &other)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (&other != this) {
|
|
|
|
if (&other != this) {
|
|
|
|