-
Notifications
You must be signed in to change notification settings - Fork 4
/
Config.h
executable file
·59 lines (50 loc) · 1.98 KB
/
Config.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
#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_
#include <time.h>
#include "Synchronizer.h"
#include "common.h"
struct PluginCfg;
//+------------------------------------------------------------------+
//| Simple configuration |
//+------------------------------------------------------------------+
class Config {
private:
Synchronizer m_sync; // synchronizer
char m_filename[MAX_PATH]; // name of the configuration file
PluginCfg* m_cfg; // configs
int m_cfg_total; // total number of records
int m_cfg_max; // max number of records
public:
static Config& Instance();
//--- Initializing the database (reading the config file)
void Load(const char* filename);
void Save(void);
//--- access
int Add(const char* name, const char* value, bool save = false);
int Add(const PluginCfg* cfg);
int Set(const PluginCfg* values, const int total);
int Get(const char* name, PluginCfg* cfg);
int Next(const int index, PluginCfg* cfg);
int Delete(const char* name);
inline int Total(void) {
m_sync.Lock();
int total = m_cfg_total;
m_sync.Unlock();
return (total);
}
int GetInteger(const char* name, int* value, const char* defvalue = NULL);
int GetLong(const char* name, long* value, const char* defvalue = NULL);
int GetString(const char* name, char* value, const int maxlen, const char* defvalue = NULL);
bool HasKey(const char* name);
private:
Config();
~Config();
Config(Config const&) = delete;
void operator=(Config const&) = delete;
PluginCfg* Search(const char* name);
static int SortByName(const void* left, const void* right);
static int SearchByName(const void* left, const void* right);
};
// extern Config ExtConfig;
//+------------------------------------------------------------------+
#endif // !_CONFIGURATION_H_