| 189 | |
| 190 | template <typename T> |
| 191 | T optValue(const std::string & key, const T & def) const |
| 192 | /// Returns the value of a property when the property exists |
| 193 | /// and can be converted to the given type. Otherwise |
| 194 | /// def will be returned. |
| 195 | { |
| 196 | T value = def; |
| 197 | ValueMap::const_iterator it = _values.find(key); |
| 198 | if (it != _values.end() && !it->second.isEmpty()) |
| 199 | { |
| 200 | try |
| 201 | { |
| 202 | value = it->second.convert<T>(); |
| 203 | } |
| 204 | catch (...) |
| 205 | { |
| 206 | // The default value will be returned |
| 207 | } |
| 208 | } |
| 209 | return value; |
| 210 | } |
| 211 | |
| 212 | std::size_t size() const; |
| 213 | /// Returns the number of properties. |