Skip to content
Snippets Groups Projects
Commit 257195e8 authored by armar-user's avatar armar-user
Browse files

fix error when adding NULL to dict

parent 9208d2e4
No related branches found
No related tags found
No related merge requests found
......@@ -161,6 +161,8 @@ namespace armarx::aron::data
void
Dict::addElement(const std::string& key, const VariantPtr& data)
{
// Please note that the data may be null (indicating that a non existing maybetype has been added)
if (hasElement(key))
{
ARMARX_TRACE;
......@@ -173,6 +175,8 @@ namespace armarx::aron::data
void
Dict::addElementCopy(const std::string& key, const VariantPtr& data)
{
// Please note that the data may be null (indicating that a non existing maybetype has been added)
if (hasElement(key))
{
ARMARX_TRACE;
......@@ -213,11 +217,16 @@ namespace armarx::aron::data
void
Dict::setElement(const std::string& key, const VariantPtr& data)
{
const auto& p = data->getPath();
if (not p.hasDirectPrefix(this->getPath()))
// Please note that the data may be null (indicating that a non existing maybetype has been added)
if (data)
{
ARMARX_WARNING << "An element added to a dict does not have a correct path set. This "
"may cause errors. Please use setElemetCopy() instead.";
const auto& p = data->getPath();
if (not p.hasDirectPrefix(this->getPath()))
{
ARMARX_WARNING << "An element added to a dict does not have a correct path set. This "
"may cause errors. Please use setElemetCopy() instead.";
}
}
this->childrenNavigators[key] = data;
......@@ -234,8 +243,14 @@ namespace armarx::aron::data
void
Dict::setElementCopy(const std::string& key, const VariantPtr& data)
{
Path newPath = getPath().withElement(key);
auto copy = data->cloneAsVariant(newPath);
// Please note that the data may be null (indicating that a non existing maybetype has been added)
VariantPtr copy = nullptr;
if (data)
{
Path newPath = getPath().withElement(key);
copy = data->cloneAsVariant(newPath);
}
setElement(key, copy);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment