42 #ifndef PROPERTYMANAGER_HH_
43 #define PROPERTYMANAGER_HH_
69 template<
typename PROPTYPE,
typename MeshT>
97 PropertyManager(MeshT &mesh,
const char *propname,
bool existing =
false) : mesh_(&mesh), retain_(existing) {
99 if (!mesh_->get_property_handle(prop_, propname)) {
100 std::ostringstream oss;
101 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
102 throw std::runtime_error(oss.str());
105 mesh_->add_property(prop_, propname);
116 void swap(PropertyManager &rhs) {
117 std::swap(mesh_, rhs.mesh_);
118 std::swap(prop_, rhs.prop_);
119 std::swap(retain_, rhs.retain_);
122 static bool propertyExists(MeshT &mesh,
const char *propname) {
124 return mesh.get_property_handle(dummy, propname);
127 bool isValid()
const {
return mesh_ != 0; }
128 operator bool()
const {
return isValid(); }
130 const PROPTYPE &getRawProperty()
const {
return prop_; }
132 #if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
136 PropertyManager(PropertyManager &&rhs) : mesh_(rhs.mesh_), prop_(rhs.prop_), retain_(rhs.retain_) {
143 PropertyManager &operator=(PropertyManager &&rhs) {
149 retain_ = rhs.retain_;
162 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
164 return std::move(pm);
170 Proxy(MeshT *mesh_, PROPTYPE prop_,
bool retain_) :
171 mesh_(mesh_), prop_(prop_), retain_(retain_) {}
180 Proxy p(mesh_, prop_, retain_);
186 PropertyManager(Proxy p) : mesh_(p.mesh_), prop_(p.prop_), retain_(p.retain_) {}
188 PropertyManager &operator=(Proxy p) {
189 PropertyManager(p).swap(*
this);
200 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
212 inline void retain(
bool doRetain =
true) {
237 template<
typename HandleType>
238 inline typename PROPTYPE::reference
operator[] (
const HandleType &handle) {
239 return mesh_->property(prop_, handle);
249 template<
typename HandleType>
250 inline typename PROPTYPE::const_reference
operator[] (
const HandleType &handle)
const {
251 return mesh_->property(prop_, handle);
255 void deleteProperty() {
257 mesh_->remove_property(prop_);