-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathjson_file.hpp
More file actions
99 lines (80 loc) · 1.87 KB
/
Copy pathjson_file.hpp
File metadata and controls
99 lines (80 loc) · 1.87 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
/**
* @file liblava/file/json_file.hpp
* @brief Json file
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/file/json.hpp"
namespace lava {
/**
* @brief Json file
*/
struct json_file {
/**
* @brief Construct a new json file
* @param path Name of file
*/
explicit json_file(string_ref path = "config.json");
/**
* @brief Json file callback
*/
struct callback {
/// List of callbacks
using list = std::vector<callback*>;
/// Load function
using load_func = std::function<void(json_ref)>;
/// Called on load
load_func on_load;
/// Save function
using save_func = std::function<json()>;
/// Called on save
save_func on_save;
};
/**
* @brief Add callback to json file
* @param callback Callback to add
*/
void add(callback* callback);
/**
* @brief Remove callback from json file
* @param callback Callback to remove
*/
void remove(callback* callback);
/**
* @brief Clear all callbacks
*/
void clear() {
m_callbacks.clear();
}
/**
* @brief Set path of the json file
* @param value Name of file
*/
void set(string_ref value) {
m_path = value;
}
/**
* @brief Get path of the json file
* @return name Name of file
*/
string_ref get() const {
return m_path;
}
/**
* @brief Load the json file
* @return Load was successful or failed
*/
bool load();
/**
* @brief Save the json file
* @return Save was successful or failed
*/
bool save();
private:
/// Name of file
string m_path;
/// List of callbacks
callback::list m_callbacks;
};
} // namespace lava