RSC  0.17.1
rsc::config Namespace Reference

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"
 

Function Documentation

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:

  1. Prepending a prefix-wide configuration directory, computed by applying prefixConfigDirectory to the value of the prefix parameter, (e.g. /usr/local/etc/) to configFileName
  2. Prepending a user-specific configuration directory (e.g. $HOME/.config) to configFileName
  3. Prepending the current working directory () to configFileName
  4. Environment Variables

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.

Parameters
handlerReceiver of the configuration options.
configFileNameA filename (without directory) from which three configuration file names are derived.
environmentVariablePrefixA prefix string with which all processed environment variables have to start.
argcnumber of arguments passed to the main program. If 0, no command line argument parsing will be performed. If something else is specified, ensure that
argvmatches the argc. Defaults to 0, so no argument parsing.
argvargument vector for command line parsing. Must match the length given in argc. Might be an arbitrary pointer of argc i 0.
stripEnvironmentVariablePrefixif 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.
prefixthe (installation) prefix for which the prefix configuration directory should be computed (by calling prefixConfigDirectory) when searching for a prefix-wide configuration file.
directories
Author
jmoringe

Definition at line 144 of file Configuration.cpp.

References getEnvironmentVariable(), rsc::config::EnvironmentVariableSource::getMatches(), processConfigFile(), rsc::config::CommandLinePropertySource::provideOptions(), and rsc::config::EnvironmentVariableSource::provideOptions().

Here is the call graph for this function:

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().

Here is the call graph for this function:

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().

Here is the caller graph for this function:

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.

Returns
A boost::shared_ptr that is null if there is no environment variable named name and holds the value of the environment variable otherwise.
Author
jmoringe

Definition at line 104 of file Environment.cpp.

Referenced by configure(), and defaultConfigurationFiles().

Here is the caller graph for this function:

LoggerPtr rsc::config::getLogger ( )

Definition at line 60 of file Configuration.cpp.

Referenced by processConfigFile().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

path rsc::config::prefixConfigDirectory ( const path &  prefix)

Definition at line 64 of file Environment.cpp.

References systemConfigDirectory().

Referenced by resolveConfigurationFile().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
prefixthe prefix for which the path shall be located.
Returns
A boost::filesystem::path object representing the prefix configuration directory.
Author
jwienke
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::string > rsc::config::splitSequenceValue ( const string &  value)

Definition at line 39 of file Utility.cpp.

Referenced by defaultConfigurationFiles(), and mergeSequenceValue().

Here is the caller graph for this function:

RSC_EXPORT boost::filesystem::path rsc::config::systemConfigDirectory ( )

Return the directory in which system-wide configuration files are located.

Returns
A boost::filesystem::path object representing the system configuration directory.
Author
jmoringe

Definition at line 56 of file Environment.cpp.

Referenced by prefixConfigDirectory().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

string rsc::config::trim ( const string &  s)

Definition at line 46 of file ConfigFileSource.cpp.

Referenced by rsc::config::ConfigFileSource::getOption().

Here is the caller graph for this function:

RSC_EXPORT boost::filesystem::path rsc::config::userConfigDirectory ( )

Return the canonical directory for configuration files of the user associated with the current process.

Returns
A boost::filesystem::path object representing the configuration directory of the user.
Exceptions
std::runtime_errorif no config directory for the user is available
Author
jmoringe

Definition at line 100 of file Environment.cpp.

References userHomeDirectory().

Referenced by resolveConfigurationFile().

Here is the call graph for this function:

Here is the caller graph for this function:

RSC_EXPORT boost::filesystem::path rsc::config::userHomeDirectory ( )

Return the home directory of the user associated with the current process.

Returns
A boost::filesystem::path object representing the home directory of the user.
Exceptions
std::runtime_errorif no home directory for the user is available
Author
jmoringe

Definition at line 79 of file Environment.cpp.

Referenced by userConfigDirectory().

Here is the caller graph for this function:

Variable Documentation

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.