Commit d7518286 authored by Mike Kremer's avatar Mike Kremer

Added function to check for existance of properties by name.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@212 66977474-1d4b-4f09-8fe9-267525286df2
parent 8bb8c674
......@@ -218,6 +218,49 @@ public:
Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }
template <class PropIterT>
bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {
if(_name.length() == 0) {
std::cerr << "Checking for the existance of anonymous properties is ambiguous!" << std::endl;
return false;
}
PropIterT it = _begin;
for(; it != _end; ++it) {
if((*it)->name() == _name) return true;
}
return false;
}
bool vertex_property_exists(const std::string& _name) const {
return property_exists(vertex_props_begin(), vertex_props_end(), _name);
}
bool edge_property_exists(const std::string& _name) const {
return property_exists(edge_props_begin(), edge_props_end(), _name);
}
bool halfedge_property_exists(const std::string& _name) const {
return property_exists(halfedge_props_begin(), halfedge_props_end(), _name);
}
bool face_property_exists(const std::string& _name) const {
return property_exists(face_props_begin(), face_props_end(), _name);
}
bool halfface_property_exists(const std::string& _name) const {
return property_exists(halfface_props_begin(), halfface_props_end(), _name);
}
bool cell_property_exists(const std::string& _name) const {
return property_exists(cell_props_begin(), cell_props_end(), _name);
}
bool mesh_property_exists(const std::string& _name) const {
return property_exists(mesh_props_begin(), mesh_props_end(), _name);
}
protected:
void delete_multiple_vertex_props(const std::vector<bool>& _tags);
......
......@@ -674,6 +674,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
VertexPropertyT<Vec3d> vp = mesh_.request_vertex_property<Vec3d>("VProp");
EXPECT_TRUE(mesh_.vertex_property_exists("VProp"));
for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
vp[v_it->idx()] = Vec3d(1.0, 0.0, 0.0);
}
......@@ -695,6 +697,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
EdgePropertyT<unsigned int> ep = mesh_.request_edge_property<unsigned int>("EProp");
EXPECT_TRUE(mesh_.edge_property_exists("EProp"));
unsigned int i = 0;
for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
ep[e_it->idx()] = i++;
......@@ -707,6 +711,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
HalfFacePropertyT<bool> hfp = mesh_.request_halfface_property<bool>("HFProp");
EXPECT_TRUE(mesh_.halfface_property_exists("HFProp"));
bool b = false;
for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
hfp[hf_it->idx()] = b;
......@@ -722,6 +728,8 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
// Request halfface properties
CellPropertyT<std::string> cp = mesh_.request_cell_property<std::string>("CProp");
EXPECT_TRUE(mesh_.cell_property_exists("CProp"));
for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
cp[c_it->idx()] = std::string("MyTestString");
}
......@@ -729,6 +737,9 @@ TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
EXPECT_EQ(std::string("MyTestString"), cp[c_it->idx()]);
}
EXPECT_FALSE(mesh_.halfedge_property_exists("HEProp"));
EXPECT_FALSE(mesh_.vertex_property_exists(""));
}
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