-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef RAYLIB_CPP_INCLUDE_FILEDATA_HPP_ | ||
#define RAYLIB_CPP_INCLUDE_FILEDATA_HPP_ | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include "./raylib.hpp" | ||
#include "./raylib-cpp-utils.hpp" | ||
|
||
namespace raylib { | ||
|
||
class FileData { | ||
public: | ||
FileData() = default; | ||
FileData(const FileData&) = delete; | ||
FileData(FileData&& other) noexcept : data(other.data), bytesRead(other.bytesRead) { | ||
other.data = nullptr; | ||
other.bytesRead = 0; | ||
} | ||
FileData& operator=(const FileData&) = delete; | ||
FileData& operator=(FileData&& other) noexcept { | ||
std::swap(data, other.data); | ||
std::swap(bytesRead, other.bytesRead); | ||
return *this; | ||
} | ||
~FileData() { Unload(); } | ||
|
||
explicit FileData(const std::string& fileName) { | ||
Load(fileName); | ||
} | ||
|
||
GETTER(const unsigned char*, Data, data) | ||
GETTER(int, BytesRead, bytesRead) | ||
|
||
void Load(const std::string& fileName) { Load(fileName.c_str()); } | ||
void Load(const char* fileName) { | ||
data = ::LoadFileData(fileName, &bytesRead); | ||
} | ||
|
||
void Unload() { | ||
if (data != nullptr) { | ||
::UnloadFileData(data); | ||
data = nullptr; | ||
} | ||
} | ||
|
||
private: | ||
unsigned char* data{nullptr}; | ||
int bytesRead{0}; | ||
}; | ||
|
||
} // namespace raylib | ||
|
||
using RFileData = raylib::FileData; | ||
|
||
#endif // RAYLIB_CPP_INCLUDE_FILEDATA_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef RAYLIB_CPP_INCLUDE_FILETEXT_HPP_ | ||
#define RAYLIB_CPP_INCLUDE_FILETEXT_HPP_ | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include "./raylib.hpp" | ||
#include "./raylib-cpp-utils.hpp" | ||
|
||
namespace raylib { | ||
|
||
class FileText { | ||
public: | ||
FileText() = default; | ||
FileText(const FileText&) = delete; | ||
FileText(FileText&& other) noexcept : data(other.data), length(other.length) { | ||
other.data = nullptr; | ||
other.length = 0; | ||
} | ||
FileText& operator=(const FileText&) = delete; | ||
FileText& operator=(FileText&& other) noexcept { | ||
std::swap(data, other.data); | ||
std::swap(length, other.length); | ||
return *this; | ||
} | ||
~FileText() { Unload(); } | ||
|
||
explicit FileText(const std::string& fileName) { | ||
Load(fileName); | ||
} | ||
|
||
GETTER(const char*, Data, data) | ||
GETTER(unsigned int, Length, length) | ||
|
||
[[nodiscard]] const char* c_str() const { return data; } | ||
|
||
[[nodiscard]] std::string ToString() const { return data; } | ||
explicit operator std::string() const { | ||
return data; | ||
} | ||
|
||
void Load(const std::string& fileName) { Load(fileName.c_str()); } | ||
void Load(const char* fileName) { | ||
data = ::LoadFileText(fileName); | ||
length = ::TextLength(data); | ||
} | ||
|
||
void Unload() { | ||
if (data != nullptr) { | ||
::UnloadFileText(data); | ||
data = nullptr; | ||
length = 0; | ||
} | ||
} | ||
|
||
private: | ||
char* data{nullptr}; | ||
unsigned int length{0}; | ||
}; | ||
|
||
} // namespace raylib | ||
|
||
using RFileText = raylib::FileText; | ||
|
||
#endif // RAYLIB_CPP_INCLUDE_FILETEXT_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters