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