/[projects]/smsdaemon/ConfigFile.h
ViewVC logotype

Annotation of /smsdaemon/ConfigFile.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations) (download)
Sun Dec 21 18:41:08 2008 UTC (15 years, 5 months ago) by torben
File MIME type: text/plain
File size: 1494 byte(s)
Enable dynamic reload of plugins/tasks when recieving a HUP signal

1 torben 146 #ifndef __CONFIG_FILE_H__
2     #define __CONFIG_FILE_H__
3    
4     /* Usage
5     * ConfigFile cf("config.txt");
6     *
7     * std::string foo;
8     * std::string water;
9     * double four;
10     *
11     * foo = cf.Value("section_1","foo" );
12     * water = cf.Value("section_2","water");
13     * four = cf.Value("section_2","four" );
14     *
15     * std::cout << foo << std::endl;
16     * std::cout << water << std::endl;
17     * std::cout << four << std::endl;
18     *
19     * From a config file like this:
20     *
21     * [section_1]
22     * foo = bar
23     * water= h2o
24     *
25     * [section_2]
26     * foo = foo
27     * water= wet
28     * four = 4.2
29     */
30    
31    
32    
33    
34     #include <string>
35     #include <map>
36 torben 201 #include <vector>
37 torben 146 #include "Value.h"
38    
39     class ConfigFile
40     {
41 torben 201 std::multimap<std::string,Value> content_;
42     typedef std::multimap<std::string,Value>::const_iterator content_iterator;
43 torben 146
44 torben 208 std::string filename_;
45     bool Open();
46    
47 torben 146 public:
48     ConfigFile();
49     ConfigFile(std::string const& configFile);
50     bool Open(std::string const& configFile);
51 torben 208 bool Reload();
52 torben 146
53 torben 202 std::string DumpConfig() const;
54    
55 torben 146 Value const& GetValue(std::string const& section, std::string const& entry) const;
56 torben 201 std::vector<Value> GetValues(std::string const& section, std::string const& entry) const;
57 torben 146
58     Value const& GetValue(std::string const& section, std::string const& entry, double value);
59     Value const& GetValue(std::string const& section, std::string const& entry, std::string const& value);
60     };
61    
62 torben 205 namespace ConfigHelper
63     {
64     std::map<std::string, std::string> ParseArguments(const std::string& args);
65     int StringToInt(const std::string& input);
66     }
67    
68 torben 146 #endif

  ViewVC Help
Powered by ViewVC 1.1.20