49 #ifndef PROPERTYMANAGER_HH_
50 #define PROPERTYMANAGER_HH_
93 template<
typename PROPTYPE,
typename MeshT>
95 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
130 PropertyManager(MeshT &mesh,
const char *propname,
bool existing =
false) : mesh_(&mesh), retain_(existing), name_(propname) {
132 if (!mesh_->get_property_handle(prop_, propname)) {
133 std::ostringstream oss;
134 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
135 throw std::runtime_error(oss.str());
138 mesh_->add_property(prop_, propname);
149 void swap(PropertyManager &rhs) {
150 std::swap(mesh_, rhs.mesh_);
151 std::swap(prop_, rhs.prop_);
152 std::swap(retain_, rhs.retain_);
153 std::swap(name_, rhs.name_);
156 static bool propertyExists(MeshT &mesh,
const char *propname) {
158 return mesh.get_property_handle(dummy, propname);
161 bool isValid()
const {
return mesh_ != 0; }
162 operator bool()
const {
return isValid(); }
164 const PROPTYPE &getRawProperty()
const {
return prop_; }
166 const std::string &getName()
const {
return name_; }
168 MeshT &getMesh()
const {
return *mesh_; }
170 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
173 typedef PropertyManager<PROPTYPE, MeshT> Proxy;
178 PropertyManager(PropertyManager &&rhs) : mesh_(rhs.mesh_), prop_(rhs.prop_), retain_(rhs.retain_), name_(rhs.name_) {
185 PropertyManager &operator=(PropertyManager &&rhs) {
190 retain_ = rhs.retain_;
206 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
208 return std::move(pm);
212 PropertyManager duplicate(
const char *clone_name) {
213 PropertyManager pm(*mesh_, clone_name,
false);
214 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
221 PropertyManager move() {
222 return std::move(*
this);
228 Proxy(MeshT *mesh_, PROPTYPE prop_,
bool retain_,
const std::string &name_) :
229 mesh_(mesh_), prop_(prop_), retain_(retain_), name_(name_) {}
239 Proxy p(mesh_, prop_, retain_, name_);
249 PropertyManager(Proxy p) : mesh_(p.mesh_), prop_(p.prop_), retain_(p.retain_), name_(p.name_) {}
251 PropertyManager &operator=(Proxy p) {
252 PropertyManager(p).swap(*
this);
265 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
270 Proxy duplicate(
const char *clone_name) {
272 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
283 inline void retain(
bool doRetain =
true) {
308 template<
typename HandleType>
309 inline typename PROPTYPE::reference
operator[] (
const HandleType &handle) {
310 return mesh_->property(prop_, handle);
320 template<
typename HandleType>
321 inline typename PROPTYPE::const_reference
operator[] (
const HandleType &handle)
const {
322 return mesh_->property(prop_, handle);
349 template<
typename HandleTypeIterator,
typename PROP_VALUE>
350 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
351 const PROP_VALUE &value) {
352 for (; begin != end; ++begin)
353 (*
this)[*begin] = value;
370 template<
typename HandleTypeIterator,
typename PROPTYPE_2,
371 typename MeshT_2,
typename HandleTypeIterator_2>
372 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
374 HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end)
const {
376 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
377 dst_propmanager[*dst_begin] = (*this)[*begin];
381 template<
typename RangeType,
typename PROPTYPE_2,
382 typename MeshT_2,
typename RangeType_2>
383 void copy_to(
const RangeType &range,
385 const RangeType_2 &dst_range)
const {
386 copy_to(range.begin(), range.end(), dst_propmanager,
387 dst_range.begin(), dst_range.end());
404 template<
typename RangeType,
typename MeshT_2,
typename RangeType_2>
405 static void copy(
const char *prop_name,
406 MeshT &src_mesh,
const RangeType &src_range,
407 MeshT_2 &dst_mesh,
const RangeType_2 &dst_range) {
410 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
413 SrcPM src(src_mesh, prop_name,
true);
415 src.copy_to(src_range, dst, dst_range);
419 void deleteProperty() {
421 mesh_->remove_property(prop_);
438 template<
typename PROPTYPE,
typename MeshT>
453 template<
typename PROPTYPE,
typename MeshT>
464 template<
typename PROPTYPE,
typename MeshT>
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExisting(MeshT &mesh, const char *propname)
Creates a non-owning wrapper for an existing mesh property (no lifecycle management).
Definition: PropertyManager.hh:454
static void copy(const char *prop_name, MeshT &src_mesh, const RangeType &src_range, MeshT_2 &dst_mesh, const RangeType_2 &dst_range)
Copy the values of a property from a source range to a target range.
Definition: PropertyManager.hh:405
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromNew(MeshT &mesh, const char *propname)
Creates a new property whose lifecycle is managed by the returned PropertyManager.
Definition: PropertyManager.hh:439
PROPTYPE & operator*()
Access the encapsulated property.
Definition: PropertyManager.hh:290
static Proxy createIfNotExists(MeshT &mesh, const char *propname)
Create a property manager for the supplied property and mesh.
Definition: PropertyManager.hh:263
PROPTYPE::reference operator[](const HandleType &handle)
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:309
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:350
PropertyManager(MeshT &mesh, const char *propname, bool existing=false)
Constructor.
Definition: PropertyManager.hh:130
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:94
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager< PROPTYPE_2, MeshT_2 > &dst_propmanager, HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end) const
Conveniently transfer the values managed by one property manager onto the values managed by a differe...
Definition: PropertyManager.hh:372
void retain(bool doRetain=true)
Disable lifecycle management for this property.
Definition: PropertyManager.hh:283
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname)
Creates a non-owning wrapper for a mesh property (no lifecycle management).
Definition: PropertyManager.hh:465