载入中...
搜索中...
未找到
ByteData.cpp
浏览该文件的文档.
1#include "ByteData.h"
2#include "common/Exception.h"
3
4#include <string.h>
5
6namespace eve {
7namespace data {
8
10 create();
11 memset(data, 0, size);
12}
13
14ByteData::ByteData(const void *d, size_t size) : size(size) {
15 create();
16 memcpy(data, d, size);
17}
18
19ByteData::ByteData(void *d, size_t size, bool own) : size(size) {
20 if (own)
21 data = (char *)d;
22 else {
23 create();
24 memcpy(data, d, size);
25 }
26}
27
29 create();
30 memcpy(data, d.data, size);
31}
32
33ByteData::~ByteData() { delete[] data; }
34
35void ByteData::create() {
36 if (size == 0) throw eve::Exception("ByteData size must be greater than 0.");
37
38 try {
39 data = new char[size];
40 } catch (std::exception &) {
41 throw eve::Exception("Create ByteData run out of memory.");
42 }
43}
44
45ByteData *ByteData::clone() const { return new ByteData(*this); }
46
47void *ByteData::getData() const { return data; }
48
49size_t ByteData::getSize() const { return size; }
50
51} // namespace data
52} // namespace eve
float d
float size
Definition TreeMesh.cpp:156
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
In-memory byte buffer implementing eve::Data (ref-counted).
Definition ByteData.h:13
void * getData() const override
Returns the data.
Definition ByteData.cpp:47
size_t getSize() const override
Returns the size.
Definition ByteData.cpp:49
ByteData(size_t size)
Allocates an uninitialized buffer of the given size.
Definition ByteData.cpp:9
virtual ~ByteData()
Byte data.
Definition ByteData.cpp:33
ByteData * clone() const override
Implements eve::Data.
Definition ByteData.cpp:45
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16