13 #ifndef mitkConfigFileReader_h
14 #define mitkConfigFileReader_h
35 std::string
Trim(std::string
const& source,
char const * delim =
" \t\r\n")
37 std::string result(source);
38 std::string::size_type index = result.find_last_not_of(delim);
39 if(index != std::string::npos)
40 result.erase(++index);
41 index = result.find_first_not_of(delim);
42 if(index != std::string::npos)
43 result.erase(0, index);
49 std::string
RemoveComment(std::string
const& source,
char const * delim =
"#;")
51 std::string result(source);
52 std::string::size_type index = result.find_first_of(delim);
53 if(index != std::string::npos)
54 result.erase(++index);
58 std::string
ListIndex(std::string
const& section,
unsigned int index)
const
60 std::stringstream stream;
61 stream << section <<
"/" << index;
62 std::string result = stream.str();
63 std::transform(result.begin(), result.end(), result.begin(), ::tolower);
67 std::string
ContentIndex(std::string
const& section, std::string
const& entry)
const
70 std::string result = section +
'/' + entry;
71 std::transform(result.begin(), result.end(), result.begin(), ::tolower);
77 std::string result = section;
78 std::transform(result.begin(), result.end(), result.begin(), ::tolower);
91 std::ifstream file(filePath.c_str());
101 std::string inSection;
102 bool inConfigSection =
true;
103 std::string::size_type posEqual;
104 while (std::getline(stream,line)) {
107 if (! line.length())
continue;
109 if (line[0] ==
'[') {
110 inConfigSection =
true;
111 inSection =
Trim(line.substr(1,line.find(
']')-1));
116 std::string address =
Trim(line.substr(1,line.find(
'}')-1));
119 inConfigSection =
false;
125 posEqual=line.find(
'=');
126 name =
Trim(line.substr(0,posEqual));
127 value =
Trim(line.substr(posEqual+1));
137 std::string
Value(std::string
const& section, std::string
const& entry)
const
141 throw std::string(
"Entry doesn't exist " + section +
"::"+ entry);
142 std::cout << section <<
"::" << entry <<
m_ConfigContent.find(index)->second << std::endl;
146 std::string
Value(
const std::string & section,
const std::string & entry,
const std::string& standard)
149 return Value(section, entry);
151 catch (
const std::string) {
153 std::cout << section <<
"::" << entry << standard <<
" (default)" << std::endl;
158 int IntValue(
const std::string & section,
const std::string & entry)
const
161 std::stringstream stream (
Value(section, entry));
166 int IntValue(
const std::string & section,
const std::string & entry,
int standard)
171 catch (
const std::string) {
172 std::stringstream stream;
175 std::cout << section <<
"::" << entry << stream.str() <<
"(default)" << std::endl;
180 std::vector<std::string>
Vector(std::string
const& section,
unsigned int index)
const
184 throw std::string(
"Entry doesn't exist " + section);
189 unsigned int ListSize(std::string
const& section)
const
193 throw std::string(
"Entry doesn't exist " + section);
198 unsigned int ListSize(std::string
const& section,
unsigned int standard)