3 #ifndef DUNE_PARAMETERTREE_HH
4 #define DUNE_PARAMETERTREE_HH
43 typedef std::vector<std::string>
KeyVector;
57 bool hasKey(
const std::string& key)
const;
67 bool hasSub(
const std::string&
sub)
const;
78 std::string&
operator[] (
const std::string& key);
90 const std::string&
operator[] (
const std::string& key)
const;
100 void report(std::ostream& stream = std::cout,
101 const std::string& prefix =
"")
const;
128 std::string
get(
const std::string& key,
const std::string& defaultValue)
const;
140 std::string
get(
const std::string& key,
const char* defaultValue)
const;
151 int get(
const std::string& key,
int defaultValue)
const;
162 double get(
const std::string& key,
double defaultValue)
const;
175 T
get(
const std::string& key,
const T& defaultValue)
const {
191 T
get(
const std::string& key)
const {
200 (*
this)[key] <<
"\" for key \"" << key <<
"\" as a " <<
228 std::map<std::string, std::string>
values;
229 std::map<std::string, ParameterTree>
subs;
230 static std::string
ltrim(
const std::string& s);
231 static std::string
rtrim(
const std::string& s);
232 static std::vector<std::string>
split(
const std::string & s);
235 template<
class Iterator>
237 Iterator it,
const Iterator &end)
239 typedef typename std::iterator_traits<Iterator>::value_type Value;
240 std::istringstream s(str);
242 for(; it != end; ++it, ++n) {
246 "range of items of type " << className<Value>() <<
" "
247 "(" << n <<
" items were extracted successfully)");
252 if(not s.fail() or not s.eof())
254 "range of " << n <<
" items of type "
255 << className<Value>() <<
" (more items than the range "
262 static T
parse(
const std::string& str) {
264 std::istringstream s(str);
272 if(not s.fail() or not s.eof())
282 template<
typename traits,
typename Allocator>
284 static std::basic_string<char, traits, Allocator>
287 return std::basic_string<char, traits, Allocator>(trimmed.begin(),
295 int operator()(
int c)
297 return std::tolower(c);
303 std::string ret = str;
305 std::transform(ret.begin(), ret.end(), ret.begin(), ToLower());
307 if (ret ==
"yes" || ret ==
"true")
310 if (ret ==
"no" || ret ==
"false")
317 template<
typename T,
int n>
327 template<
typename T, std::
size_t n>
337 template<
typename T,
typename A>
339 static std::vector<T, A>
341 std::vector<std::string>
sub =
split(str);
342 std::vector<T, A> vec;
343 for (
unsigned int i=0; i<sub.size(); ++i) {
353 #endif // DUNE_PARAMETERTREE_HH