X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fconfig.h;h=f18487bfeeb61493bc5ab0459f81903deff13ddf;hb=a116ad9af4a6a75093f6e1c3603d16b397833154;hp=e5c90de0ce597f5bb14607a0f0b0e49481682202;hpb=97001ddfa2463e6a3526eff772962acdad45f995;p=builder.git diff --git a/source/config.h b/source/config.h index e5c90de..f18487b 100644 --- a/source/config.h +++ b/source/config.h @@ -3,16 +3,21 @@ #include #include -#include -#include +#include +#include #include -#include "option.h" +#include "misc.h" -typedef std::map RawOptionMap; +class SourcePackage; +/** +Manages configuration for a package. A configuration may have an arbitary +amount of options, as well as a modification time (mtime). +*/ class Config { public: + /** A single configuration option. */ struct Option { std::string name; @@ -22,21 +27,52 @@ public: Option(const std::string &, const std::string &, const std::string &); }; + typedef std::map OptionMap; - void add_option(const std::string &, const std::string &, const std::string &); - const Option &get_option(const std::string &) const; - const Msp::Time::TimeStamp &get_mtime() const { return mtime; } - bool is_option(const std::string &) const; - bool process(const RawOptionMap &); - void load(const Msp::Path::Path &); private: - class Loader: public Msp::Parser::Loader + class Loader: public Msp::DataFile::ObjectLoader { + public: + Loader(Config &); + private: + void option(const std::string &, const std::string &); }; - + + SourcePackage &package; OptionMap options; Msp::Time::TimeStamp mtime; + bool changed; + +public: + Config(SourcePackage &); + + /** Adds a configuration option with name, default value and description. */ + void add_option(const std::string &, const std::string &, const std::string &); + + /** Gets a configuration option by name. */ + const Option &get_option(const std::string &) const; + + const OptionMap &get_options() const { return options; } + const Msp::Time::TimeStamp &get_mtime() const { return mtime; } + + /** Checks whether an option exists. */ + bool is_option(const std::string &) const; + + /** Processes options from the given raw option map. Nonexistent options + are ignored. If any options were changed, the mtime of the configuration is + updated to the current time. Return value indicates whether any options + were changed. */ + bool update(const StringMap &); + + /** Expands any variable references in options. */ + void finish(); + + void save() const; +private: + bool set_option(const std::string &, const std::string &); +public: + void load(); }; #endif