#include <TFile.hpp>
|
static bool | write (const char *path, const char *data, const size_t length) |
| Write to a file. More...
|
|
static std::string | joinPath (const std::initializer_list< std::string > &paths) |
| Concats multiple paths TODO tklb trim path dilimters. More...
|
|
static std::string | platformPath (std::string path) |
| Replaces all pathdelimters to the platform ones. More...
|
|
static bool | isRelative (const std::string &path) |
|
static void | toUnixPath (std::string &path) |
|
Definition at line 29 of file TFile.hpp.
◆ FileInfo() [1/2]
tklb::FileInfo::FileInfo |
( |
const char * |
path | ) |
|
|
inline |
Definition at line 36 of file TFile.hpp.
void recursiveScan(FileInfo &root, bool recursive)
static void toUnixPath(std::string &path)
static bool isRelative(const std::string &path)
◆ FileInfo() [2/2]
tklb::FileInfo::FileInfo |
( |
| ) |
|
|
default |
◆ appendDelimiter()
void tklb::FileInfo::appendDelimiter |
( |
FileInfo & |
info | ) |
|
|
inlineprivate |
Definition at line 235 of file TFile.hpp.
236 if (info.relative.length() - info.relative.find_last_of(
'/') != 1) {
237 info.relative = info.relative +
"/";
239 if (info.absolute.length() - info.absolute.find_last_of(
'/') != 1) {
240 info.absolute = info.absolute +
"/";
◆ hashFile()
std::string tklb::FileInfo::hashFile |
( |
| ) |
|
|
inline |
Simple hash operation.
Definition at line 93 of file TFile.hpp.
99 std::ifstream fp(path);
100 std::stringstream ss;
107 uint32_t magic = 5381;
110 magic = ((magic << 5) + magic) + c;
113 ss << std::hex << std::setw(8) << std::setfill(
'0') << magic;
◆ isJSON()
bool tklb::FileInfo::isJSON |
( |
| ) |
|
|
inline |
check if the file has a .json extension
Definition at line 72 of file TFile.hpp.
73 return name.length() -
name.find_last_of(
".JSON") == 5
74 ||
name.length() -
name.find_last_of(
".json") == 5;
◆ isRelative()
static bool tklb::FileInfo::isRelative |
( |
const std::string & |
path | ) |
|
|
inlinestatic |
Definition at line 172 of file TFile.hpp.
173 return path[0] ==
'.';
◆ isWave()
bool tklb::FileInfo::isWave |
( |
| ) |
|
|
inline |
check if the file has a .wav extension
Definition at line 64 of file TFile.hpp.
65 return name.length() -
name.find_last_of(
".WAV") == 4
66 ||
name.length() -
name.find_last_of(
".wav") == 4;
◆ joinPath()
static std::string tklb::FileInfo::joinPath |
( |
const std::initializer_list< std::string > & |
paths | ) |
|
|
inlinestatic |
Concats multiple paths TODO tklb trim path dilimters.
Definition at line 145 of file TFile.hpp.
147 for (
auto &i : paths) {
◆ platformPath()
static std::string tklb::FileInfo::platformPath |
( |
std::string |
path | ) |
|
|
inlinestatic |
Replaces all pathdelimters to the platform ones.
Definition at line 156 of file TFile.hpp.
157 for (
size_t i = 1; i < path.size(); i++) {
158 if ((path[i - 1] ==
'/' || path[i - 1] ==
'\\') && (path[i] ==
'/' || path[i] ==
'\\')) {
164 for (
size_t i = 0; i < path.size(); i++) {
165 if (path[i] ==
'/' || path[i] ==
'\\') {
#define TKLB_ASSERT(condition)
Wrap assertions.
const std::string PATH_DELIMITER
◆ print()
void tklb::FileInfo::print |
( |
| ) |
|
|
inline |
Print the directory tree.
Definition at line 120 of file TFile.hpp.
void recursivePrint(FileInfo &info, int depth)
◆ recursivePrint()
void tklb::FileInfo::recursivePrint |
( |
FileInfo & |
info, |
|
|
int |
depth |
|
) |
| |
|
inlineprivate |
Definition at line 185 of file TFile.hpp.
187 std::fill_n(space, 256, 0);
188 std::fill_n(space, depth,
' ');
189 TKLB_PRINT(
"%s%s\n", space, info.name.c_str())
190 for (
int i = 0; i < info.
children.size(); i++) {
HeapBuffer< FileInfo > children
◆ recursiveScan()
void tklb::FileInfo::recursiveScan |
( |
FileInfo & |
root, |
|
|
bool |
recursive |
|
) |
| |
|
inlineprivate |
Definition at line 195 of file TFile.hpp.
196 root.children.clear();
197 struct dirent** files =
nullptr;
198 const int count = scandir(root.absolute.c_str(), &files,
nullptr, alphasort);
200 root.isFolder =
true;
202 for (
int i = 0; i < count; i++) {
203 const struct dirent* ent = files[i];
204 if (ent ==
nullptr) {
207 if (ent->d_name[0] !=
'.') {
209 info.isFolder = ent->d_type == DT_DIR;
210 info.name = ent->d_name;
211 info.relative = root.relative + info.name;
212 info.absolute = root.absolute + info.name;
213 if (recursive && info.isFolder) {
216 root.children.push(info);
225 root.isFolder =
false;
void appendDelimiter(FileInfo &info)
◆ remove()
bool tklb::FileInfo::remove |
( |
| ) |
|
|
inline |
Will delete the file, does not work with folders.
Definition at line 80 of file TFile.hpp.
83 return std::remove(path) == 0;
◆ scan()
void tklb::FileInfo::scan |
( |
| ) |
|
|
inline |
Recursively scans the directory and its subfolder.
Definition at line 57 of file TFile.hpp.
◆ toUnixPath()
static void tklb::FileInfo::toUnixPath |
( |
std::string & |
path | ) |
|
|
inlinestatic |
Definition at line 176 of file TFile.hpp.
177 for (
size_t i = 1; i < path.size(); i++) {
178 if (path[i] ==
'\\') {
◆ write()
static bool tklb::FileInfo::write |
( |
const char * |
path, |
|
|
const char * |
data, |
|
|
const size_t |
length |
|
) |
| |
|
inlinestatic |
Write to a file.
- Parameters
-
path | The path to the file |
data | The data buffer |
length | The length of the data buffer |
Definition at line 130 of file TFile.hpp.
132 auto file = std::fstream(path, std::ios::out | std::ios::binary);
133 file.write(data, length);
◆ absolute
std::string tklb::FileInfo::absolute |
◆ children
◆ isFolder
bool tklb::FileInfo::isFolder = false |
◆ name
std::string tklb::FileInfo::name |
◆ relative
std::string tklb::FileInfo::relative |
The documentation for this struct was generated from the following file: