Commit 5e5ed3b1 authored by Martin Heistermann's avatar Martin Heistermann

Expose PropertyPtr use_count and use it to properly keep used properties during clear().

parent 15670d62
Pipeline #7414 passed with stage
in 3 minutes and 59 seconds
......@@ -57,7 +57,7 @@ public:
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
explicit BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
BaseProperty& operator=(const BaseProperty& _cpy) = delete;
......@@ -87,6 +87,9 @@ public:
virtual const std::string typeNameWrapper() const = 0;
/// return the PropertyPtr shared_ptr use count
virtual long use_count() const = 0;
protected:
virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0;
......
......@@ -105,6 +105,8 @@ public:
virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }
virtual long use_count() const { return ptr::shared_ptr<PropT>::use_count(); }
protected:
virtual void delete_multiple_entries(const std::vector<bool>& _tags);
......
......@@ -62,7 +62,7 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* remove it, since the resource manager is the
* only one who stores the property.
*/
if(resMan_ && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
if(resMan_ && !persistent() && use_count() == 2) {
resMan_->release_property(HandleT(handle().idx()));
}
}
......
......@@ -197,12 +197,18 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle&
template<class StdVecT>
void ResourceManager::clearVec(StdVecT& _vec) {
StdVecT newVec;
for (auto prop: _vec) {
prop->setResMan(nullptr);
delete prop;
if (prop->use_count() == 1) {
// No-one else holds a PropertyPtr to this object.
prop->setResMan(nullptr);
delete prop;
} else {
newVec.push_back(prop);
}
}
_vec.clear();
_vec = newVec;
updatePropHandles(_vec);
}
template<class StdVecT>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment