-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathfile_utils.hpp
More file actions
123 lines (104 loc) · 2.77 KB
/
Copy pathfile_utils.hpp
File metadata and controls
123 lines (104 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @file liblava/file/file_utils.hpp
* @brief File utilities
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/core/data.hpp"
namespace lava {
/**
* @brief Read data from file
* @param out File data
* @param filename Name of file
* @return Read was successful or failed
*/
bool read_file(std::vector<char>& out, string_ref filename);
/**
* @brief Write data to file
* @param filename Name of file
* @param data Data to write
* @param data_size Size of data
* @return Write was successful or failed
*/
bool write_file(string_ref filename,
char const* data,
size_t data_size);
/**
* @brief Check extension of file
* @param filename Name of file
* @param extension Extension to check
* @return Extension found or not
*/
bool extension(string_ref filename, string_ref extension);
/**
* @brief Check extensions of file
* @param filename Name of file
* @param extensions List of extensions to check
* @return Extension found or not
*/
bool extension(string_ref filename,
string_list_ref extensions);
/**
* @brief Get the file name from path
* @param path Target path
* @param with_extension Include extension in file name
* @return string File name
*/
string get_filename_from(string_ref path,
bool with_extension = false);
/**
* @brief Remove existing path
* @param target Target path
* @param path Path to remove
* @return Remove was successful or failed
*/
bool remove_existing_path(string& target,
string_ref path);
/**
* @brief Load file data
* @param filename Name of file
* @param target Target data
* @return Load was successful or failed
*/
bool load_file_data(string_ref filename,
data& target);
/**
* @brief File data
*/
struct file_data : u_data {
/// Reference to file data
using ref = file_data const&;
/// Unique data constructors
using u_data::u_data;
/**
* @brief Construct a new file data
* @param filename Name of file
*/
explicit file_data(string_ref filename)
: filename(filename) {
load_file_data(filename, *this);
}
/// Name of file
string filename;
};
/**
* @brief File delete guard
*/
struct file_delete : no_copy_no_move {
/**
* @brief Construct a new file delete
* @param filename Name of file
*/
explicit file_delete(string filename = "")
: filename(filename) {}
/**
* @brief Destroy the file delete
*/
~file_delete();
/// Name of file
string filename;
/// Active state
bool active = true;
};
} // namespace lava