14 #ifndef DICTIONARY_HPP
15 #define DICTIONARY_HPP
23 #include <type_traits>
30 template <
typename _Key=std::
string,
typename _Value=
unsigned int>
34 typedef std::map<_Key, _Value>
Items;
55 void setItem(
const _Key&
key,
const _Value& value);
60 template <
class _Other> _Other
cast(
void)
const;
61 template <
class _Other,
class _Arg> _Other
cast(_Arg arg)
const;
62 template <
class _Other>
void copy(_Other& other)
const;
82 (*this) = std::forward<Dictionary>(rhs);
98 items = std::move(rhs.getItems());
107 this->setItem((*iter).first, getItem((*iter).first)+(*iter).second);
114 if (std::is_arithmetic<_Value>::value && count)
118 (*iter).second /= count;
131 return (items.find(key) != end());
137 return (*iter).second;
142 return (isExist(key))?items[
key]:_Value();
152 items[
key] = std::move(std::forward<_Value>(value));
185 return items.begin();
190 return items.begin();
204 template <
typename _Key,
typename _Value>
207 static const char DELIMITER =
',';
240 std::stringstream ostr;
243 if (iter!=dictionary.begin())
245 ostr << (*iter).second;
258 std::string str(data);
259 std::replace(str.begin(), str.end(),
delimiter,
' ');
260 std::stringstream istr(str);
261 std::istream_iterator<std::string> iit(istr);
262 std::istream_iterator<std::string> eos;
264 unsigned int index = 0;
268 std::istringstream(std::to_string(++index)) >>
key;
270 std::istringstream(*iit) >> value;
272 dictionary.setItem(key, value);
281 #endif // DICTIONARY_HPP