]> git.tdb.fi Git - builder.git/blob - source/config.h
Reorder class members
[builder.git] / source / config.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef CONFIG_H_
9 #define CONFIG_H_
10
11 #include <map>
12 #include <string>
13 #include <msp/datafile/loader.h>
14 #include <msp/fs/path.h>
15 #include <msp/time/timestamp.h>
16 #include "misc.h"
17
18 class SourcePackage;
19
20 /**
21 Manages configuration for a package.  A configuration may have an arbitary
22 amount of options, as well as a modification time (mtime).
23 */
24 class Config
25 {
26 public:
27         /** A single configuration option. */
28         struct Option
29         {
30                 std::string name;
31                 std::string defv;
32                 std::string descr;
33                 std::string value;
34
35                 Option(const std::string &, const std::string &, const std::string &);
36         };
37
38         typedef std::map<std::string, Option> OptionMap;
39
40 private:
41         class Loader: public Msp::DataFile::Loader
42         {
43         private:
44                 Config &conf;
45
46         public:
47                 Loader(Config &);
48         private:
49                 void option(const std::string &, const std::string &);
50         };
51
52         SourcePackage &package;
53         OptionMap options;
54         Msp::Time::TimeStamp mtime;
55         bool freeze_mtime;
56
57 public:
58         Config(SourcePackage &);
59
60         /** Adds a configuration option with name, default value and description. */
61         void add_option(const std::string &, const std::string &, const std::string &);
62
63         /** Gets a configuration option by name. */
64         const Option &get_option(const std::string &) const;
65
66         const OptionMap &get_options() const { return options; }
67         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
68
69         /** Checks whether an option exists. */
70         bool is_option(const std::string &) const;
71
72         /** Selects the last profile used.  If the profile cache file is not
73         present, the default profile is assumed. */
74         void select_last_profile();
75
76         /** Selects a profile.  The profile cache file is updated, unless doing a
77         dry run. */
78         void select_profile(const std::string &);
79
80         /** Processes options from the given raw option map.  Nonexistent options
81         are ignored.  If any options were changed, the mtime of the configuration is
82         updated to the current time.  Return value indicates whether any options
83         were changed. */
84         bool update(const StringMap &);
85
86         /** Expands any variable references in options. */
87         void finish();
88
89         void save() const;
90 private:
91         bool set_option(const std::string &, const std::string &);
92         void load();
93 };
94
95 #endif