36
36
typedef std::map <std::string, std::string> param_map_t;
39
parse (param_map_t& list, const std::string& params) throw (Exception);
39
parse (param_map_t& list, const std::string& params);
41
41
/*! Convert string configuration values to other types.
42
42
* General template for integers, specialized templates follow below. */
43
43
template <typename T> static inline T
44
from_config (const std::string& value) throw (Exception)
44
from_config (const std::string& value)
46
46
const char* str = value.c_str();
63
Config (const std::string& params) throw (Exception);
63
Config (const std::string& params);
66
has (const std::string& key) const throw ()
66
has (const std::string& key) const
68
68
return (params_.find(key) != params_.end());
72
set (const std::string& key, const std::string& value) throw ()
72
set (const std::string& key, const std::string& value)
74
74
params_[key] = value;
78
set (const std::string& key, const char* value) throw ()
78
set (const std::string& key, const char* value)
80
80
params_[key] = value;
83
83
/* General template for integer types */
84
84
template <typename T> void
85
set (const std::string& key, T val) throw ()
85
set (const std::string& key, T val)
87
87
set_longlong (key, val);
90
/*! @throws NotFound */
91
get (const std::string& key) const throw (NotFound)
92
get (const std::string& key) const
93
94
param_map_t::const_iterator i = params_.find(key);
94
95
if (i == params_.end()) throw NotFound();
99
get (const std::string& key, const std::string& def) const throw (Exception)
100
get (const std::string& key, const std::string& def) const
101
102
try { return get(key); }
102
103
catch (NotFound&) { return def ; }
106
/*! @throws NotFound */
105
107
template <typename T> inline T
106
get (const std::string& key) const throw (NotFound, Exception)
108
get (const std::string& key) const
108
110
return from_config <T> (get(key));
111
113
template <typename T> inline T
112
get(const std::string& key, const T& def) const throw (Exception)
114
get(const std::string& key, const T& def) const
114
116
try { return get<T>(key); }
115
117
catch (NotFound&) { return def; }
118
const param_map_t& params () const throw() { return params_; }
120
const param_map_t& params () const { return params_; }
123
check_conversion (const char* ptr, const char* endptr, const char* type)
125
check_conversion (const char* ptr, const char* endptr, const char* type);
127
overflow_char(long long ret) throw (Exception);
128
overflow_char(long long ret);
130
overflow_short(long long ret) throw (Exception);
131
overflow_short(long long ret);
133
overflow_int(long long ret) throw (Exception);
134
overflow_int(long long ret);
135
136
void set_longlong (const std::string& key, long long value);
148
149
/*! Specialized templates for "funny" types */
150
151
template <> inline double
151
Config::from_config (const std::string& value) throw (Exception)
152
Config::from_config (const std::string& value)
153
154
const char* str = value.c_str();
186
187
template <> inline void
187
Config::set (const std::string& key, const void* value) throw ()
188
Config::set (const std::string& key, const void* value)
189
190
set (key, to_string<const void*>(value));
192
193
template <> inline void
193
Config::set (const std::string& key, double val) throw ()
194
Config::set (const std::string& key, double val)
195
196
set (key, to_string<double>(val));
198
199
template <> inline void
199
Config::set (const std::string& key, bool val) throw ()
200
Config::set (const std::string& key, bool val)
201
202
const char* val_str(val ? "YES" : "NO"); // YES/NO is most generic
202
203
set (key, val_str);