This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfgparser.h
82 lines (70 loc) · 2.41 KB
/
cfgparser.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
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#define NULLINDEX 4294967295
class CfgParser {
public:
/**
* @brief CfgParser class constructor
*
* @param [filename] Name and location of the config file
* (defaultly "./config.cfg")
*/
CfgParser(const std::wstring &filename = L"config.cfg");
/**
* @brief Load config file or create it, if not existent.
*
* @param [createIfNotExistent] If true, a default config file will
* be created with keys and values set
* with {@link setStandart} function.
* (defaultly true)
* @see {@link setStandart}
* @returns True if loading was successful.
*/
bool load(const bool &createIfNotExistent = true);
/**
* @brief Create config file with default values set with {@link setStandart}
* function at defined file location.
* Attention: If you execute this function manually, this will overwrite
* any existing config with the same name.
*
* @see {@link setStandart}
* @returns True if file creation was successful.
*/
bool create();
/**
* @brief Set the standart keys and values for creating new config.
*
* @param standartConf Map with keys and values (both as std::wstring's).
* (defaultly empty map)
*/
void setStandart(const std::map<std::wstring, std::wstring> &standartConf = std::map<std::wstring, std::wstring>());
/**
* @brief Get number value from config by key.
*
* @param key Key of the config value.
* @returns Number value of the key's value.
*/
double getNumber(const std::wstring &key);
/**
* @brief Get string value from config by key.
*
* @param key Key of the config value.
* @returns String value of the key's value.
*/
std::wstring getString(const std::wstring &key);
// <---- S O O N ---->
// template <typename T>
// bool set(const std::wstring &key, const T &value);
//
// template <typename T>
// bool add(const std::wstring &key, const T &value = NULL);
private:
std::wstring m_filename;
std::map<std::wstring, std::wstring> m_standartConf;
std::map<std::wstring, long> m_long_data;
std::map<std::wstring, double> m_double_data;
std::map<std::wstring, std::wstring> m_string_data;
};