added Buffer append()
This commit is contained in:
Родитель
c41196bd5b
Коммит
11539da851
|
@ -116,6 +116,22 @@ public:
|
|||
_used = newCapacity;
|
||||
}
|
||||
|
||||
void append(const T* buf, std::size_t sz)
|
||||
/// Resizes this buffer and appends the argument buffer.
|
||||
{
|
||||
if (0 == sz)
|
||||
return;
|
||||
std::size_t oldSize = _used;
|
||||
resize(_used + sz, true);
|
||||
std::memcpy(_ptr + oldSize, buf, sz);
|
||||
}
|
||||
|
||||
void append(const Buffer& buf)
|
||||
/// Resizes this buffer and appends the argument buffer.
|
||||
{
|
||||
append(buf.begin(), buf.size());
|
||||
}
|
||||
|
||||
std::size_t capacity() const
|
||||
/// Returns the allocated memory size.
|
||||
{
|
||||
|
|
|
@ -251,6 +251,14 @@ void CoreTest::testBuffer()
|
|||
|
||||
Buffer<int> f = e;
|
||||
assert (f == e);
|
||||
|
||||
buffer<char> g;
|
||||
g.append("hello", 5);
|
||||
assert (g.size() == 5);
|
||||
|
||||
g.append(g);
|
||||
assert (g.size() == 10);
|
||||
assert ( !memcmp(g.begin(), "hellohello", 10) );
|
||||
}
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче