6 #include <msp/datafile/loader.h>
7 #include <msp/fs/path.h>
8 #include <msp/time/timestamp.h>
14 Manages configuration for a package. A configuration may have an arbitary
15 amount of options, as well as a modification time (mtime).
20 /** A single configuration option. */
28 Option(const std::string &, const std::string &, const std::string &);
31 typedef std::map<std::string, Option> OptionMap;
34 class Loader: public Msp::DataFile::Loader
42 void option(const std::string &, const std::string &);
45 SourcePackage &package;
47 Msp::Time::TimeStamp mtime;
51 Config(SourcePackage &);
53 /** Adds a configuration option with name, default value and description. */
54 void add_option(const std::string &, const std::string &, const std::string &);
56 /** Gets a configuration option by name. */
57 const Option &get_option(const std::string &) const;
59 const OptionMap &get_options() const { return options; }
60 const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
62 /** Checks whether an option exists. */
63 bool is_option(const std::string &) const;
65 /** Selects the last profile used. If the profile cache file is not
66 present, the default profile is assumed. */
67 void select_last_profile();
69 /** Selects a profile. The profile cache file is updated, unless doing a
71 void select_profile(const std::string &);
73 /** Processes options from the given raw option map. Nonexistent options
74 are ignored. If any options were changed, the mtime of the configuration is
75 updated to the current time. Return value indicates whether any options
77 bool update(const StringMap &);
79 /** Expands any variable references in options. */
84 bool set_option(const std::string &, const std::string &);