RSC
0.16.0
|
Classes | |
class | CollectingOptionHandler |
An OptionHandler which collects the options in an instance of Properties. More... | |
class | CommandLinePropertySource |
A source for options from the command line using a -D java properties-like syntax. More... | |
class | ConfigFileSource |
Objects of this class parse streams that contain configuration information in "ini-file" syntax. More... | |
class | ConfigSource |
Implementations of this interface obtain configuration information somewhere and pass individual configuration options to an OptionHandler instance. More... | |
class | EnvironmentVariableSource |
Objects of this class analyze the environment of the current process, finding environment variables whose name starts with a specified string. More... | |
class | OptionHandler |
Implementations of this interface receive options from ConfigSource objects. More... | |
class | PropertyHandler |
This implementation of the OptionHandler interface stores all options it receives into a runtime::Properties object. More... | |
Functions | |
string | trim (const string &s) |
LoggerPtr | getLogger () |
std::vector< std::string > | defaultConfigurationFiles (const std::string &fileVariableName) |
std::pair< boost::filesystem::path, std::string > | resolveConfigurationFile (const std::string &spec, const boost::filesystem::path &prefix, const std::string &configFileName) |
Return a pair of configuration file path and description derived from spec. More... | |
void | describeFileStream (const std::string &label, const boost::filesystem::path &path, const istream &stream) |
void | processConfigFile (unsigned int index, const std::string &spec, const boost::filesystem::path &prefix, const std::string &configFileName, bool debug, OptionHandler &handler) |
void | configure (OptionHandler &handler, const std::string &configFileName, const std::string &environmentVariablePrefix, int argc=0, const char **argv=0, bool stripEnvironmentVariablePrefix=true, const boost::filesystem::path &prefix="/", const std::string &debugVariableName=DEFAULT_DEBUG_VARIABLE_NAME, const std::vector< std::string > &configurationFiles=defaultConfigurationFiles()) |
Pass configuration options in from configuration files derived from configFileName and environment variables with prefix environmentVariablePrefix to handler. More... | |
path | systemConfigDirectory () |
Return the directory in which system-wide configuration files are located. More... | |
path | prefixConfigDirectory (const path &prefix) |
path | userHomeDirectory () |
Return the home directory of the user associated with the current process. More... | |
path | userConfigDirectory () |
Return the canonical directory for configuration files of the user associated with the current process. More... | |
boost::shared_ptr< std::string > | getEnvironmentVariable (const std::string &name) |
Return the value of the environment value name or an empty pointer. More... | |
string | transformName (const string &name, const string &prefix, const bool &stripPrefix) |
RSC_EXPORT boost::filesystem::path | prefixConfigDirectory (const boost::filesystem::path &prefix=RSC_INSTALL_PREFIX) |
Return the directory in which prefix-wide configuration files are located. More... | |
vector< string > | splitSequenceValue (const string &value) |
vector< string > | mergeSequenceValue (const string &description, const vector< string > &key, const string &raw, const vector< string > &previous) |
Variables | |
const std::string | DEFAULT_DEBUG_VARIABLE_NAME = "__CONFIG_DEBUG" |
const std::string | DEFAULT_FILE_VARIABLE_NAME = "__CONFIG_FILES" |
const std::string | CONFIG_FILE_KEY_PREFIX = "%prefix" |
const std::string | CONFIG_FILE_KEY_USER = "%user" |
const std::string | CONFIG_FILE_KEY_PWD = "%pwd" |
void RSC_EXPORT rsc::config::configure | ( | OptionHandler & | handler, |
const std::string & | configFileName, | ||
const std::string & | environmentVariablePrefix, | ||
int | argc = 0 , |
||
const char ** | argv = 0 , |
||
bool | stripEnvironmentVariablePrefix = true , |
||
const boost::filesystem::path & | prefix = "/" , |
||
const std::string & | debugVariableName = DEFAULT_DEBUG_VARIABLE_NAME , |
||
const std::vector< std::string > & | configurationFiles = defaultConfigurationFiles() |
||
) |
Pass configuration options in from configuration files derived from configFileName and environment variables with prefix environmentVariablePrefix to handler.
The following configuration configuration sources are considered based on configFileName:
/usr/local/etc/
) to configFileName $HOME/
.config) to configFileName
) to configFileName See #ConfigFileSource for the configuration file format.
Setting the environment variable __CONFIG_DEBUG
to an arbitrary value enables configuration debugging. All debug output is written to stderr
.
handler | Receiver of the configuration options. |
configFileName | A filename (without directory) from which three configuration file names are derived. |
environmentVariablePrefix | A prefix string with which all processed environment variables have to start. |
argc | number of arguments passed to the main program. If 0, no command line argument parsing will be performed. If something else is specified, ensure that |
argv | matches the argc. Defaults to 0, so no argument parsing. |
argv | argument vector for command line parsing. Must match the length given in argc. Might be an arbitrary pointer of argc i 0. |
stripEnvironmentVariablePrefix | if true, the prefix for environment variable will be stripped before passing options to the handler. If e.g. RSC_ is set as prefix and this is true, RSC_TEST will be passed to the handlers as just TEST. Default is true. |
prefix | the (installation) prefix for which the prefix configuration directory should be computed (by calling prefixConfigDirectory) when searching for a prefix-wide configuration file. |
directories |
Definition at line 144 of file Configuration.cpp.
References getEnvironmentVariable(), rsc::config::EnvironmentVariableSource::getMatches(), processConfigFile(), rsc::config::CommandLinePropertySource::provideOptions(), and rsc::config::EnvironmentVariableSource::provideOptions().
std::vector< std::string > RSC_EXPORT rsc::config::defaultConfigurationFiles | ( | const std::string & | fileVariableName | ) |
Definition at line 67 of file Configuration.cpp.
References getEnvironmentVariable(), and splitSequenceValue().
void rsc::config::describeFileStream | ( | const std::string & | label, |
const boost::filesystem::path & | path, | ||
const istream & | stream | ||
) |
Definition at line 101 of file Configuration.cpp.
Referenced by processConfigFile().
RSC_EXPORT boost::shared_ptr< std::string > rsc::config::getEnvironmentVariable | ( | const std::string & | name | ) |
Return the value of the environment value name or an empty pointer.
Definition at line 104 of file Environment.cpp.
Referenced by configure(), and defaultConfigurationFiles().
LoggerPtr rsc::config::getLogger | ( | ) |
Definition at line 60 of file Configuration.cpp.
Referenced by processConfigFile().
std::vector< std::string > rsc::config::mergeSequenceValue | ( | const string & | description, |
const vector< string > & | key, | ||
const string & | raw, | ||
const vector< string > & | previous | ||
) |
Definition at line 47 of file Utility.cpp.
References std::container_none, std::element_sequence(), and splitSequenceValue().
Referenced by rsc::plugins::Configurator::handleOption().
path rsc::config::prefixConfigDirectory | ( | const path & | prefix | ) |
Definition at line 64 of file Environment.cpp.
References systemConfigDirectory().
Referenced by resolveConfigurationFile().
RSC_EXPORT boost::filesystem::path rsc::config::prefixConfigDirectory | ( | const boost::filesystem::path & | prefix = RSC_INSTALL_PREFIX | ) |
Return the directory in which prefix-wide configuration files are located.
prefix | the prefix for which the path shall be located. |
void rsc::config::processConfigFile | ( | unsigned int | index, |
const std::string & | spec, | ||
const boost::filesystem::path & | prefix, | ||
const std::string & | configFileName, | ||
bool | debug, | ||
OptionHandler & | handler | ||
) |
Definition at line 108 of file Configuration.cpp.
References describeFileStream(), getLogger(), rsc::config::ConfigFileSource::provideOptions(), resolveConfigurationFile(), and RSCWARN.
Referenced by configure().
std::pair< boost::filesystem::path, std::string > RSC_EXPORT rsc::config::resolveConfigurationFile | ( | const std::string & | spec, |
const boost::filesystem::path & | prefix, | ||
const std::string & | configFileName | ||
) |
Return a pair of configuration file path and description derived from spec.
If spec is one of CONFIG_FILE_KEY_PREFIX, CONFIG_FILE_KEY_USER or CONFIG_FILE_KEY_PWD, configFileName and potentially prefix are used to derive a prefix-wide, user-specific or pwd-relative configuration file path.
Otherwise spec is treated as a filename and returned.
Definition at line 81 of file Configuration.cpp.
References rsc::patterns::detail::make_pair(), prefixConfigDirectory(), and userConfigDirectory().
Referenced by processConfigFile().
std::vector< std::string > rsc::config::splitSequenceValue | ( | const string & | value | ) |
Definition at line 39 of file Utility.cpp.
Referenced by defaultConfigurationFiles(), and mergeSequenceValue().
RSC_EXPORT boost::filesystem::path rsc::config::systemConfigDirectory | ( | ) |
Return the directory in which system-wide configuration files are located.
Definition at line 56 of file Environment.cpp.
Referenced by prefixConfigDirectory().
string rsc::config::transformName | ( | const string & | name, |
const string & | prefix, | ||
const bool & | stripPrefix | ||
) |
Definition at line 114 of file Environment.cpp.
Referenced by rsc::config::EnvironmentVariableSource::getMatches().
string rsc::config::trim | ( | const string & | s | ) |
Definition at line 46 of file ConfigFileSource.cpp.
Referenced by rsc::config::ConfigFileSource::getOption().
RSC_EXPORT boost::filesystem::path rsc::config::userConfigDirectory | ( | ) |
Return the canonical directory for configuration files of the user associated with the current process.
std::runtime_error | if no config directory for the user is available |
Definition at line 100 of file Environment.cpp.
References userHomeDirectory().
Referenced by resolveConfigurationFile().
RSC_EXPORT boost::filesystem::path rsc::config::userHomeDirectory | ( | ) |
Return the home directory of the user associated with the current process.
std::runtime_error | if no home directory for the user is available |
Definition at line 79 of file Environment.cpp.
Referenced by userConfigDirectory().
RSC_EXPORT const std::string rsc::config::CONFIG_FILE_KEY_PREFIX = "%prefix" |
Definition at line 56 of file Configuration.cpp.
RSC_EXPORT const std::string rsc::config::CONFIG_FILE_KEY_PWD = "%pwd" |
Definition at line 58 of file Configuration.cpp.
RSC_EXPORT const std::string rsc::config::CONFIG_FILE_KEY_USER = "%user" |
Definition at line 57 of file Configuration.cpp.
RSC_EXPORT const std::string rsc::config::DEFAULT_DEBUG_VARIABLE_NAME = "__CONFIG_DEBUG" |
Definition at line 52 of file Configuration.cpp.
RSC_EXPORT const std::string rsc::config::DEFAULT_FILE_VARIABLE_NAME = "__CONFIG_FILES" |
Definition at line 54 of file Configuration.cpp.