forked from ar-/incron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
incroncfg.h
129 lines (112 loc) · 3.46 KB
/
incroncfg.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
/// inotify cron configuration header
/**
* \file incroncfg.h
*
* incron configuration
*
* Copyright (C) 2007, 2008 Lukas Jelinek, <[email protected]>
*
* This program is free software; you can use it, redistribute
* it and/or modify it under the terms of the GNU General Public
* License, version 2 (see LICENSE-GPL).
*
*/
#ifndef INCRONCFG_H_
#define INCRONCFG_H_
#include <cstring>
#include <map>
/// Configuration class.
/**
* This class provides access to values loaded from
* a configuration file (either a explicitly specified one
* or the default one).
*/
class IncronCfg
{
public:
/// Initializes default configuration values.
static void Init();
/// Loads configuration values.
/**
* This method attempts to load configuration values
* from the specified file. If it fails (e.g. the file
* doesn't exist) the default file is read. As the last
* resort (for the case the default file can't be loaded)
* the hard-wired values are used.
*
* \param[in] rPath configuration file path
*/
static void Load(const std::string& rPath);
/// Retrieves a configuration value.
/**
* This method attempts to find the appropriate configuration
* value for the given key and stores it into the given
* variable.
*
* \param[in] rKey value key
* \param[out] rVal retrieved value
* \return true = success, false = failure (invalid key)
*/
static bool GetValue(const std::string& rKey, std::string& rVal);
/// Retrieves a configuration value.
/**
* This method attempts to find the appropriate configuration
* value for the given key and stores it into the given
* variable.
*
* \param[in] rKey value key
* \param[out] rVal retrieved value
* \return true = success, false = failure (invalid key)
*/
static bool GetValue(const std::string& rKey, int& rVal);
/// Retrieves a configuration value.
/**
* This method attempts to find the appropriate configuration
* value for the given key and stores it into the given
* variable.
*
* \param[in] rKey value key
* \param[out] rVal retrieved value
* \return true = success, false = failure (invalid key)
*/
static bool GetValue(const std::string& rKey, unsigned& rVal);
/// Retrieves a configuration value.
/**
* This method attempts to find the appropriate configuration
* value for the given key and stores it into the given
* variable.
*
* \param[in] rKey value key
* \param[out] rVal retrieved value
* \return true = success, false = failure (invalid key)
*/
static bool GetValue(const std::string& rKey, bool& rVal);
/// Builds a file path.
/**
* This function composes a path from a base path and a file name.
*
* \param[in] rPath base path
* \param[in] rName file name
* \return full path
*/
static std::string BuildPath(const std::string& rPath, const std::string& rName);
protected:
/// Parses a line a attempts to get a key and a value.
/**
* \param[in] s text line
* \param[out] rKey key
* \param[out] rVal value
* \return true = success, false = failure
*/
static bool ParseLine(const char* s, std::string& rKey, std::string& rVal);
/// Checks whether a line is a comment.
/**
* \param[in] s text line
* \return true = comment, false = otherwise
*/
static bool IsComment(const char* s);
private:
static std::map<std::string, std::string> m_values;
static std::map<std::string, std::string> m_defaults;
};
#endif /*INCRONCFG_H_*/