From 75bec507b3815f8a101de265bd353cfdb289bc6d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 21 Nov 2012 08:44:24 +0000 Subject: Configuration file support. Change "jack-client" option to "jack-name". Print more informative info log messages. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4841 a436a847-0d15-0410-975c-d299462d15a1 --- ingen/Configuration.hpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'ingen') diff --git a/ingen/Configuration.hpp b/ingen/Configuration.hpp index bc04ecba..0ede7059 100644 --- a/ingen/Configuration.hpp +++ b/ingen/Configuration.hpp @@ -112,10 +112,20 @@ public: } _val; }; - Configuration& add(const std::string& name, + /** Add a configuration option. + * + * @param key URI local name, in camelCase + * @param name Long option name (without leading "--") + * @param letter Short option name (without leading "-") + * @param desc Description + * @param type Type + * @param value Default value + */ + Configuration& add(const std::string& key, + const std::string& name, char letter, const std::string& desc, - OptionType type, + const OptionType type, const Value& value); void print_usage(const std::string& program, std::ostream& os); @@ -126,6 +136,18 @@ public: void parse(int argc, char** argv) throw (CommandLineError); + /** Load a specific file. */ + bool load(const std::string& path); + + /** Load files from the standard configuration directories for the app. + * + * The system configuration file(s), e.g. /etc/xdg/appname/filename, + * will be loaded before the user's, e.g. ~/.config/appname/filename, + * so the user options will override the system options. + */ + std::list load_default(const std::string& app, + const std::string& file); + void print(std::ostream& os, const std::string mime_type="text/plain") const; const Value& option(const std::string& long_name) const; @@ -138,14 +160,13 @@ private: public: Option(const std::string& n, char l, const std::string& d, const OptionType type, const Value& def) - : name(n), letter(l), desc(d), type(type), default_value(def), value(def) + : name(n), letter(l), desc(d), type(type), value(def) {} std::string name; char letter; std::string desc; OptionType type; - Value default_value; Value value; }; @@ -155,9 +176,10 @@ private: } }; - typedef std::map Options; - typedef std::map ShortNames; - typedef std::list Files; + typedef std::map Options; + typedef std::map ShortNames; + typedef std::map Keys; + typedef std::list Files; int set_value_from_string(Configuration::Option& option, const std::string& value) throw (Configuration::CommandLineError); @@ -165,6 +187,7 @@ private: const std::string _shortdesc; const std::string _desc; Options _options; + Keys _keys; ShortNames _short_names; Files _files; size_t _max_name_length; -- cgit v1.2.1