31 #include <boost/format.hpp> 32 #include <boost/tokenizer.hpp> 34 #include "../runtime/ContainerIO.h" 38 using namespace boost;
46 string trim(
const string& s) {
47 string::size_type n, n2;
48 n = s.find_first_not_of(
" \t\r\n");
49 if (n == string::npos) {
52 n2 = s.find_last_not_of(
" \t\r\n");
53 return s.substr(n, n2 - n + 1);
57 ConfigFileSource::ConfigFileSource(istream& stream) :
58 logger(
Logger::
getLogger(
"rsc.config.ConfigFileSource")), stream(stream) {
86 for (map<vector<string>,
string>::const_iterator it =
options.begin();
95 while (getline(this->
stream, line)) {
98 size_t rPos = line.find(
'\r');
99 if (rPos != line.npos && rPos != 0 && rPos != line.size() - 1) {
100 throw invalid_argument(
"Old Mac EOL style '\\r' is not supported.");
105 if ((n = line.find(
'#')) != string::npos)
106 line = line.substr(0, n);
111 if (*line.begin() ==
'[' && *line.rbegin() ==
']') {
116 }
else if ((n = line.find(
'=')) != string::npos) {
118 value =
trim(line.substr(n + 1));
121 throw invalid_argument(
122 str(format(
"Syntax error in line `%1%'") % line));
string trim(const string &s)
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.
void splitKeyAtDots(const std::string &input, std::vector< std::string > &output)
Creates a key vector structure used in the options backend from a dot-separated string.
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.
Implementations of this interface receive options from ConfigSource objects.
std::string currentSection
#define RSCTRACE(logger, msg)
std::map< std::vector< std::string >, std::string > options
Provides a hierarchical logging system with the possibility to install different backends, which are instances of LoggingSystem.
logging::LoggerPtr logger
bool getOption(std::string &name, std::string &value)
Interface for logging adapters that can be used with RSC.