3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
13 #include <msp/datafile/loader.h>
14 #include <msp/fs/path.h>
15 #include <msp/time/timestamp.h>
21 Manages configuration for a package. A configuration may have an arbitary
22 amount of options, as well as a modification time (mtime).
27 /** A single configuration option. */
35 Option(const std::string &, const std::string &, const std::string &);
38 typedef std::map<std::string, Option> OptionMap;
41 class Loader: public Msp::DataFile::Loader
49 void option(const std::string &, const std::string &);
52 SourcePackage &package;
54 Msp::Time::TimeStamp mtime;
58 Config(SourcePackage &);
60 /** Adds a configuration option with name, default value and description. */
61 void add_option(const std::string &, const std::string &, const std::string &);
63 /** Gets a configuration option by name. */
64 const Option &get_option(const std::string &) const;
66 const OptionMap &get_options() const { return options; }
67 const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
69 /** Checks whether an option exists. */
70 bool is_option(const std::string &) const;
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();
76 /** Selects a profile. The profile cache file is updated, unless doing a
78 void select_profile(const std::string &);
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
84 bool update(const StringMap &);
86 /** Expands any variable references in options. */
91 bool set_option(const std::string &, const std::string &);