载入中...
搜索中...
未找到
ByteData.cpp
浏览该文件的文档.
1#include "ByteData.h"
2#include "common/Exception.h"
3
4#include <string.h>
5
6namespace eve {
7namespace data {
8
9ByteData::ByteData(size_t size) : size(size) {
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
28ByteData::ByteData(const ByteData &d) : size(d.size) {
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
Light2D::Data * data
int d
In-memory byte buffer implementing eve::Data (ref-counted).
Definition ByteData.h:11
void * getData() const override
Gets a pointer to the data. This pointer will obviously not be valid if the Data object is destroyed.
Definition ByteData.cpp:47
size_t getSize() const override
Gets the size of the Data in bytes.
Definition ByteData.cpp:49
ByteData(size_t size)
Allocates an uninitialized buffer of the given size.
Definition ByteData.cpp:9
virtual ~ByteData()
Definition ByteData.cpp:33
ByteData * clone() const override
Implements eve::Data.
Definition ByteData.cpp:45
Definition Build.cpp:11