| 82da8a1c |
sago007 |
2015-12-19 18:00 |
1 |
/* |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
2 |
Copyright (c) 2015 Poul Sander |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
3 |
|
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
4 |
Permission is hereby granted, free of charge, to any person |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
5 |
obtaining a copy of this software and associated documentation files |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
6 |
(the "Software"), to deal in the Software without restriction, |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
7 |
including without limitation the rights to use, copy, modify, merge, |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
8 |
publish, distribute, sublicense, and/or sell copies of the Software, |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
9 |
and to permit persons to whom the Software is furnished to do so, |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
10 |
subject to the following conditions: |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
11 |
|
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
12 |
The above copyright notice and this permission notice shall be |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
13 |
included in all copies or substantial portions of the Software. |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
14 |
|
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
15 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
16 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
17 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
18 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
19 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
20 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
21 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
22 |
SOFTWARE. |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
23 |
*/ |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
24 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
25 |
#ifndef SAGOMISC_HPP |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
26 |
#define SAGOMISC_HPP |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
27 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
28 |
#include <vector> |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
29 |
#include <string> |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
30 |
#include <memory> |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
31 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
32 |
namespace sago { |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
33 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
34 |
/** |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
35 |
* Returns a vector with all filenames in a given directory. |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
36 |
* PHYSFS must be setup before hand. The directory is relative to the PHYSFS base |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
37 |
* @param dir The directory to list |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
38 |
* @return A vector with the filenames in the given directory. If empty the directory was empty or did not exist |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
39 |
*/ |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
40 |
std::vector<std::string> GetFileList(const char* dir); |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
41 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
42 |
/** |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
43 |
* Reads an entire file into memory. |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
44 |
* PHYSFS must be setup before hand |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
45 |
* @param filename The file to read |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
46 |
* @param dest The unique pointer in which the bytes will be written |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
47 |
* @param bytes Number of bytes written |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
48 |
* @return The content of the file. If empty either the file was empty, did not exist or could not be opened |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
49 |
*/ |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
50 |
void ReadBytesFromFile(const char* filename, std::unique_ptr<char[]>& dest, unsigned int& bytes); |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
51 |
|
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
52 |
/** |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
53 |
* Reads an entire file into memory. |
| 3dd66f5b |
sago007 |
2020-07-04 08:31 |
54 |
* PHYSFS must be setup before hand |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
55 |
* @param filename The file to read |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
56 |
* @return The content of the file. If empty either the file was empty, did not exist or could not be opened |
| 47fef8e8 |
sago007 |
2016-11-24 21:37 |
57 |
*/ |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
58 |
std::string GetFileContent(const char* filename); |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
59 |
|
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
60 |
/** |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
61 |
* Reads an entire file into memory. |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
62 |
* PHYSFS must be setup before hand |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
63 |
* @param filename The file to read |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
64 |
* @return The content of the file. If empty either the file was empty, did not exist or could not be opened |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
65 |
*/ |
| 6dcd75df |
sago007 |
2017-03-19 10:48 |
66 |
inline std::string GetFileContent(const std::string& filename) { return GetFileContent(filename.c_str()); }; |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
67 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
68 |
bool FileExists(const char* filename); |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
69 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
70 |
void WriteFileContent(const char* filename, const std::string& content); |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
71 |
|
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
72 |
/** |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
73 |
* This functions converts a string on a best effort basis |
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
74 |
* Unlike atol this does NOT cause undefined behavior if out of range |
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
75 |
* @param c_string A string that may contain a number |
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
76 |
* @return A number between LONG_MIN and LONG_MAX (both inclusive) |
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
77 |
*/ |
| b84f3eee |
Poul Sander |
2016-06-10 16:55 |
78 |
long int StrToLong(const char* c_string); |
| e373cd75 |
Poul Sander |
2018-11-07 19:21 |
79 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
80 |
} //namespace sago |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
81 |
|
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
82 |
#endif /* SAGOMISC_HPP */ |
| 82da8a1c |
sago007 |
2015-12-19 18:00 |
83 |
|
|
|
1970-01-01 00:00 |
84 |
|