| 10 | namespace raylib { |
| 11 | |
| 12 | class FileData { |
| 13 | public: |
| 14 | FileData() = default; |
| 15 | FileData(const FileData&) = delete; |
| 16 | FileData(FileData&& other) noexcept : data(other.data), bytesRead(other.bytesRead) { |
| 17 | other.data = nullptr; |
| 18 | other.bytesRead = 0; |
| 19 | } |
| 20 | FileData& operator=(const FileData&) = delete; |
| 21 | FileData& operator=(FileData&& other) noexcept { |
| 22 | std::swap(data, other.data); |
| 23 | std::swap(bytesRead, other.bytesRead); |
| 24 | return *this; |
| 25 | } |
| 26 | ~FileData() { Unload(); } |
| 27 | |
| 28 | explicit FileData(const std::string& fileName) { Load(fileName); } |
| 29 | |
| 30 | GETTER(const unsigned char*, Data, data) |
| 31 | GETTER(int, BytesRead, bytesRead) |
| 32 | |
| 33 | void Load(const std::string& fileName) { Load(fileName.c_str()); } |
| 34 | void Load(const char* fileName) { |
| 35 | Unload(); |
| 36 | data = ::LoadFileData(fileName, &bytesRead); |
| 37 | } |
| 38 | |
| 39 | void Unload() { |
| 40 | if (data != nullptr) { |
| 41 | ::UnloadFileData(data); |
| 42 | data = nullptr; |
| 43 | bytesRead = 0; |
| 44 | } |
| 45 | } |
| 46 | private: |
| 47 | unsigned char* data{nullptr}; |
| 48 | int bytesRead{0}; |
| 49 | }; |
| 50 | |
| 51 | } // namespace raylib |
| 52 |
nothing calls this directly
no outgoing calls
no test coverage detected