- added mix
- redesigned multi buffer
This commit is contained in:
+35
-4
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user