载入中...
搜索中...
未找到
FileData.cpp
浏览该文件的文档.
1
2#include "FileData.h"
3
4#include <iostream>
5#include <limits>
6#include <cstring>
7
8namespace eve {
9namespace filesystem {
10
11FileData::FileData(const std::string &filename, uint64_t size)
12 : data(nullptr), size((size_t)size), filename(filename) {
13 try {
14 data = new uint8_t[size];
15 } catch (std::bad_alloc &) {
16 throw eve::Exception("Out of memory.");
17 }
18
19 size_t dotpos = filename.rfind('.');
20
21 if (dotpos != std::string::npos) {
22 extension = filename.substr(dotpos + 1);
23 name = filename.substr(0, dotpos);
24 } else
25 name = filename;
26}
27
29 : data(nullptr), size(c.size), filename(c.filename), extension(c.extension), name(c.name) {
30 try {
31 data = new uint8_t[size];
32 } catch (std::bad_alloc &) {
33 throw eve::Exception("Out of memory.");
34 }
35 memcpy(data, c.data, size);
36}
37
38FileData::~FileData() { delete[] data; }
39
40FileData *FileData::clone() const { return new FileData(*this); }
41
42
43} // namespace filesystem
44} // namespace eve
std::int32_t c
std::string name
float size
Definition TreeMesh.cpp:156
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Data buffer paired with a filename (used for type identification).
Definition FileData.h:14
FileData(const std::string &filename, uint64_t size)
Allocates a buffer of the given size for the named file.
Definition FileData.cpp:11
virtual ~FileData()
File data.
Definition FileData.cpp:38
FileData * clone() const
Implements eve::Data.
Definition FileData.cpp:40
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16