3 #ifndef DUNE_PARAMETERTREE_HH
4 #define DUNE_PARAMETERTREE_HH
41 typedef std::vector<std::string>
KeyVector;
55 bool hasKey(
const std::string& key)
const;
65 bool hasSub(
const std::string&
sub)
const;
76 std::string&
operator[] (
const std::string& key);
88 const std::string&
operator[] (
const std::string& key)
const;
98 void report(std::ostream& stream = std::cout,
99 const std::string& prefix =
"")
const;
126 std::string
get(
const std::string& key,
const std::string& defaultValue)
const;
138 std::string
get(
const std::string& key,
const char* defaultValue)
const;
149 int get(
const std::string& key,
int defaultValue)
const;
160 double get(
const std::string& key,
double defaultValue)
const;
173 T
get(
const std::string& key,
const T& defaultValue)
const {
189 T
get(
const std::string& key)
const {
198 (*
this)[key] <<
"\" for key \"" << key <<
"\" as a " <<
226 std::map<std::string, std::string>
values;
227 std::map<std::string, ParameterTree>
subs;
228 static std::string
ltrim(
const std::string& s);
229 static std::string
rtrim(
const std::string& s);
230 static std::vector<std::string>
split(
const std::string & s);
233 template<
class Iterator>
235 Iterator it,
const Iterator &end)
237 typedef typename std::iterator_traits<Iterator>::value_type Value;
238 std::istringstream s(str);
240 for(; it != end; ++it, ++n) {
244 "range of items of type " << className<Value>() <<
" "
245 "(" << n <<
" items were extracted successfully)");
250 if(not s.fail() or not s.eof())
252 "range of " << n <<
" items of type "
253 << className<Value>() <<
" (more items than the range "
260 static T
parse(
const std::string& str) {
262 std::istringstream s(str);
270 if(not s.fail() or not s.eof())
280 template<
typename traits,
typename Allocator>
282 static std::basic_string<char, traits, Allocator>
285 return std::basic_string<char, traits, Allocator>(trimmed.begin(),
293 int operator()(
int c)
295 return std::tolower(c);
301 std::string ret = str;
303 std::transform(ret.begin(), ret.end(), ret.begin(), ToLower());
305 if (ret ==
"yes" || ret ==
"true")
308 if (ret ==
"no" || ret ==
"false")
315 template<
typename T,
int n>
325 template<
typename T, std::
size_t n>
335 template<
typename T,
typename A>
337 static std::vector<T, A>
339 std::vector<std::string>
sub =
split(str);
340 std::vector<T, A> vec;
341 for (
unsigned int i=0; i<sub.size(); ++i) {
351 #endif // DUNE_PARAMETERTREE_HH