Commit 15670d62 authored by Martin Heistermann's avatar Martin Heistermann

Simplify property destruction and do not keep non-persistent props around in clearVec().

parent e66a7d6a
Pipeline #7412 passed with stage
in 5 minutes and 17 seconds
......@@ -55,9 +55,9 @@ class BaseProperty {
public:
friend class ResourceManager;
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan), lock_(false) {}
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_), lock_(_cpy.lock_) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
BaseProperty& operator=(const BaseProperty& _cpy) = delete;
......@@ -95,17 +95,9 @@ protected:
virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0;
void lock() { lock_ = true; }
void unlock() { lock_ = false; }
bool locked() const { return lock_; }
void setResMan(ResourceManager &resMan) { resMan_ = &resMan;}
void setResMan(ResourceManager *resMan) { resMan_ = resMan;}
ResourceManager* resMan_;
bool lock_;
};
} // Namespace OpenVolumeMesh
......
......@@ -62,9 +62,8 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* remove it, since the resource manager is the
* only one who stores the property.
*/
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
if(resMan_ && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
resMan_->release_property(HandleT(handle().idx()));
unlock();
}
}
......
......@@ -82,7 +82,7 @@ ResourceManager &ResourceManager::operator=(ResourceManager &&other)
auto moveProps = [this](Properties &&src, Properties &dest) {
dest = std::move(src);
for (auto prop: dest) {
prop->setResMan(*this);
prop->setResMan(this);
}
};
moveProps(std::move(other.vertex_props_), vertex_props_);
......
......@@ -346,6 +346,9 @@ private:
template<class StdVecT>
void clearVec(StdVecT& _vec);
template<class StdVecT>
void updatePropHandles(StdVecT& _vec);
Properties vertex_props_;
Properties edge_props_;
......
......@@ -170,13 +170,11 @@ void ResourceManager::set_persistentT(PropT& _prop, bool _flag) {
template<class StdVecT>
void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) {
(*(_vec.begin() + _idx))->lock();
delete *(_vec.begin() + _idx);
auto prop_ptr = _vec[_idx];
prop_ptr->setResMan(nullptr);
delete prop_ptr;
_vec.erase(_vec.begin() + _idx);
size_t n = _vec.size();
for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle((int)i));
}
updatePropHandles(_vec);
}
template<class StdVecT>
......@@ -200,22 +198,20 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle&
template<class StdVecT>
void ResourceManager::clearVec(StdVecT& _vec) {
StdVecT newVec;
for(typename StdVecT::iterator it = _vec.begin();
it != _vec.end(); ++it) {
if(!(*it)->persistent()) {
#ifndef NDEBUG
std::cerr << "Keeping property \"" << (*it)->name()
<< "\" since it is still in use!" << std::endl;
#endif
(*it)->resize(0);
newVec.push_back(*it);
}
else
delete *it;
for (auto prop: _vec) {
prop->setResMan(nullptr);
delete prop;
}
_vec.clear();
}
_vec = newVec;
template<class StdVecT>
void ResourceManager::updatePropHandles(StdVecT &_vec)
{
size_t n = _vec.size();
for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle((int)i));
}
}
} // Namespace OpenVolumeMesh
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