- added mix

- redesigned multi buffer
This commit is contained in:
2025-11-06 22:16:59 +01:00
parent bc013ff352
commit 8310d46176
7 changed files with 285 additions and 25 deletions
+35 -4
View File
@@ -49,7 +49,7 @@ class Buffer
std::vector<T> &m_buffer;
public:
Buffer(size_t capacity)
Buffer(size_t capacity=1)
: m_index(0)
, m_mask(0)
, m_offset(0)
@@ -59,7 +59,6 @@ class Buffer
, m_allocated_capacity(1)
{
resize(capacity);
m_buffer.assign(m_allocated_capacity, T());
}
Buffer(const Buffer<T> &buffer, int offset=0, uint increment=1)
@@ -82,7 +81,7 @@ class Buffer
, m_buffer(*new std::vector<T>(v))
, m_allocated_capacity(1)
{
resize(v.size());
resize(v.size(), false);
}
size_t capacity() const
@@ -95,13 +94,18 @@ class Buffer
m_index = 0;
}
void resize(uint capacity)
void resize(uint capacity, bool doAssign=true)
{
m_allocated_capacity = 1;
while (m_allocated_capacity < capacity)
{
m_allocated_capacity *= 2;
}
if (doAssign)
{
m_buffer.assign(m_allocated_capacity, T());
}
m_capacity = capacity;
m_mask = unsigned(m_allocated_capacity - 1);
@@ -163,6 +167,33 @@ class Buffer
return true;
}
Buffer& operator = (const std::initializer_list<T> &v)
{
if (v.size() > m_allocated_capacity)
{
resize(v.size());
}
int i=0;
for (auto v_: v)
{
(*this)[i++] = v_;
}
return *this;
}
Buffer& operator = (const Buffer<T> &other)
{
m_buffer = other.m_buffer;
m_index = other.m_index;
m_mask = other.m_mask;
m_offset = other.m_offset;
m_increment = other.m_increment;
m_capacity = other.m_capacity;
m_allocated_capacity = other.m_allocated_capacity;
return *this;
}
protected: