raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
FileText.hpp
1#ifndef RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
2#define RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
3
4#include <string>
5#include <utility>
6
7#include "./raylib-cpp-utils.hpp"
8#include "./raylib.hpp"
9
10namespace raylib {
11
12class FileText {
13public:
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_view fileName) {
29 Load(fileName);
30 }
31
32 GETTER(const char*, Data, data)
33 GETTER(unsigned int, Length, length)
34
35 [[nodiscard]] const char* c_str() const { return data; }
36
37 [[nodiscard]] std::string ToString() const { return data; }
38 explicit operator std::string() const { return data; }
39
40 void Load(const std::string_view fileName) { Load(fileName.data()); }
41 void Load(const char* fileName) {
42 data = ::LoadFileText(fileName);
43 length = ::TextLength(data);
44 }
45
46 void Unload() {
47 if (data != nullptr) {
48 ::UnloadFileText(data);
49 data = nullptr;
50 length = 0;
51 }
52 }
53private:
54 char* data{nullptr};
55 unsigned int length{0};
56};
57
58} // namespace raylib
59
60using RFileText = raylib::FileText;
61
62#endif // RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
static unsigned int TextLength(const char *text)
Check if two text string are equal.
Definition: Functions.hpp:348
static std::string LoadFileText(const std::string_view fileName)
Load text data from file (read)
Definition: Functions.hpp:76