Commit f833f9a7 authored by Mike Kremer's avatar Mike Kremer

Fixed persistency of properties.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@105 66977474-1d4b-4f09-8fe9-267525286df2
parent f25bee21
......@@ -69,10 +69,6 @@ public:
virtual const std::string& name() const = 0;
virtual void set_persistent() = 0;
virtual bool persistent() const = 0;
virtual void delete_element(size_t _idx) = 0;
virtual std::ostream& serialize(std::ostream& _ostr) const = 0;
......@@ -81,16 +77,6 @@ public:
protected:
virtual void set_non_persistent() = 0;
void set_master_copy(bool _b) { masterCopy_ = _b; }
bool master_copy() const { return masterCopy_; }
virtual void set_ref_count(unsigned int /*_c*/) = 0;
virtual unsigned int ref_count() const = 0;
virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0;
virtual OpenVolumeMeshHandle handle() const = 0;
......
......@@ -122,19 +122,11 @@ public:
/// Access the encapsulated dereferenced pointer
PropT& operator*();
virtual void set_persistent();
virtual bool persistent() const;
virtual void delete_element(size_t _idx);
protected:
virtual void set_non_persistent();
virtual void set_ref_count(unsigned int _c);
unsigned int counter() const { return h_->count_; }
virtual unsigned int ref_count() const;
protected:
virtual void set_handle(const OpenVolumeMeshHandle& _handle);
......
......@@ -61,8 +61,8 @@ PropertyPtr<PropT,HandleT>::PropertyPtr(const PropertyPtr<PropT,HandleT>& _cpy)
template <class PropT, class HandleT>
PropertyPtr<PropT,HandleT>::~PropertyPtr() {
if(--h_->count_ == 0 && !persistent()) {
if(!master_copy()) resMan_.released_property(handle_);
if(--h_->count_ == 0) {
resMan_.released_property(handle_);
delete h_;
}
}
......@@ -119,37 +119,11 @@ PropT& PropertyPtr<PropT,HandleT>::operator*() {
return *h_->ptr_;
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_persistent() {
h_->ptr_->set_persistent(true);
resMan_.set_persistent_copy(handle_);
}
template <class PropT, class HandleT>
bool PropertyPtr<PropT,HandleT>::persistent() const {
return h_->ptr_->persistent();
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) {
h_->ptr_->delete_element(_idx);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_non_persistent() {
h_->ptr_->set_persistent(false);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_ref_count(unsigned int _c) {
h_->count_ = _c;
}
template <class PropT, class HandleT>
unsigned int PropertyPtr<PropT,HandleT>::ref_count() const {
return h_->count_;
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) {
handle_.idx(_handle.idx());
......
......@@ -51,63 +51,41 @@ ResourceManager::ResourceManager() {
ResourceManager::~ResourceManager() {
// Delete all persistent properties
for(std::vector<BaseProperty*>::iterator it = vertex_props_.begin();
it != vertex_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
for(std::vector<BaseProperty*>::iterator it = persistent_vprops_.begin();
it != persistent_vprops_.end(); ++it) {
delete *it;
}
vertex_props_.clear();
for(std::vector<BaseProperty*>::iterator it = edge_props_.begin();
it != edge_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_vprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_eprops_.begin();
it != persistent_eprops_.end(); ++it) {
delete *it;
}
edge_props_.clear();
for(std::vector<BaseProperty*>::iterator it = halfedge_props_.begin();
it != halfedge_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_eprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_heprops_.begin();
it != persistent_heprops_.end(); ++it) {
delete *it;
}
halfedge_props_.clear();
for(std::vector<BaseProperty*>::iterator it = face_props_.begin();
it != face_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_heprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_fprops_.begin();
it != persistent_fprops_.end(); ++it) {
delete *it;
}
face_props_.clear();
for(std::vector<BaseProperty*>::iterator it = halfface_props_.begin();
it != halfface_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_fprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_hfprops_.begin();
it != persistent_hfprops_.end(); ++it) {
delete *it;
}
halfface_props_.clear();
for(std::vector<BaseProperty*>::iterator it = cell_props_.begin();
it != cell_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_hfprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_cprops_.begin();
it != persistent_cprops_.end(); ++it) {
delete *it;
}
cell_props_.clear();
for(std::vector<BaseProperty*>::iterator it = mesh_props_.begin();
it != mesh_props_.end(); ++it) {
(*it)->set_non_persistent();
(*it)->set_ref_count(1u);
persistent_cprops_.clear();
for(std::vector<BaseProperty*>::iterator it = persistent_mprops_.begin();
it != persistent_mprops_.end(); ++it) {
delete *it;
}
mesh_props_.clear();
persistent_mprops_.clear();
}
void ResourceManager::resize_vprops(unsigned int _nv) {
......@@ -262,32 +240,4 @@ void ResourceManager::released_property(MeshPropHandle _handle) {
}
}
void ResourceManager::set_persistent_copy(VertexPropHandle _handle) {
(*(vertex_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(EdgePropHandle _handle) {
(*(edge_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(HalfEdgePropHandle _handle) {
(*(halfedge_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(FacePropHandle _handle) {
(*(face_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(HalfFacePropHandle _handle) {
(*(halfface_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(CellPropHandle _handle) {
(*(cell_props_.begin() + _handle.idx()))->set_master_copy(true);
}
void ResourceManager::set_persistent_copy(MeshPropHandle _handle) {
(*(mesh_props_.begin() + _handle.idx()))->set_master_copy(true);
}
} // Namespace OpenVolumeMesh
......@@ -134,20 +134,6 @@ public:
void released_property(MeshPropHandle _handle);
void set_persistent_copy(VertexPropHandle _handle);
void set_persistent_copy(EdgePropHandle _handle);
void set_persistent_copy(HalfEdgePropHandle _handle);
void set_persistent_copy(FacePropHandle _handle);
void set_persistent_copy(HalfFacePropHandle _handle);
void set_persistent_copy(CellPropHandle _handle);
void set_persistent_copy(MeshPropHandle _handle);
unsigned int n_vertex_props() const { return vertex_props_.size(); }
unsigned int n_edge_props() const { return edge_props_.size(); }
......@@ -162,6 +148,20 @@ public:
unsigned int n_mesh_props() const { return mesh_props_.size(); }
template<class T> void set_persistent(VertexPropertyT<T>& _prop);
template<class T> void set_persistent(EdgePropertyT<T>& _prop);
template<class T> void set_persistent(HalfEdgePropertyT<T>& _prop);
template<class T> void set_persistent(FacePropertyT<T>& _prop);
template<class T> void set_persistent(HalfFacePropertyT<T>& _prop);
template<class T> void set_persistent(CellPropertyT<T>& _prop);
template<class T> void set_persistent(MeshPropertyT<T>& _prop);
private:
std::vector<BaseProperty*> vertex_props_;
......@@ -177,6 +177,20 @@ private:
std::vector<BaseProperty*> cell_props_;
std::vector<BaseProperty*> mesh_props_;
std::vector<BaseProperty*> persistent_vprops_;
std::vector<BaseProperty*> persistent_eprops_;
std::vector<BaseProperty*> persistent_heprops_;
std::vector<BaseProperty*> persistent_fprops_;
std::vector<BaseProperty*> persistent_hfprops_;
std::vector<BaseProperty*> persistent_cprops_;
std::vector<BaseProperty*> persistent_mprops_;
};
}
......
......@@ -53,13 +53,11 @@ namespace OpenVolumeMesh {
template<class T>
VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = vertex_props_.begin();
it != vertex_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
VertexPropertyT<T>* prop = dynamic_cast<VertexPropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_vprops_.begin();
it != persistent_vprops_.end(); ++it) {
if((*it)->name() == _name) {
VertexPropertyT<T>* prop = dynamic_cast<VertexPropertyT<T>* >(*it);
return *prop;
}
}
......@@ -82,13 +80,11 @@ VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _
template<class T>
EdgePropertyT<T> ResourceManager::request_edge_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = edge_props_.begin();
it != edge_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
EdgePropertyT<T>* prop = dynamic_cast<EdgePropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_eprops_.begin();
it != persistent_eprops_.end(); ++it) {
if((*it)->name() == _name) {
EdgePropertyT<T>* prop = dynamic_cast<EdgePropertyT<T>* >(*it);
return *prop;
}
}
......@@ -111,13 +107,11 @@ EdgePropertyT<T> ResourceManager::request_edge_property(const std::string& _name
template<class T>
HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = halfedge_props_.begin();
it != halfedge_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
HalfEdgePropertyT<T>* prop = dynamic_cast<HalfEdgePropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_heprops_.begin();
it != persistent_heprops_.end(); ++it) {
if((*it)->name() == _name) {
HalfEdgePropertyT<T>* prop = dynamic_cast<HalfEdgePropertyT<T>* >(*it);
return *prop;
}
}
......@@ -140,13 +134,11 @@ HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(const std::strin
template<class T>
FacePropertyT<T> ResourceManager::request_face_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = face_props_.begin();
it != face_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
FacePropertyT<T>* prop = dynamic_cast<FacePropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_fprops_.begin();
it != persistent_fprops_.end(); ++it) {
if((*it)->name() == _name) {
FacePropertyT<T>* prop = dynamic_cast<FacePropertyT<T>* >(*it);
return *prop;
}
}
......@@ -169,13 +161,11 @@ FacePropertyT<T> ResourceManager::request_face_property(const std::string& _name
template<class T>
HalfFacePropertyT<T> ResourceManager::request_halfface_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = halfface_props_.begin();
it != halfface_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
HalfFacePropertyT<T>* prop = dynamic_cast<HalfFacePropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_hfprops_.begin();
it != persistent_hfprops_.end(); ++it) {
if((*it)->name() == _name) {
HalfFacePropertyT<T>* prop = dynamic_cast<HalfFacePropertyT<T>* >(*it);
return *prop;
}
}
......@@ -198,13 +188,11 @@ HalfFacePropertyT<T> ResourceManager::request_halfface_property(const std::strin
template<class T>
CellPropertyT<T> ResourceManager::request_cell_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = cell_props_.begin();
it != cell_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
CellPropertyT<T>* prop = dynamic_cast<CellPropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_cprops_.begin();
it != persistent_cprops_.end(); ++it) {
if((*it)->name() == _name) {
CellPropertyT<T>* prop = dynamic_cast<CellPropertyT<T>* >(*it);
return *prop;
}
}
......@@ -227,13 +215,11 @@ CellPropertyT<T> ResourceManager::request_cell_property(const std::string& _name
template<class T>
MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name) {
for(std::vector<BaseProperty*>::iterator it = mesh_props_.begin();
it != mesh_props_.end(); ++it) {
if((*it)->persistent() && (*it)->name() == _name) {
MeshPropertyT<T>* prop = dynamic_cast<MeshPropertyT<T>*>(*it);
if(prop != NULL) {
return *prop;
}
for(std::vector<BaseProperty*>::iterator it = persistent_mprops_.begin();
it != persistent_mprops_.end(); ++it) {
if((*it)->name() == _name) {
MeshPropertyT<T>* prop = dynamic_cast<MeshPropertyT<T>* >(*it);
return *prop;
}
}
......@@ -253,4 +239,53 @@ MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name
return *prop;
}
template<class T>
void ResourceManager::set_persistent(VertexPropertyT<T>& _prop) {
VertexPropertyT<T>* prop = new VertexPropertyT<T>(_prop);
persistent_vprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(EdgePropertyT<T>& _prop) {
EdgePropertyT<T>* prop = new EdgePropertyT<T>(_prop);
persistent_eprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(HalfEdgePropertyT<T>& _prop) {
HalfEdgePropertyT<T>* prop = new HalfEdgePropertyT<T>(_prop);
persistent_heprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(FacePropertyT<T>& _prop) {
FacePropertyT<T>* prop = new FacePropertyT<T>(_prop);
persistent_fprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(HalfFacePropertyT<T>& _prop) {
HalfFacePropertyT<T>* prop = new HalfFacePropertyT<T>(_prop);
persistent_hfprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(CellPropertyT<T>& _prop) {
CellPropertyT<T>* prop = new CellPropertyT<T>(_prop);
persistent_cprops_.push_back(prop);
}
template<class T>
void ResourceManager::set_persistent(MeshPropertyT<T>& _prop) {
MeshPropertyT<T>* prop = new MeshPropertyT<T>(_prop);
persistent_mprops_.push_back(prop);
}
} // Namespace OpenVolumeMesh
......@@ -44,7 +44,7 @@ TEST_F(PolyhedralMeshBase, PropertySmartPointerTest1) {
EXPECT_EQ(4u, mesh_.n_vertex_props());
}
v_prop_d.set_persistent();
mesh_.set_persistent(v_prop_d);
EXPECT_EQ(1u, mesh_.n_vertex_props());
......@@ -76,7 +76,7 @@ TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest1) {
v_prop[0] = 24.5f;
v_prop[11] = 2.34f;
v_prop.set_persistent();
mesh_.set_persistent(v_prop);
}
VertexPropertyT<float> v_prop2 = mesh_.request_vertex_property<float>("FloatVProp");
......
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