summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io/data_buffer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-25 23:46:59 +0800
committerchai <chaifix@163.com>2019-03-25 23:46:59 +0800
commit03b3b8ae80559745f98ef94569b421adddeb441f (patch)
tree7bf46892fef7453d4c25172333bd4fbddb29ee16 /source/libs/asura-lib-utils/io/data_buffer.cpp
parent82956beb1fe17e1226327638c8ab22b5f5adfc1d (diff)
*misc
Diffstat (limited to 'source/libs/asura-lib-utils/io/data_buffer.cpp')
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp
new file mode 100644
index 0000000..98675e9
--- /dev/null
+++ b/source/libs/asura-lib-utils/io/data_buffer.cpp
@@ -0,0 +1,77 @@
+#include <cstdlib>
+#include <cstring>
+#include "data_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace IO
+ {
+
+ DataBuffer::DataBuffer(DataBuffer& src)
+ {
+ Load(src);
+ }
+
+ DataBuffer::DataBuffer(std::size_t size)
+ : mSize(size)
+ , mBytes(nullptr)
+ {
+ mBytes = new byte[size];
+ memset(mBytes, 0, size);
+ }
+
+ DataBuffer::DataBuffer(const void* data, std::size_t size)
+ : mSize(size)
+ , mBytes(nullptr)
+ {
+ Load(data, size);
+ }
+
+ DataBuffer::~DataBuffer()
+ {
+ delete[] mBytes;
+ }
+
+ void DataBuffer::Load(DataBuffer& db)
+ {
+ Load(db.GetData(), db.GetSize());
+ }
+
+ void DataBuffer::Load(const void* data, std::size_t size)
+ {
+ if (!mBytes || mSize != size)
+ {
+ delete[] mBytes;
+ mBytes = new byte[size];
+ }
+ memcpy(mBytes, data, size);
+ }
+
+ void DataBuffer::Move(void* bytes, std::size_t size)
+ {
+ if (!mBytes)
+ {
+ delete[] mBytes;
+ }
+ mBytes = (byte*)bytes;
+ mSize = size;
+ }
+
+ byte* DataBuffer::GetData()
+ {
+ return mBytes;
+ }
+
+ void DataBuffer::Clear()
+ {
+ if (mBytes)
+ memset(mBytes, 0, mSize);
+ }
+
+ std::size_t DataBuffer::GetSize()
+ {
+ return mSize;
+ }
+
+ }
+} \ No newline at end of file