-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibCfgPP.hpp
More file actions
107 lines (92 loc) · 3.17 KB
/
Copy pathLibCfgPP.hpp
File metadata and controls
107 lines (92 loc) · 3.17 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
#ifndef _LIBCFGPP_HPP
#define _LIBCFGPP_HPP
#include <string>
#include <vector>
namespace LibCfgPP {
class LCPPException : std::exception {
std::string _msg;
public:
LCPPException(const std::string &msg) : _msg(msg){};
virtual const char *what() const noexcept override {
return _msg.c_str();
}
};
class CfgFile {
public:
/// Default constructor.
CfgFile() = default;
/**
* @details Creates a new CfgFile object and opens the configuration
* file at the specified path.
*
* @param path The path to the configuration file.
*/
CfgFile(const std::string &path);
/**
* @brief Opens the configuration file at the specified path.
*
* @param path The path to the configuration file.
*/
void open(const std::string &path);
/// Closes the file.
void close();
/**
* @brief Returns true if the file is open, false if closed.
*
* @return true
* @return false
*/
bool is_open();
/**
* @details Finds a string by the specified key in the file and reads
* its value.
*
* @param string_key Key to the string.
*
* @return The value of the found string.
*/
std::string read(const std::string &string_key),
/**
* @brief Reads the value of a string in a specific section.
*
* @param section_key Key to the section.
* @param string_key Key to the string.
*
* @return The value of the found string.
*/
read(const std::string §ion_key, const std::string &string_key);
/// Updates all lines of the file.
void update();
/**
* @details Finds a string under the specified key and changes its value
* to the one you specified.
*
* @param string_key The key to the string.
* @param value New value for the string.
*/
void change(const std::string &string_key, const std::string &value),
/**
* @details Finds a string by the specified key, in a specific
* section and changes its value to the one you specified.
*
* @param section_key The key to the section.
* @param string_key The key to the string.
* @param value New value for the string.
*/
change(const std::string §ion_key,
const std::string &string_key, const std::string &value);
/**
* @brief Creates a new string in the file.
*
* @param string_key The key of the string.
* @param value The value that should be assigned to the string.
*/
void create_string(const std::string &string_key,
const std::string &value);
private:
std::string path;
std::vector<std::string> lines;
bool _is_open = false;
};
} // namespace LibCfgPP
#endif // _LIBCFGPP_HPP