raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
FileData.hpp
1#ifndef RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
2#define RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
3
4#include <string>
5#include <utility>
6
7#include "./raylib-cpp-utils.hpp"
8#include "./raylib.hpp"
9
10namespace raylib {
11
12class FileData {
13public:
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_view fileName) {
29 Load(fileName);
30 }
31
32 GETTER(const unsigned char*, Data, data)
33 GETTER(int, BytesRead, bytesRead)
34
35 void Load(const std::string_view fileName) { Load(fileName.data()); }
36 void Load(const char* fileName) {
37 Unload();
38 data = ::LoadFileData(fileName, &bytesRead);
39 }
40
41 void Unload() {
42 if (data != nullptr) {
43 ::UnloadFileData(data);
44 data = nullptr;
45 bytesRead = 0;
46 }
47 }
48private:
49 unsigned char* data{nullptr};
50 int bytesRead{0};
51};
52
53} // namespace raylib
54
55using RFileData = raylib::FileData;
56
57#endif // RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8