]> git.tdb.fi Git - builder.git/blob - source/lib/config.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / 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 #include "libbuilder_api.h"
11
12 class SourcePackage;
13
14 /**
15 Manages configuration for a package.  A configuration may have an arbitary
16 amount of options, as well as a modification time (mtime).
17 */
18 class LIBBUILDER_API Config
19 {
20 public:
21         /** A single configuration option. */
22         struct LIBBUILDER_API Option: public Feature
23         {
24                 std::string value;
25
26                 Option(const Feature &);
27         };
28
29         using InputOptions = std::map<std::string, std::string>;
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         std::map<std::string, Option> options;
42         InputOptions pending_options;
43         Msp::Time::TimeStamp mtime;
44         mutable bool changed = false;
45
46 public:
47         Config(SourcePackage &p): package(p) { }
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 std::map<std::string, Option> &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