Commit 4dcc56e0 authored by Mike Kremer's avatar Mike Kremer

Introduced anonymous properties.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@111 66977474-1d4b-4f09-8fe9-267525286df2
parent 054d1027
......@@ -77,6 +77,8 @@ public:
protected:
virtual const void* ptr() const = 0;
virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0;
virtual OpenVolumeMeshHandle handle() const = 0;
......
......@@ -129,6 +129,8 @@ public:
protected:
virtual const void* ptr() const { return h_->ptr_; }
virtual void set_handle(const OpenVolumeMeshHandle& _handle);
virtual OpenVolumeMeshHandle handle() const;
......
......@@ -106,19 +106,19 @@ public:
/// Get number of cells in mesh
virtual unsigned int n_cells() const = 0;
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name);
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string());
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name);
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string());
template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name);
template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string());
template<class T> FacePropertyT<T> request_face_property(const std::string& _name);
template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string());
template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name);
template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string());
template<class T> CellPropertyT<T> request_cell_property(const std::string& _name);
template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string());
template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name);
template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string());
void released_property(VertexPropHandle _handle);
......
......@@ -53,11 +53,13 @@ namespace OpenVolumeMesh {
template<class T>
VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _name) {
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;
if(!_name.empty()) {
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;
}
}
}
......@@ -80,11 +82,13 @@ 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 = persistent_eprops_.begin();
it != persistent_eprops_.end(); ++it) {
if((*it)->name() == _name) {
EdgePropertyT<T>* prop = dynamic_cast<EdgePropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -107,11 +111,13 @@ 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 = persistent_heprops_.begin();
it != persistent_heprops_.end(); ++it) {
if((*it)->name() == _name) {
HalfEdgePropertyT<T>* prop = dynamic_cast<HalfEdgePropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -134,11 +140,13 @@ 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 = persistent_fprops_.begin();
it != persistent_fprops_.end(); ++it) {
if((*it)->name() == _name) {
FacePropertyT<T>* prop = dynamic_cast<FacePropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -161,11 +169,13 @@ 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 = persistent_hfprops_.begin();
it != persistent_hfprops_.end(); ++it) {
if((*it)->name() == _name) {
HalfFacePropertyT<T>* prop = dynamic_cast<HalfFacePropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -188,11 +198,13 @@ 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 = persistent_cprops_.begin();
it != persistent_cprops_.end(); ++it) {
if((*it)->name() == _name) {
CellPropertyT<T>* prop = dynamic_cast<CellPropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -215,11 +227,13 @@ 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 = persistent_mprops_.begin();
it != persistent_mprops_.end(); ++it) {
if((*it)->name() == _name) {
MeshPropertyT<T>* prop = dynamic_cast<MeshPropertyT<T>* >(*it);
return *prop;
if(!_name.empty()) {
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;
}
}
}
......@@ -247,7 +261,7 @@ void ResourceManager::set_persistent(VertexPropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_vprops_.begin();
it != persistent_vprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_vprops_.erase(it);
......@@ -269,7 +283,7 @@ void ResourceManager::set_persistent(EdgePropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_eprops_.begin();
it != persistent_eprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_eprops_.erase(it);
......@@ -291,7 +305,7 @@ void ResourceManager::set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_heprops_.begin();
it != persistent_heprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_heprops_.erase(it);
......@@ -313,7 +327,7 @@ void ResourceManager::set_persistent(FacePropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_fprops_.begin();
it != persistent_fprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_fprops_.erase(it);
......@@ -335,7 +349,7 @@ void ResourceManager::set_persistent(HalfFacePropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_hfprops_.begin();
it != persistent_hfprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_hfprops_.erase(it);
......@@ -357,7 +371,7 @@ void ResourceManager::set_persistent(CellPropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_cprops_.begin();
it != persistent_cprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_cprops_.erase(it);
......@@ -379,7 +393,7 @@ void ResourceManager::set_persistent(MeshPropertyT<T>& _prop, bool _flag) {
if(!_flag) {
for(std::vector<BaseProperty*>::iterator it = persistent_mprops_.begin();
it != persistent_mprops_.end(); ++it) {
if((*it)->name() == _prop.name()) {
if((*it)->ptr() == _prop.h_->ptr_) {
_prop.h_->persistent_ = false;
delete (*it);
persistent_mprops_.erase(it);
......
......@@ -110,6 +110,39 @@ TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest2) {
EXPECT_EQ(0u, mesh_.n_vertex_props());
}
TEST_F(HexahedralMeshBase, AnonymousPropertiesTest1) {
generateHexahedralMesh(mesh_);
CellPropertyT<float> c_prop = mesh_.request_cell_property<float>();
CellPropertyT<float> c_prop2 = c_prop;
EXPECT_EQ(1u, mesh_.n_cell_props());
mesh_.set_persistent(c_prop);
EXPECT_EQ(1u, mesh_.n_cell_props());
mesh_.set_persistent(c_prop2, false);
EXPECT_EQ(1u, mesh_.n_cell_props());
}
TEST_F(HexahedralMeshBase, AnonymousPropertiesTest2) {
generateHexahedralMesh(mesh_);
CellPropertyT<float> c_prop1 = mesh_.request_cell_property<float>();
for(int i = 0; i < 1; ++i) {
CellPropertyT<float> c_prop2 = mesh_.request_cell_property<float>();
EXPECT_EQ(2u, mesh_.n_cell_props());
}
EXPECT_EQ(1u, mesh_.n_cell_props());
}
TEST_F(PolyhedralMeshBase, StatusTest) {
generatePolyhedralMesh(mesh_);
......
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