Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s)
if (previous == this) return;
if (previous)
previous->l_slaves.remove(s);
l_slaves.add(s);
l_slaves.add(s.get());
if (previous)
this->getContext()->notifyMoveSlave(previous.get(), this, s.get());
else
Expand Down
2 changes: 2 additions & 0 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class SOFA_CORE_API BaseLink

/// Add a new target to the link.
bool add(Base* baseptr, const std::string& path) { return _doAdd_(baseptr, path); }
bool add(Base* baseptr) { return _doAdd_(baseptr); }

/// Change the link's target at the provided index.
bool set(Base* baseptr, size_t index=0) { return _doSet_(baseptr, index); }
Expand All @@ -181,6 +182,7 @@ class SOFA_CORE_API BaseLink
virtual void _doSetOwner_(Base* owner) = 0;
virtual Base* _doGet_(const size_t=0) const = 0;
virtual bool _doAdd_(Base* target, const std::string&) = 0;
virtual bool _doAdd_(Base*) = 0;
virtual void _doClear_() = 0;
virtual std::string _doGetLinkedPath_(const size_t=0) const = 0;

Expand Down
52 changes: 28 additions & 24 deletions Sofa/framework/Core/src/sofa/core/objectmodel/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,27 +377,6 @@ class TLink : public BaseLink
return true;
}

bool add(DestPtr v)
{
if (!v)
return false;
const std::size_t index = TraitsContainer::add(m_value,v);
updateCounter();
added(v, index);
return true;
}

bool add(DestPtr v, const std::string& path)
{
if (!v && path.empty())
return false;
std::size_t index = TraitsContainer::add(m_value,v);
TraitsValueType::setPath(m_value[index],path);
updateCounter();
added(v, index);
return true;
}

bool addPath(const std::string& path)
{
if (path.empty())
Expand Down Expand Up @@ -503,7 +482,32 @@ class TLink : public BaseLink
}

/// TLink:adding accepts nullptr (for a not yet resolved link).
return TLink::add(destptr, path);
std::size_t index = TraitsContainer::add(m_value, destptr);
TraitsValueType::setPath(m_value[index], path);
updateCounter();
added(destptr, index);
return true;
}

bool _doAdd_(Base* baseptr) override
{
/// If the pointer is null and the path empty we do nothing
if(!baseptr)
return false;

/// Downcast the pointer to a compatible type and
/// If the types are not compatible with the Link we returns false
auto destptr = castTo<DestType*>(baseptr);
if(!destptr)
{
return false;
}

/// TLink:adding accepts nullptr (for a not yet resolved link).
const std::size_t index = TraitsContainer::add(m_value, destptr);
updateCounter();
added(destptr, index);
return true;;
}

/// Returns false on type mismatch
Expand Down Expand Up @@ -577,7 +581,7 @@ class MultiLink : public TLink<TOwnerType,TDestType,TFlags|BaseLink::FLAG_MULTIL
MultiLink(const BaseLink::InitLink<OwnerType>& init, DestPtr val)
: Inherit(init), m_validator(nullptr)
{
if (val) this->add(val);
if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val)));
}

virtual ~MultiLink()
Expand Down Expand Up @@ -654,7 +658,7 @@ class SingleLink : public TLink<TOwnerType,TDestType,TFlags&~BaseLink::FLAG_MULT
SingleLink(const BaseLink::InitLink<OwnerType>& init, DestPtr val)
: Inherit(init), m_validator(nullptr)
{
if (val) this->add(val);
if (val) this->_doAdd_(sofa::core::castToBase(TraitsDestPtr::get(val)));
}

virtual ~SingleLink()
Expand Down
4 changes: 2 additions & 2 deletions Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ bool Node::doAddObject(sofa::core::objectmodel::BaseComponent::SPtr sobj, sofa::
{
this->setObjectContext(sobj);
if(insertionLocation == sofa::core::objectmodel::TypeOfInsertion::AtEnd)
object.add(sobj);
object.add(sobj.get());
else
object.addBegin(sobj);

Expand Down Expand Up @@ -1175,7 +1175,7 @@ void Node::doAddChild(BaseNode::SPtr node)
{
const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast<Node>(node);
setDirtyDescendancy();
child.add(dagnode);
child.add(dagnode.get());
dagnode->l_parents.add(this);
dagnode->l_parents.updateLinks(); // to fix load-time unresolved links
}
Expand Down