29 #include <boost/format.hpp>
30 #include <boost/algorithm/string.hpp>
32 #include "../runtime/ContainerIO.h"
36 using namespace boost;
38 using namespace rsc::logging;
44 string trim(
const string& s) {
45 string::size_type n, n2;
46 n = s.find_first_not_of(
" \t\r\n");
47 if (n == string::npos) {
50 n2 = s.find_last_not_of(
" \t\r\n");
51 return s.substr(n, n2 - n + 1);
55 ConfigFileSource::ConfigFileSource(istream& stream) :
56 logger(
Logger::getLogger(
"rsc.config.ConfigFileSource")), stream(stream) {
64 split(key, name, is_any_of(
"."));
75 for (map<vector<string>,
string>::const_iterator it =
options.begin();
84 while (getline(this->
stream, line)) {
87 size_t rPos = line.find(
'\r');
88 if (rPos != line.npos && rPos != 0 && rPos != line.size() - 1) {
89 throw invalid_argument(
"Old Mac EOL style '\\r' is not supported.");
94 if ((n = line.find(
'#')) != string::npos)
95 line = line.substr(0, n);
100 if (*line.begin() ==
'[' && *line.rbegin() ==
']') {
105 }
else if ((n = line.find(
'=')) != string::npos) {
107 value =
trim(line.substr(n + 1));
110 throw invalid_argument(
111 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 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
logging::LoggerPtr logger
bool getOption(std::string &name, std::string &value)
Interface for logging adapters that can be used with RSC.