35 #if defined(__APPLE__) && defined(__DYNAMIC__) 36 #include <crt_externs.h> 37 #define environ (*_NSGetEnviron()) 40 #include <boost/algorithm/string.hpp> 41 #include <boost/program_options.hpp> 42 #include <boost/program_options/environment_iterator.hpp> 48 using namespace boost;
69 if (prefix ==
"/usr") {
72 return prefix /
"etc/";
81 char* rawHome = getenv(
"HOME");
83 throw runtime_error(
"Home directory not defined in HOME variable.");
85 string home = string(rawHome) + string(
"/");
87 char* rawHomeDrive = getenv(
"HOMEDRIVE");
89 throw runtime_error(
"HOMEDRIVE variable not set.");
91 char* rawHomePath = getenv(
"HOMEPATH");
93 throw runtime_error(
"HOMEPATH variable not set.");
95 string home = string(rawHomeDrive) + string(rawHomePath) + string(
"\\");
105 const bool& stripPrefix) {
106 if (starts_with(name, prefix)) {
108 string::const_iterator start = name.begin();
110 start = start + prefix.size();
112 transform(start, name.end(), back_inserter(result), &::tolower);
119 EnvironmentVariableSource::EnvironmentVariableSource(
const string& prefix,
120 const bool& stripPrefix) :
121 logger(
Logger::
getLogger(
"rsc.config.EnvironmentVariableSource")), prefix(
122 prefix), stripPrefix(stripPrefix) {
126 for (environment_iterator it = environment_iterator(environ); it
127 != environment_iterator(); ++it) {
128 string name =
transformName(it->first, this->prefix, this->stripPrefix);
134 split(key, name, is_any_of(
"_"));
135 string value = it->second;
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.
string transformName(const string &name, const string &prefix, const bool &stripPrefix)
virtual void handleOption(const std::vector< std::string > &key, const std::string &value)=0
This method is called once for each individual option available from a given ConfigSource.
path userConfigDirectory()
Return the canonical directory for configuration files of the user associated with the current proces...
Implementations of this interface receive options from ConfigSource objects.
path systemConfigDirectory()
Return the directory in which system-wide configuration files are located.
path prefixConfigDirectory(const path &prefix)
#define RSCTRACE(logger, msg)
rsc::logging::LoggerPtr logger
Provides a hierarchical logging system with the possibility to install different backends, which are instances of LoggingSystem.
path userHomeDirectory()
Return the home directory of the user associated with the current process.
Interface for logging adapters that can be used with RSC.