summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/asura-lib-utils/filesystem/data_buffer.cpp')
-rw-r--r--source/libs/asura-lib-utils/filesystem/data_buffer.cpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
index 629dc92..32a123f 100644
--- a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
+++ b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
@@ -1,3 +1,5 @@
+#include <cstdlib>
+#include <cstring>
#include "data_buffer.h"
namespace AsuraEngine
@@ -5,24 +7,60 @@ namespace AsuraEngine
namespace Filesystem
{
+ 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)
{
- this->data = (const byte*)data;
- this->size = size;
+ Load(data, size);
}
DataBuffer::~DataBuffer()
{
- delete[] data;
+ delete[] mBytes;
}
- void DataBuffer::SetContent(const void* data, std::size_t siez)
+ void DataBuffer::Load(DataBuffer& db)
{
- if (this->data != nullptr)
- delete[] this->data;
+ Load(db.GetBuffer(), db.GetSize());
+ }
- this->data = (const byte*)data;
- this->size = size;
+ void DataBuffer::Load(const void* data, std::size_t size)
+ {
+ if (!mBytes || mSize != size)
+ {
+ delete[] mBytes;
+ mBytes = new byte[size];
+ }
+ memcpy(mBytes, data, size);
+ }
+
+ byte* DataBuffer::GetBuffer()
+ {
+ return mBytes;
+ }
+
+ void DataBuffer::Clear()
+ {
+ if (mBytes)
+ memset(mBytes, 0, mSize);
+ }
+
+ std::size_t DataBuffer::GetSize()
+ {
+ return mSize;
}
}