3 #ifndef DUNE_PARAMETERTREE_HH
4 #define DUNE_PARAMETERTREE_HH
44 typedef std::vector<std::string>
KeyVector;
58 bool hasKey(
const std::string& key)
const;
68 bool hasSub(
const std::string&
sub)
const;
79 std::string&
operator[] (
const std::string& key);
91 const std::string&
operator[] (
const std::string& key)
const;
101 void report(std::ostream& stream = std::cout,
102 const std::string& prefix =
"")
const;
129 std::string
get(
const std::string& key,
const std::string& defaultValue)
const;
141 std::string
get(
const std::string& key,
const char* defaultValue)
const;
152 int get(
const std::string& key,
int defaultValue)
const;
163 double get(
const std::string& key,
double defaultValue)
const;
176 T
get(
const std::string& key,
const T& defaultValue)
const {
192 T
get(
const std::string& key)
const {
201 (*
this)[key] <<
"\" for key \"" << key <<
"\" as a " <<
229 std::map<std::string, std::string>
values;
230 std::map<std::string, ParameterTree>
subs;
231 static std::string
ltrim(
const std::string& s);
232 static std::string
rtrim(
const std::string& s);
233 static std::vector<std::string>
split(
const std::string & s);
236 template<
class Iterator>
238 Iterator it,
const Iterator &end)
240 typedef typename std::iterator_traits<Iterator>::value_type Value;
241 std::istringstream s(str);
243 for(; it != end; ++it, ++n) {
247 "range of items of type " << className<Value>() <<
" "
248 "(" << n <<
" items were extracted successfully)");
253 if(not s.fail() or not s.eof())
255 "range of " << n <<
" items of type "
256 << className<Value>() <<
" (more items than the range "
263 static T
parse(
const std::string& str) {
265 std::istringstream s(str);
273 if(not s.fail() or not s.eof())
283 template<
typename traits,
typename Allocator>
285 static std::basic_string<char, traits, Allocator>
288 return std::basic_string<char, traits, Allocator>(trimmed.begin(),
296 int operator()(
int c)
298 return std::tolower(c);
304 std::string ret = str;
306 std::transform(ret.begin(), ret.end(), ret.begin(), ToLower());
308 if (ret ==
"yes" || ret ==
"true")
311 if (ret ==
"no" || ret ==
"false")
318 template<
typename T,
int n>
328 template<
typename T, std::
size_t n>
338 template<
typename T,
typename A>
340 static std::vector<T, A>
342 std::vector<std::string>
sub =
split(str);
343 std::vector<T, A> vec;
344 for (
unsigned int i=0; i<sub.size(); ++i) {
354 #endif // DUNE_PARAMETERTREE_HH