]> git.tdb.fi Git - builder.git/blob - source/config.h
Change mspparser -> mspdatafile
[builder.git] / source / config.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 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/path/path.h>
15 #include <msp/time/timestamp.h>
16 #include "misc.h"
17
18 class Package;
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         /**
28         A single configuration option.
29         */
30         struct Option
31         {
32                 std::string name;
33                 std::string defv;
34                 std::string descr;
35                 std::string value;
36
37                 Option(const std::string &, const std::string &, const std::string &);
38         };
39         typedef std::map<std::string, Option> OptionMap;
40
41         Config(Package &);
42         void add_option(const std::string &, const std::string &, const std::string &);
43         const Option &get_option(const std::string &) const;
44         const OptionMap &get_options() const          { return options; }
45         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
46         bool is_option(const std::string &) const;
47         void select_last_profile();
48         void select_profile(const std::string &);
49         bool update(const StringMap &);
50         void finish();
51         void save() const;
52 private:
53         class Loader: public Msp::DataFile::Loader
54         {
55         public:
56                 Loader(Config &);
57         private:
58                 Config &conf;
59                 
60                 void option(const std::string &, const std::string &);
61         };
62
63         Package         &package;
64         OptionMap       options;
65         Msp::Time::TimeStamp mtime;
66         bool freeze_mtime;
67
68         bool set_option(const std::string &, const std::string &);
69         void load();
70 };
71
72 #endif