]> git.tdb.fi Git - builder.git/blob - source/config.h
Remove most container typedefs and refactor others
[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 #include "feature.h"
10
11 class SourcePackage;
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         /** A single configuration option. */
21         struct Option: public Feature
22         {
23                 std::string value;
24
25                 Option(const Feature &);
26         };
27
28         using InputOptions = std::map<std::string, std::string>;
29
30 private:
31         class Loader: public Msp::DataFile::ObjectLoader<Config>
32         {
33         public:
34                 Loader(Config &);
35         private:
36                 void option(const std::string &, const std::string &);
37         };
38
39         SourcePackage &package;
40         std::map<std::string, Option> options;
41         InputOptions pending_options;
42         Msp::Time::TimeStamp mtime;
43         mutable bool changed;
44
45 public:
46         Config(SourcePackage &);
47
48         /** Adds a configuration option based on a feature. */
49         const Option &add_option(const Feature &);
50
51         bool set_option(const std::string &, const std::string &);
52
53         /** Checks whether an option exists. */
54         bool is_option(const std::string &) const;
55
56         /** Gets a configuration option by name. */
57         const Option &get_option(const std::string &) const;
58
59         const std::map<std::string, Option> &get_options() const { return options; }
60         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
61
62         void load();
63         void save() const;
64 };
65
66 #endif