Skip to content

Commit c596426

Browse files
committed
Updated README
1 parent feb449a commit c596426

File tree

1 file changed

+241
-18
lines changed

1 file changed

+241
-18
lines changed

README.md

Lines changed: 241 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,6 @@ In you main file configure logger:
2727
#include <iostream>
2828
#include "wsjcpp_yaml.h"
2929

30-
class MyLogger : public IWsjcppYamlLog {
31-
public:
32-
// IWsjcppYamlLog
33-
virtual void err(const std::string &TAG, const std::string &sMessage) override {
34-
std::cerr << TAG << " [error] : " << sMessage << std::endl;
35-
};
36-
virtual void throw_err(const std::string &TAG, const std::string &sMessage) override {
37-
std::cerr << TAG << " [critical_error] : " << sMessage << std::endl;
38-
throw std::runtime_error(TAG + " [critical_error] : " + sMessage);
39-
};
40-
virtual void warn(const std::string &TAG, const std::string &sMessage) override {
41-
std::cerr << TAG << " [warn] : " << sMessage << std::endl;
42-
};
43-
virtual void info(const std::string &TAG, const std::string &sMessage) override {
44-
std::cout << TAG << " [info] : " << sMessage << std::endl;
45-
};
46-
};
47-
4830
int main(int argc, char* argv[]) {
4931
std::string TAG = "MAIN";
5032
std::string appLogPath = ".logs";
@@ -90,3 +72,244 @@ int main(int argc, char* argv[]) {
9072
}
9173

9274
```
75+
76+
## a little doc:
77+
78+
### class methods (WsjcppYaml)
79+
80+
**`WsjcppYaml()`**
81+
82+
Just a constructor
83+
84+
**`void clear();`**
85+
86+
Clear all nodes
87+
88+
**`void setLogger(IWsjcppYamlLog *pLog);`**
89+
90+
If you wanna use custom logger
91+
92+
```cpp
93+
class MyLogger : public IWsjcppYamlLog {
94+
public:
95+
// IWsjcppYamlLog
96+
virtual void err(const std::string &TAG, const std::string &sMessage) override {
97+
std::cerr << TAG << " [error] : " << sMessage << std::endl;
98+
};
99+
virtual void throw_err(const std::string &TAG, const std::string &sMessage) override {
100+
std::cerr << TAG << " [critical_error] : " << sMessage << std::endl;
101+
throw std::runtime_error(TAG + " [critical_error] : " + sMessage);
102+
};
103+
virtual void warn(const std::string &TAG, const std::string &sMessage) override {
104+
std::cerr << TAG << " [warn] : " << sMessage << std::endl;
105+
};
106+
virtual void info(const std::string &TAG, const std::string &sMessage) override {
107+
std::cout << TAG << " [info] : " << sMessage << std::endl;
108+
};
109+
};
110+
111+
MyLogger *pLogger = new MyLogger();
112+
WsjcppYaml yaml;
113+
yaml.setLogger(pLogger);
114+
```
115+
116+
**`bool loadFromFile(const std::string &sFileName, std::string &sError);`**
117+
118+
load yaml from file
119+
120+
Will retrun:
121+
- `true` - success
122+
- `false` - failed (information about error will be in sError)
123+
124+
**`bool saveToFile(const std::string &sFileName, std::string &sError);`**
125+
126+
save yaml to file
127+
128+
Will retrun:
129+
- `true` - success
130+
- `false` - failed (information about error will be in sError)
131+
132+
**`bool loadFromString(const std::string &sBufferName, const std::string &sBuffer, std::string &sError);`**
133+
134+
load yaml from string
135+
136+
**`bool saveToString(std::string &sBuffer, std::string &sError);`**
137+
138+
save yaml to string
139+
140+
sBuffer - here will be result.
141+
142+
Will retrun:
143+
- `true` - success
144+
- `false` - failed (information about error will be in sError)
145+
146+
**`WsjcppYamlNode *getRoot();`**
147+
148+
return root node
149+
150+
**`WsjcppYamlCursor getCursor() const;`**
151+
152+
return cursor (for walk by yaml tree)
153+
154+
**`WsjcppYamlCursor operator[](int idx) const;`**
155+
156+
return cursor if current element is array else will be error
157+
158+
**`WsjcppYamlCursor operator[](const std::string &sName) const;`**
159+
160+
return cursor if current element is map else will be error
161+
162+
#### Static methods (WsjcppYaml)
163+
164+
**`bool readTextFile(const std::string &sFilename, std::string &sOutputContent, std::string &sError);`**
165+
166+
static method. Just read text file
167+
168+
Will retrun:
169+
- `true` - success
170+
- `false` - failed (information about error will be in sError)
171+
172+
**`bool writeFile(const std::string &sFilename, const std::string &sContent);`**
173+
174+
static method. Just write text to file
175+
176+
Will retrun:
177+
- `true` - success
178+
- `false` - failed
179+
180+
**`static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");`**
181+
182+
static method. left trim
183+
184+
**`static std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");`**
185+
186+
static method. right trim
187+
188+
**`static std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ");`**
189+
190+
static method. left and right trim
191+
192+
**`static std::string toLower(const std::string &str);`**
193+
194+
static method. to lower characters (will be work only for latin coding)
195+
196+
#### methods for logging (WsjcppYaml)
197+
198+
**`void err(const std::string &TAG, const std::string &sMessage);`**
199+
200+
default: print to std::cerr
201+
202+
But you can override by `setLogger`
203+
204+
**`void throw_err(const std::string &TAG, const std::string &sMessage);`**
205+
206+
default: print to std::cerr and throw std::exception
207+
208+
But you can override by `setLogger`
209+
210+
**`void warn(const std::string &TAG, const std::string &sMessage);`**
211+
212+
default: print to std::cerr
213+
214+
But you can override by `setLogger`
215+
216+
**`void info(const std::string &TAG, const std::string &sMessage);`**
217+
218+
default: print to std::cout
219+
220+
But you can override by `setLogger`
221+
222+
223+
### class method (WsjcppYamlCursor)
224+
225+
WsjcppYamlCursor - keep a pointer to node ()
226+
227+
228+
**`bool isNull() const;`**
229+
230+
return `true` if node is null or undefined
231+
232+
233+
**`bool isUndefined() const;`**
234+
235+
return `true` if node is undefined.
236+
It's possible if definintion in yaml without value like a `some: ` - undefined node
237+
238+
**`bool isValue() const;`**
239+
240+
return `true` if node is a simple type with a value
241+
242+
**`bool isArray() const;`**
243+
244+
return `true` if node is a array
245+
246+
**`size_t size() const;`**
247+
248+
return size of array if node is a array
249+
250+
**`bool isMap() const;`**
251+
252+
return `true` if node is map
253+
254+
**`std::vector<std::string> keys() const;`**
255+
256+
return list of keys if node is map
257+
258+
**`bool hasKey(const std::string &sKey) const;`**
259+
260+
return true if node is map and key exists
261+
262+
**`std::string comment();`**
263+
264+
return user comment or empty for node
265+
266+
**`WsjcppYamlCursor &comment(const std::string& sComment);`**
267+
268+
set new comment
269+
270+
**`std::string valStr();`**
271+
272+
return value as string
273+
274+
example: `yaml["some"].valStr()`
275+
276+
**`WsjcppYamlCursor &val(const std::string &sValue);`**
277+
278+
set new string value
279+
280+
**`WsjcppYamlCursor &val(const char *sValue);`**
281+
282+
set new string value
283+
284+
**`int valInt();`**
285+
286+
return value as integer
287+
288+
**`WsjcppYamlCursor &val(int nValue);`**
289+
290+
set new integer value
291+
292+
**`bool valBool();`**
293+
294+
return value as integer
295+
296+
**`WsjcppYamlCursor &val(bool bValue);`**
297+
298+
set new boolean value
299+
300+
**`WsjcppYamlNode *node();`**
301+
302+
return pointer to node
303+
304+
**`WsjcppYamlCursor operator[](int idx) const;`**
305+
306+
return node by index if current node is array
307+
308+
example: `yaml["somearr"][0]`
309+
310+
**`WsjcppYamlCursor operator[](const std::string &sName) const;`**
311+
312+
return node by index if current node is map
313+
314+
example: `yaml["some_map"]["el1"]`
315+

0 commit comments

Comments
 (0)