-
Notifications
You must be signed in to change notification settings - Fork 0
/
libini.h
147 lines (104 loc) · 6.59 KB
/
libini.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef _INI_VECTOR_
#define _INI_VECTOR_
#include <string>
#include <vector>
class INIObject
{
public:
struct INIItem
{
std::string item;
std::string value;
};
class INISection
{
private:
std::string name;
std::vector<INIObject::INIItem> data;
public:
INISection() {}
INISection(const std::string &topic, std::vector<INIObject::INIItem> &items);
std::string& operator() (const std::string &item, size_t skipItem = 0);
std::string& operator() (size_t item);
std::vector<INIObject::INIItem>::iterator begin() { return data.begin(); }
std::vector<INIObject::INIItem>::iterator end() { return data.end(); }
std::vector<INIObject::INIItem>::reverse_iterator rbegin() { return data.rbegin(); }
std::vector<INIObject::INIItem>::reverse_iterator rend() { return data.rend(); }
std::vector<INIObject::INIItem>::const_iterator cbegin() { return data.cbegin(); }
std::vector<INIObject::INIItem>::const_iterator cend() { return data.cend(); }
std::vector<INIObject::INIItem>::const_reverse_iterator crbegin() { return data.crbegin(); }
std::vector<INIObject::INIItem>::const_reverse_iterator crend() { return data.crend(); }
std::string find(const std::string &item, size_t skipItem = 0);
std::string find(size_t item);
std::string topic() { return name; }
std::string info(size_t item);
size_t items() { return data.size(); }
size_t items(const std::string &item);
int erase(const std::string &item, size_t skipItem = 0);
int erase(size_t item);
std::vector<INIObject::INIItem>::iterator erase(std::vector<INIObject::INIItem>::iterator it);
std::vector<INIObject::INIItem>::iterator erase(std::vector<INIObject::INIItem>::iterator first, std::vector<INIObject::INIItem>::iterator last);
bool exists(const std::string &item, size_t skipItem = 0);
};
private:
std::vector<INISection> data;
public:
INIObject() {}
INIObject(const std::string &filepath);
int open(const std::string &filepath);
int write(const std::string &filepath);
// writes the ini file
std::string& operator() (const std::string &topic, const std::string &item, size_t skipTopic = 0, size_t skipItem = 0);
// return reference to item
std::string& operator() (const std::string &topic, size_t item, size_t skipTopic = 0);
// return reference to item
std::string& operator() (size_t topic, const std::string &item, size_t skipItem = 0);
// return reference to item
std::string& operator() (size_t topic, size_t item);
// return reference to item
std::vector<INIObject::INISection>::iterator begin() { return data.begin(); }
std::vector<INIObject::INISection>::iterator end() { return data.end(); }
std::vector<INIObject::INISection>::reverse_iterator rbegin() { return data.rbegin(); }
std::vector<INIObject::INISection>::reverse_iterator rend() { return data.rend(); }
std::vector<INIObject::INISection>::const_iterator cbegin() { return data.cbegin(); }
std::vector<INIObject::INISection>::const_iterator cend() { return data.cend(); }
std::vector<INIObject::INISection>::const_reverse_iterator crbegin() { return data.crbegin(); }
std::vector<INIObject::INISection>::const_reverse_iterator crend() { return data.crend(); }
std::vector<INIObject::INISection>::iterator topic_it(const std::string &topic, size_t skipTopic = 0);
// returns an iterator pointing to the topic
std::string find(const std::string &topic, const std::string &item, size_t skipTopic = 0, size_t skipItem = 0);
std::string find(const std::string &topic, size_t item, size_t skipTopic = 0);
std::string find(size_t topic, const std::string &item, size_t skipItem = 0);
std::string find(size_t topic, size_t item);
std::string info(size_t topic);
// returns the name of the nth topic
std::string info(size_t topic, size_t item);
// returns the name of the nth item in the nth topic
std::string info(const std::string &topic, size_t item, size_t skipTopic = 0);
// returns the name of the nth item in the topic
size_t topics();
// returns the total number of topics
size_t topics(const std::string &topic);
// returns the total number of matching topics
size_t items(const std::string &topic, size_t skipTopic = 0);
// returns the total number of items in topic
size_t items(size_t topic); // returns the total number of items in the topic
size_t items(const std::string &topic, const std::string &item, size_t skipTopic = 0);
// returns the total number of matching items in topic
size_t items(size_t topic, const std::string &item);
// returns the total number of matching items in topic
int erase(const std::string &topic, size_t skipTopic = 0);
// erases an entire section
int erase(const std::string &topic, const std::string &item, size_t skipTopic = 0, size_t skipItem = 0);
// erases an item from a section
int erase(size_t topic);
int erase(size_t topic, size_t item);
int erase(size_t topic, const std::string &item, size_t skipItem = 0);
int erase(const std::string &topic, size_t item, size_t skipTopic = 0);
std::vector<INIObject::INISection>::iterator erase(std::vector<INIObject::INISection>::iterator it);
std::vector<INIObject::INISection>::iterator erase(std::vector<INIObject::INISection>::iterator first, std::vector<INIObject::INISection>::iterator last);
bool exists(const std::string &topic, size_t skipTopic = 0);
bool exists(const std::string &topic, const std::string &item, size_t skipTopic = 0, size_t skipItem = 0);
bool exists(size_t topic, const std::string &item, size_t skipItem = 0);
};
#endif