Cleanup of the properties API

This commit is contained in:
Andreas Fabri 2014-10-03 12:03:46 +02:00
parent c01176760c
commit 1fc44743cf
2 changed files with 29 additions and 12 deletions

View File

@ -29,13 +29,28 @@ int main()
// give each vertex a name, the default is empty // give each vertex a name, the default is empty
Mesh::Property_map<vertex_descriptor,std::string> name; Mesh::Property_map<vertex_descriptor,std::string> name;
bool created; bool created;
boost::tie(name, created) = m.property_map<vertex_descriptor,std::string>("v:name", "noname"); boost::tie(name, created) = m.add_property_map<vertex_descriptor,std::string>("v:name", "noname");
assert(created); assert(created);
// add some names to the vertices // add some names to the vertices
name[v0] = "hello"; name[v0] = "hello";
name[v2] = "world"; name[v2] = "world";
// retrieve the point property {
// You can't add a property if it already exists
Mesh::Property_map<vertex_descriptor,std::string> name;
bool created;
boost::tie(name, created) = m.add_property_map<vertex_descriptor,std::string>("v:name", "noname");
assert(! created);
}
// You can't get a property that does not exist
Mesh::Property_map<face_descriptor,std::string> gnus;
bool found;
boost::tie(gnus, found) = m.property_map<face_descriptor,std::string>("v:gnus");
assert(! found);
// retrieve the point property for which exists a convenience function
Mesh::Property_map<vertex_descriptor, K::Point_3> location = m.points(); Mesh::Property_map<vertex_descriptor, K::Point_3> location = m.points();
BOOST_FOREACH( vertex_descriptor vd, m.vertices()) { BOOST_FOREACH( vertex_descriptor vd, m.vertices()) {
std::cout << name[vd] << " @ " << location[vd] << std::endl; std::cout << name[vd] << " @ " << location[vd] << std::endl;

View File

@ -1897,25 +1897,27 @@ private: //--------------------------------------------------- property handling
#endif #endif
#if 0
/// adds a property map named `name` with value type `T` and default `t` /// 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 /// for index type `I`. Returns the property map together with a Boolean
/// map named `name` already exists. /// that is `true` if a new map was created. In case it already exists
/// the existing map together with `false` is returned.
template<class I, class T> template<class I, class T>
Property_map<I, T> std::pair<Property_map<I, T>, bool>
add_property_map(const std::string& name, const T t=T()) { add_property_map(const std::string& name, const T t=T()) {
return (this->*boost::fusion::at_key<I>(pmap_)).template add<T>(name, t); return (this->*boost::fusion::at_key<I>(pmap_)).template add<T>(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 <class I, class T> template <class I, class T>
std::pair<Property_map<I, T>,bool> property_map(const std::string& name, const T& t=T()) const std::pair<Property_map<I, T>,bool> property_map(const std::string& name) const
{ {
return (this->*boost::fusion::at_key<I>(pmap_)).template get<T>(name, t); return (this->*boost::fusion::at_key<I>(pmap_)).template get<T>(name);
} }