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/";
75 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 for (environment_iterator it = environment_iterator(environ); it
106 != environment_iterator(); ++it) {
107 if (it->first == name) {
108 return boost::shared_ptr<string>(
new string(it->second));
111 return boost::shared_ptr<string>();
115 const bool& stripPrefix) {
116 if (starts_with(name, prefix)) {
118 string::const_iterator start = name.begin();
120 start = start + prefix.size();
122 transform(start, name.end(), back_inserter(result), &::tolower);
129 EnvironmentVariableSource::Match::Match(
const string& rawName,
130 const string& transformedName,
132 : rawName(rawName), transformedName(transformedName), value(value) {
150 prefix), stripPrefix(stripPrefix) {
156 for (environment_iterator it = environment_iterator(environ); it
157 != environment_iterator(); ++it) {
158 string name =
transformName(it->first, this->prefix, this->stripPrefix);
162 this->
matches->push_back(
Match(it->first, name, it->second));
170 for (Matches::const_iterator it = matches.begin();
171 it != matches.end(); ++it) {
173 split(key, it->getTransformedName(), is_any_of(
"_"));
174 const string& value = it->getValue();
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...
Matches getMatches()
Return matching environment variables.
Implementations of this interface receive options from ConfigSource objects.
std::vector< Match > Matches
boost::shared_ptr< std::string > getEnvironmentVariable(const std::string &name)
Return the value of the environment value name or an empty pointer.
path systemConfigDirectory()
Return the directory in which system-wide configuration files are located.
path prefixConfigDirectory(const path &prefix)
const std::string & getRawName() const
#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.
const std::string & getValue() const
boost::shared_ptr< Matches > matches
path userHomeDirectory()
Return the home directory of the user associated with the current process.
std::string transformedName
Interface for logging adapters that can be used with RSC.
EnvironmentVariableSource(const std::string &prefix="", const bool &stripPrefix=true)
Construct a source that collect environment variables whose name starts with prefix.
const std::string & getTransformedName() const