summaryrefslogtreecommitdiff
path: root/source/modules/asura-utils/io/data_buffer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-02 20:51:00 +0800
committerchai <chaifix@163.com>2019-08-02 20:51:00 +0800
commitbad78945ceba425f6a80e3b8dca2414d592970eb (patch)
tree8bf7540766349c534bf9e5746b24fd7507ba034e /source/modules/asura-utils/io/data_buffer.cpp
parent99b90496765df21c5f377f42b9ed073ccb34c1fd (diff)
*修改文件名格式
Diffstat (limited to 'source/modules/asura-utils/io/data_buffer.cpp')
-rw-r--r--source/modules/asura-utils/io/data_buffer.cpp156
1 files changed, 0 insertions, 156 deletions
diff --git a/source/modules/asura-utils/io/data_buffer.cpp b/source/modules/asura-utils/io/data_buffer.cpp
deleted file mode 100644
index 37f749c..0000000
--- a/source/modules/asura-utils/io/data_buffer.cpp
+++ /dev/null
@@ -1,156 +0,0 @@
-#include <cstdlib>
-#include <cstring>
-#include "data_buffer.h"
-
-using namespace AEThreading;
-
-namespace AsuraEngine
-{
- namespace IO
- {
-
- DataBuffer::DataBuffer(DataBuffer& src)
- : m_Size(0)
- , m_Capacity(0)
- , m_Bytes(nullptr)
- {
- // ʼ
- lock(m_Mutex)
- {
- m_Capacity = src.m_Size;
- m_Bytes = new byte[m_Capacity];
- Clear();
-
- Load(src);
- }
- }
-
- DataBuffer::DataBuffer(std::size_t capacity)
- : m_Size(0)
- , m_Capacity(0)
- , m_Bytes(nullptr)
- {
- lock(m_Mutex)
- {
- m_Capacity = capacity;
- m_Bytes = new byte[m_Capacity];
- Clear();
- }
- }
-
- DataBuffer::DataBuffer(const void* data, std::size_t size)
- : m_Capacity(0)
- , m_Size(0)
- , m_Bytes(nullptr)
- {
- lock(m_Mutex)
- {
- m_Capacity = size;
- m_Bytes = new byte[m_Capacity];
- Clear();
-
- Load(data, size);
- }
- }
-
- DataBuffer::~DataBuffer()
- {
- lock(m_Mutex)
- {
- delete[] m_Bytes;
- }
- }
-
- void DataBuffer::Refactor(size_t capacity)
- {
- lock(m_Mutex)
- {
- if (!m_Bytes || m_Capacity != capacity)
- {
- if(m_Bytes)
- delete[] m_Bytes;
- m_Capacity = capacity;
- m_Bytes = new byte[m_Capacity];
- m_Size = 0;
- }
- Clear();
- }
- }
-
- void DataBuffer::Load(DataBuffer& db)
- {
- lock(m_Mutex)
- {
- Load(db.GetData(), db.GetSize());
- }
- }
-
- void DataBuffer::Load(const void* data, std::size_t size)
- {
- lock(m_Mutex)
- {
- ASSERT(m_Capacity >= size);
- memcpy(m_Bytes, data, size);
- m_Size = size;
- }
- }
-
- void DataBuffer::Move(void* bytes, std::size_t size)
- {
- lock(m_Mutex)
- {
- if (m_Bytes == bytes)
- {
- // sizeֵڶļʱ
- m_Size = size;
- }
- else
- {
- if (m_Bytes)
- delete[] m_Bytes;
- m_Bytes = (byte*)bytes;
- m_Size = size;
- m_Capacity = size;
- }
- }
- }
-
- byte* DataBuffer::GetData()
- {
- return m_Bytes;
- }
-
- void DataBuffer::Clear()
- {
- lock(m_Mutex)
- {
- if (m_Bytes)
- {
- memset(m_Bytes, 0, m_Size);
- m_Size = 0;
- }
- }
- }
-
- std::size_t DataBuffer::GetSize()
- {
- return m_Size;
- }
-
- std::size_t DataBuffer::GetCapacity()
- {
- return m_Capacity;
- }
-
- void DataBuffer::Lock()
- {
- m_Mutex.Lock();
- }
-
- void DataBuffer::Unlock()
- {
- m_Mutex.Unlock();
- }
-
- }
-} \ No newline at end of file