载入中...
搜索中...
未找到
CompressedData.cpp
浏览该文件的文档.
1#include "CompressedData.h"
2#include "common/Exception.h"
3
4#include <cstring>
5
6namespace eve {
7namespace data {
8
9CompressedData::CompressedData(std::string format, char *cdata, size_t compressedsize, size_t rawsize, bool own)
10 : format(format), data(nullptr), dataSize(compressedsize), originalSize(rawsize) {
11 if (own)
12 data = cdata;
13 else {
14 try {
15 data = new char[dataSize];
16 } catch (std::bad_alloc &) {
17 throw eve::Exception("Create CompressedData run out of memory.");
18 }
19
20 memcpy(data, cdata, dataSize);
21 }
22}
23
25 : format(c.format), data(nullptr), dataSize(c.dataSize), originalSize(c.originalSize) {
26 try {
27 data = new char[dataSize];
28 } catch (std::bad_alloc &) {
29 throw eve::Exception("Copy CompressedData run out of memory.");
30 }
31
32 memcpy(data, c.data, dataSize);
33}
34
36
38
39std::string CompressedData::getFormat() const { return format; }
40
41size_t CompressedData::getDecompressedSize() const { return originalSize; }
42
43void *CompressedData::getData() const { return data; }
44
45size_t CompressedData::getSize() const { return dataSize; }
46
47} // namespace data
48} // namespace eve
uint32_t c
Light2D::Data * data
Stores byte data compressed via DataModule::compress.
CompressedData * clone() const override
Creates a duplicate of Data derived class instance.
CompressedData(std::string format, char *cdata, size_t compressedsize, size_t rawsize, bool own=true)
Constructor just stores already-compressed data in the object.
size_t getDecompressedSize() const
Gets the original (uncompressed) size of the compressed data. May return 0 if the uncompressed size i...
void * getData() const override
Gets a pointer to the data. This pointer will obviously not be valid if the Data object is destroyed.
size_t getSize() const override
Gets the size of the Data in bytes.
std::string getFormat() const
Gets the format that was used to compress the data.
Definition Build.cpp:11