]> git.tdb.fi Git - builder.git/blob - source/config.h
Save caches before starting the build
[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         typedef std::map<std::string, Option> OptionMap;
29         typedef std::map<std::string, std::string> InputOptions;
30
31 private:
32         class Loader: public Msp::DataFile::ObjectLoader<Config>
33         {
34         public:
35                 Loader(Config &);
36         private:
37                 void option(const std::string &, const std::string &);
38         };
39
40         SourcePackage &package;
41         OptionMap options;
42         InputOptions pending_options;
43         Msp::Time::TimeStamp mtime;
44         mutable bool changed;
45
46 public:
47         Config(SourcePackage &);
48
49         /** Adds a configuration option based on a feature. */
50         const Option &add_option(const Feature &);
51
52         bool set_option(const std::string &, const std::string &);
53
54         /** Checks whether an option exists. */
55         bool is_option(const std::string &) const;
56
57         /** Gets a configuration option by name. */
58         const Option &get_option(const std::string &) const;
59
60         const OptionMap &get_options() const { return options; }
61         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
62
63         void load();
64         void save() const;
65 };
66
67 #endif