fixed GH #1355: [JSON::Object] After copy-ctor, JSON::Object::_keys still points to keys in map of copied object

This commit is contained in:
Günter Obiltschnig 2016-08-27 10:54:35 +02:00
parent 4232d0b497
commit f9f4c54bc3
2 changed files with 23 additions and 1 deletions

View File

@ -303,6 +303,19 @@ inline std::size_t Object::size() const
inline void Object::remove(const std::string& key)
{
_values.erase(key);
if (_preserveInsOrder)
{
KeyPtrList::iterator it = _keys.begin();
KeyPtrList::iterator end = _keys.end();
for (; it != end; ++it)
{
if (key == **it)
{
_keys.erase(it);
break;
}
}
}
}

View File

@ -32,10 +32,19 @@ Object::Object(bool preserveInsertionOrder): _preserveInsOrder(preserveInsertion
Object::Object(const Object& copy) : _values(copy._values),
_keys(copy._keys),
_preserveInsOrder(copy._preserveInsOrder),
_pStruct(0)
{
if (_preserveInsOrder)
{
// need to update pointers in _keys to point to copied _values
for (KeyPtrList::const_iterator it = copy._keys.begin(); it != copy._keys.end(); ++it)
{
ValueMap::const_iterator itv = _values.find(**it);
poco_assert (itv != _values.end());
_keys.push_back(&itv->first);
}
}
}