25 #include <boost/lexical_cast.hpp>
43 explicit Pair(std::string s) : key(std::move(s)), val() {}
44 Pair(std::string s,
const RDValue &v) : key(std::move(s)), val(v) {}
49 Dict() : _data(), _hasNonPodData(false){};
52 _hasNonPodData = other._hasNonPodData;
53 if (other._hasNonPodData) {
54 std::vector<Pair> data(other._data.size());
56 for (
size_t i = 0; i < _data.size(); ++i) {
57 _data[i].key = other._data[i].key;
67 void update(
const Dict &other,
bool preserveExisting =
false) {
68 if (!preserveExisting) {
71 if (other._hasNonPodData) _hasNonPodData =
true;
72 for (
size_t i = 0; i < other._data.size(); ++i) {
73 const Pair &pair = other._data[i];
75 for (
size_t i = 0; i < _data.size(); ++i) {
76 if (_data[i].key == pair.
key) {
84 _data.push_back(
Pair(pair.
key));
95 if (
this == &other)
return *
this;
96 if (_hasNonPodData) reset();
98 if (other._hasNonPodData) {
99 std::vector<Pair> data(other._data.size());
101 for (
size_t i = 0; i < _data.size(); ++i) {
102 _data[i].key = other._data[i].key;
108 _hasNonPodData = other._hasNonPodData;
126 bool hasVal(
const std::string &what)
const {
127 for (
const auto &data : _data) {
128 if (data.key == what)
return true;
140 DataType::const_iterator item;
141 for (item = _data.begin(); item != _data.end(); item++) {
142 res.push_back(item->key);
160 template <
typename T>
161 void getVal(
const std::string &what, T &res)
const {
162 res = getVal<T>(what);
165 template <
typename T>
166 T
getVal(
const std::string &what)
const {
167 for (
auto &data : _data) {
168 if (data.key == what) {
169 return from_rdvalue<T>(data.val);
176 void getVal(
const std::string &what, std::string &res)
const;
193 template <
typename T>
195 for (
const auto &data : _data) {
196 if (data.key == what) {
197 res = from_rdvalue<T>(data.val);
205 bool getValIfPresent(
const std::string &what, std::string &res)
const;
220 template <
typename T>
221 void setVal(
const std::string &what, T &val) {
222 _hasNonPodData =
true;
223 for (
auto &&data : _data) {
224 if (data.key == what) {
230 _data.push_back(
Pair(what, val));
233 template <
typename T>
236 for (
auto &&data : _data) {
237 if (data.key == what) {
243 _data.push_back(
Pair(what, val));
246 void setVal(
const std::string &what,
bool val) { setPODVal(what, val); }
248 void setVal(
const std::string &what,
double val) { setPODVal(what, val); }
250 void setVal(
const std::string &what,
float val) { setPODVal(what, val); }
252 void setVal(
const std::string &what,
int val) { setPODVal(what, val); }
254 void setVal(
const std::string &what,
unsigned int val) {
255 setPODVal(what, val);
259 void setVal(
const std::string &what,
const char *val) {
276 for (DataType::iterator it = _data.begin(); it < _data.end(); ++it) {
277 if (it->key == what) {
278 if (_hasNonPodData) {
292 if (_hasNonPodData) {
293 for (
auto &&data : _data) {
335 const std::string &what)
const;