Commit 64992de3 authored by Mike Kremer's avatar Mike Kremer
Browse files

Made function to check for a property's existance depending on the property's...

Made function to check for a property's existance depending on the property's type as template parameter.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@214 66977474-1d4b-4f09-8fe9-267525286df2
parent c5c33164
...@@ -218,7 +218,7 @@ public: ...@@ -218,7 +218,7 @@ public:
Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); } Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }
template <class PropIterT> template <class FullPropT, class PropIterT>
bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const { bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {
if(_name.length() == 0) { if(_name.length() == 0) {
...@@ -228,37 +228,46 @@ public: ...@@ -228,37 +228,46 @@ public:
PropIterT it = _begin; PropIterT it = _begin;
for(; it != _end; ++it) { for(; it != _end; ++it) {
if((*it)->name() == _name) return true; if((*it)->name() == _name && dynamic_cast<FullPropT*>(*it) != NULL) {
return true;
}
} }
return false; return false;
} }
template <class PropT>
bool vertex_property_exists(const std::string& _name) const { bool vertex_property_exists(const std::string& _name) const {
return property_exists(vertex_props_begin(), vertex_props_end(), _name); return property_exists<VertexPropertyT<PropT> >(vertex_props_begin(), vertex_props_end(), _name);
} }
template <class PropT>
bool edge_property_exists(const std::string& _name) const { bool edge_property_exists(const std::string& _name) const {
return property_exists(edge_props_begin(), edge_props_end(), _name); return property_exists<EdgePropertyT<PropT> >(edge_props_begin(), edge_props_end(), _name);
} }
template <class PropT>
bool halfedge_property_exists(const std::string& _name) const { bool halfedge_property_exists(const std::string& _name) const {
return property_exists(halfedge_props_begin(), halfedge_props_end(), _name); return property_exists<HalfEdgePropertyT<PropT> >(halfedge_props_begin(), halfedge_props_end(), _name);
} }
template <class PropT>
bool face_property_exists(const std::string& _name) const { bool face_property_exists(const std::string& _name) const {
return property_exists(face_props_begin(), face_props_end(), _name); return property_exists<FacePropertyT<PropT> >(face_props_begin(), face_props_end(), _name);
} }
template <class PropT>
bool halfface_property_exists(const std::string& _name) const { bool halfface_property_exists(const std::string& _name) const {
return property_exists(halfface_props_begin(), halfface_props_end(), _name); return property_exists<HalfFacePropertyT<PropT> >(halfface_props_begin(), halfface_props_end(), _name);
} }
template <class PropT>
bool cell_property_exists(const std::string& _name) const { bool cell_property_exists(const std::string& _name) const {
return property_exists(cell_props_begin(), cell_props_end(), _name); return property_exists<CellPropertyT<PropT> >(cell_props_begin(), cell_props_end(), _name);
} }
template <class PropT>
bool mesh_property_exists(const std::string& _name) const { bool mesh_property_exists(const std::string& _name) const {
return property_exists(mesh_props_begin(), mesh_props_end(), _name); return property_exists<MeshPropertyT<PropT> >(mesh_props_begin(), mesh_props_end(), _name);
} }
protected: protected:
......
...@@ -674,7 +674,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) { ...@@ -674,7 +674,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
VertexPropertyT<Vec3d> vp = mesh_.request_vertex_property<Vec3d>("VProp"); VertexPropertyT<Vec3d> vp = mesh_.request_vertex_property<Vec3d>("VProp");
EXPECT_TRUE(mesh_.vertex_property_exists("VProp")); EXPECT_TRUE(mesh_.vertex_property_exists<Vec3d>("VProp"));
for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) { for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
vp[v_it->idx()] = Vec3d(1.0, 0.0, 0.0); vp[v_it->idx()] = Vec3d(1.0, 0.0, 0.0);
...@@ -697,7 +697,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) { ...@@ -697,7 +697,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
EdgePropertyT<unsigned int> ep = mesh_.request_edge_property<unsigned int>("EProp"); EdgePropertyT<unsigned int> ep = mesh_.request_edge_property<unsigned int>("EProp");
EXPECT_TRUE(mesh_.edge_property_exists("EProp")); EXPECT_TRUE(mesh_.edge_property_exists<unsigned int>("EProp"));
unsigned int i = 0; unsigned int i = 0;
for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) { for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
...@@ -711,7 +711,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) { ...@@ -711,7 +711,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
HalfFacePropertyT<bool> hfp = mesh_.request_halfface_property<bool>("HFProp"); HalfFacePropertyT<bool> hfp = mesh_.request_halfface_property<bool>("HFProp");
EXPECT_TRUE(mesh_.halfface_property_exists("HFProp")); EXPECT_TRUE(mesh_.halfface_property_exists<bool>("HFProp"));
bool b = false; bool b = false;
for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) { for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
...@@ -728,7 +728,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) { ...@@ -728,7 +728,7 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
// Request halfface properties // Request halfface properties
CellPropertyT<std::string> cp = mesh_.request_cell_property<std::string>("CProp"); CellPropertyT<std::string> cp = mesh_.request_cell_property<std::string>("CProp");
EXPECT_TRUE(mesh_.cell_property_exists("CProp")); EXPECT_TRUE(mesh_.cell_property_exists<std::string>("CProp"));
for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) { for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
cp[c_it->idx()] = std::string("MyTestString"); cp[c_it->idx()] = std::string("MyTestString");
...@@ -738,8 +738,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) { ...@@ -738,8 +738,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
EXPECT_EQ(std::string("MyTestString"), cp[c_it->idx()]); EXPECT_EQ(std::string("MyTestString"), cp[c_it->idx()]);
} }
EXPECT_FALSE(mesh_.halfedge_property_exists("HEProp")); EXPECT_FALSE(mesh_.halfedge_property_exists<unsigned char>("HEProp"));
EXPECT_FALSE(mesh_.vertex_property_exists("")); EXPECT_FALSE(mesh_.vertex_property_exists<size_t>(""));
} }
TEST_F(PolyhedralMeshBase, STLCompliance) { TEST_F(PolyhedralMeshBase, STLCompliance) {
......
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