]> git.tdb.fi Git - builder.git/blob - source/config.h
Add profile templates
[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 #include "misc.h"
10
11 class Package;
12
13 /**
14 Manages configuration for a package.  A configuration may have an arbitary
15 amount of options, as well as a modification time (mtime).
16 */
17 class Config
18 {
19 public:
20         /**
21         A single configuration option.
22         */
23         struct Option
24         {
25                 std::string name;
26                 std::string defv;
27                 std::string descr;
28                 std::string value;
29
30                 Option(const std::string &, const std::string &, const std::string &);
31         };
32         typedef std::map<std::string, Option> OptionMap;
33
34         Config(Package &);
35         void add_option(const std::string &, const std::string &, const std::string &);
36         const Option &get_option(const std::string &) const;
37         const OptionMap &get_options() const          { return options; }
38         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
39         bool is_option(const std::string &) const;
40         void select_last_profile();
41         void select_profile(const std::string &);
42         bool update(const StringMap &);
43         void finish();
44         void save() const;
45 private:
46         class Loader: public Msp::Parser::Loader
47         {
48         public:
49                 Loader(Config &);
50         private:
51                 Config &conf;
52                 
53                 void option(const std::string &, const std::string &);
54         };
55
56         Package         &package;
57         OptionMap       options;
58         Msp::Time::TimeStamp mtime;
59         bool freeze_mtime;
60
61         bool set_option(const std::string &, const std::string &);
62         void load();
63 };
64
65 #endif