diff --git a/Surface_mesh/examples/Surface_mesh/sm_properties.cpp b/Surface_mesh/examples/Surface_mesh/sm_properties.cpp index 17cb02bb1dd..1e54d36b446 100644 --- a/Surface_mesh/examples/Surface_mesh/sm_properties.cpp +++ b/Surface_mesh/examples/Surface_mesh/sm_properties.cpp @@ -29,13 +29,28 @@ int main() // give each vertex a name, the default is empty Mesh::Property_map name; bool created; - boost::tie(name, created) = m.property_map("v:name", "noname"); + boost::tie(name, created) = m.add_property_map("v:name", "noname"); assert(created); // add some names to the vertices name[v0] = "hello"; name[v2] = "world"; - - // retrieve the point property + + { + // You can't add a property if it already exists + Mesh::Property_map name; + bool created; + boost::tie(name, created) = m.add_property_map("v:name", "noname"); + assert(! created); + } + + // You can't get a property that does not exist + Mesh::Property_map gnus; + bool found; + boost::tie(gnus, found) = m.property_map("v:gnus"); + assert(! found); + + + // retrieve the point property for which exists a convenience function Mesh::Property_map location = m.points(); BOOST_FOREACH( vertex_descriptor vd, m.vertices()) { std::cout << name[vd] << " @ " << location[vd] << std::endl; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 09f84479345..9fe25c09ec2 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -1897,25 +1897,27 @@ private: //--------------------------------------------------- property handling #endif -#if 0 /// adds a property map named `name` with value type `T` and default `t` - /// for index type `I`. Returns an invalid property map if a property - /// map named `name` already exists. + /// for index type `I`. Returns the property map together with a Boolean + /// that is `true` if a new map was created. In case it already exists + /// the existing map together with `false` is returned. template - Property_map + std::pair, bool> add_property_map(const std::string& name, const T t=T()) { return (this->*boost::fusion::at_key(pmap_)).template add(name, t); } -#endif + - /// returns a property map named `name` with key type `I` and value type `T`, and a Boolean - /// that is `true` if the property map gets newly created. + /// returns a property map named `name` with key type `I` and value type `T`, + /// and a Boolean that is `true` if the property exists. + /// In case it does not exist the Boolean is `false` and the behavior of + /// the property map is undefined. template - std::pair,bool> property_map(const std::string& name, const T& t=T()) const + std::pair,bool> property_map(const std::string& name) const { - return (this->*boost::fusion::at_key(pmap_)).template get(name, t); + return (this->*boost::fusion::at_key(pmap_)).template get(name); }