]> git.tdb.fi Git - builder.git/blob - source/config.h
Eliminate all global typedefs, making misc.h finally unnecessary
[builder.git] / source / config.h
1 #ifndef CONFIG_H_
2 #define CONFIG_H_
3
4 #include <map>
5 #include <string>
6 #include <msp/datafile/loader.h>
7 #include <msp/fs/path.h>
8 #include <msp/time/timestamp.h>
9
10 class SourcePackage;
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         /** A single configuration option. */
20         struct Option
21         {
22                 std::string name;
23                 std::string default_value;
24                 std::string description;
25                 std::string value;
26
27                 Option(const std::string &, const std::string &, const std::string &);
28         };
29
30         typedef std::map<std::string, Option> OptionMap;
31         typedef std::map<std::string, std::string> InputOptions;
32
33 private:
34         class Loader: public Msp::DataFile::ObjectLoader<Config>
35         {
36         public:
37                 Loader(Config &);
38         private:
39                 void option(const std::string &, const std::string &);
40         };
41
42         SourcePackage &package;
43         OptionMap options;
44         InputOptions pending_options;
45         Msp::Time::TimeStamp mtime;
46         bool changed;
47
48 public:
49         Config(SourcePackage &);
50
51         /** Adds a configuration option with name, default value and description. */
52         void add_option(const std::string &, const std::string &, const std::string &);
53
54         bool set_option(const std::string &, const std::string &);
55
56         /** Checks whether an option exists. */
57         bool is_option(const std::string &) const;
58
59         /** Gets a configuration option by name. */
60         const Option &get_option(const std::string &) const;
61
62         const OptionMap &get_options() const { return options; }
63         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
64
65         void load();
66         void save() const;
67 };
68
69 #endif