YourGameLib
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2024 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_FILE_H
21#define YOURGAME_FILE_H
22
23#include <cstdint>
24#include <string>
25#include <vector>
26
27namespace yourgame
28{
29 namespace file
30 {
39 int readFile(const std::string &filename, std::vector<uint8_t> &dst);
40
42 int readAssetFile(const std::string &filename, std::vector<uint8_t> &dst);
43
45 int readProjectFile(const std::string &filename, std::vector<uint8_t> &dst);
46
50 int writeFile(const std::string &filename, const void *data, size_t numBytes);
51
54 int writeAssetFile(const std::string &filename, const void *data, size_t numBytes);
55
58 int writeProjectFile(const std::string &filename, const void *data, size_t numBytes);
59
61 void setProjectPath(const std::string &path);
62
64 std::string getBasePath(const std::string &pathRelative = "");
65
67 std::string getAssetFilePath(const std::string &pathRelative = "");
68
70 std::string getProjectFilePath(const std::string &pathRelative = "");
71
77 std::string getFileLocation(const std::string &filepath);
78
84 std::string getFileName(const std::string &filepath);
85
96 std::string getFileNameWithoutExtension(const std::string &filepath);
97
104 std::string getFileExtension(const std::string &filepath);
105
108 std::vector<std::string> ls(const std::string &pattern);
109 } // namespace file
110} // namespace yourgame
111
112#endif
std::vector< std::string > ls(const std::string &pattern)
returns list of directory content. accepts prefixes like readFile() does. accepts wildcard "*" for fi...
Definition file.cpp:101
int writeFile(const std::string &filename, const void *data, size_t numBytes)
writes numBytes bytes from data to a file called filename, destination path determined by prefix ("a/...
Definition file.cpp:195
int writeProjectFile(const std::string &filename, const void *data, size_t numBytes)
writes numBytes bytes from data to a file called filename in the project file location....
Definition file.cpp:92
int readProjectFile(const std::string &filename, std::vector< uint8_t > &dst)
reads an entire file (from project file location) and returns it as a vector of bytes
Definition file.cpp:82
std::string getAssetFilePath(const std::string &pathRelative="")
returns the full (absolut) path to the assets directory, extended by pathRelative
Definition file.cpp:50
int writeAssetFile(const std::string &filename, const void *data, size_t numBytes)
writes numBytes bytes from data to a file called filename in the asset file location....
Definition file.cpp:87
int readAssetFile(const std::string &filename, std::vector< uint8_t > &dst)
reads an entire file (from asset file location) and returns it as a vector of bytes
Definition file.cpp:65
std::string getFileName(const std::string &filepath)
returns the actual file name of a file, filepath points to
Definition file.cpp:153
std::string getFileNameWithoutExtension(const std::string &filepath)
returns the actual file name (w/o file extension) of a file, filepath points to
Definition file.cpp:166
std::string getFileExtension(const std::string &filepath)
returns the file extension
Definition file.cpp:182
std::string getProjectFilePath(const std::string &pathRelative="")
returns the full (absolut) path to the current project directory, extended by pathRelative
Definition file.cpp:60
int readFile(const std::string &filename, std::vector< uint8_t > &dst)
reads an entire file and returns it as a vector of bytes
Definition file.cpp:118
std::string getBasePath(const std::string &pathRelative="")
returns the full (absolut) path to the executable (base), extended by pathRelative
Definition file.cpp:55
std::string getFileLocation(const std::string &filepath)
returns the location (path or prefix, such as a//) of a file, filepath points to
Definition file.cpp:134
void setProjectPath(const std::string &path)
sets path as current project directory
Definition file.cpp:97
Definition audio.h:27