]> git.tdb.fi Git - builder.git/blob - source/config.h
Better encapsulation of config inside Package
[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         void select_last_profile();
39         void select_profile(const std::string &);
40         bool update(const RawOptionMap &);
41         void set_source(const Msp::Path::Path &s)     { source=s; }
42         void save() const;
43 private:
44         class Loader: public Msp::Parser::Loader
45         {
46         public:
47                 Loader(Config &);
48         private:
49                 Config &conf;
50                 
51                 void option(const std::string &, const std::string &);
52         };
53         
54         Msp::Path::Path source;
55         OptionMap       options;
56         Msp::Time::TimeStamp mtime;
57
58         bool set_option(const std::string &, const std::string &);
59         void load();
60 };
61
62 #endif