]> git.tdb.fi Git - builder.git/blob - source/config.h
Add comments
[builder.git] / source / config.h
1 #ifndef CONFIG_H_
2 #define CONFIG_H_
3
4 #include <map>
5 #include <string>
6 #include <msp/parser/loader.h>
7 #include <msp/path/path.h>
8 #include <msp/time/timestamp.h>
9
10 typedef std::map<std::string, std::string> RawOptionMap;
11
12 /**
13 Manages configuration for a package.  A configuration may have an arbitary
14 amount of options, as well as a modification time (mtime).
15 */
16 class Config
17 {
18 public:
19         /**
20         A single configuration option.
21         */
22         struct Option
23         {
24                 std::string name;
25                 std::string defv;
26                 std::string descr;
27                 std::string value;
28
29                 Option(const std::string &, const std::string &, const std::string &);
30         };
31         typedef std::map<std::string, Option> OptionMap;
32
33         void add_option(const std::string &, const std::string &, const std::string &);
34         const Option &get_option(const std::string &) const;
35         const OptionMap &get_options() const          { return options; }
36         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
37         bool is_option(const std::string &) const;
38         bool process(const RawOptionMap &);
39         void load(const Msp::Path::Path &); 
40         void save(const Msp::Path::Path &) const;
41 private:
42         class Loader: public Msp::Parser::Loader
43         {
44         public:
45                 Loader(Config &);
46         private:
47                 Config &conf;
48                 
49                 void option(const std::string &, const std::string &);
50         };
51         
52         OptionMap options;
53         Msp::Time::TimeStamp mtime;
54 };
55
56 #endif