49 #ifndef PROPERTYMANAGER_HH_ 50 #define PROPERTYMANAGER_HH_ 93 template<
typename PROPTYPE,
typename MeshT>
95 #if (defined(_MSC_VER) && (_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);
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 (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 190 retain_ = rhs.retain_;
206 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
208 return std::move(pm);
220 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
222 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
223 const PROP_VALUE &init_value) {
224 const bool exists = propertyExists(mesh, propname);
229 return std::move(pm);
241 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
243 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
245 mesh, propname, range.begin(), range.end(), init_value);
250 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
258 return std::move(*
this);
264 Proxy(MeshT *mesh_, PROPTYPE prop_,
bool retain_,
const std::string &name_) :
265 mesh_(mesh_), prop_(prop_), retain_(retain_), name_(name_) {}
275 Proxy p(mesh_, prop_, retain_, name_);
285 PropertyManager(Proxy p) : mesh_(p.mesh_), prop_(p.prop_), retain_(p.retain_), name_(p.name_) {}
301 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
315 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
317 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
318 const PROP_VALUE &init_value) {
319 const bool exists = propertyExists(mesh, propname);
327 Proxy duplicate(
const char *clone_name) {
329 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
340 inline void retain(
bool doRetain =
true) {
365 template<
typename HandleType>
366 inline typename PROPTYPE::reference
operator[] (
const HandleType &handle) {
367 return mesh_->property(prop_, handle);
377 template<
typename HandleType>
378 inline typename PROPTYPE::const_reference
operator[] (
const HandleType &handle)
const {
379 return mesh_->property(prop_, handle);
406 template<
typename HandleTypeIterator,
typename PROP_VALUE>
407 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
408 const PROP_VALUE &value) {
409 for (; begin != end; ++begin)
410 (*
this)[*begin] = value;
413 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 414 template<
typename HandleTypeIteratorRange,
typename PROP_VALUE>
415 void set_range(
const HandleTypeIteratorRange &range,
416 const PROP_VALUE &value) {
417 set_range(range.begin(), range.end(), value);
435 template<
typename HandleTypeIterator,
typename PROPTYPE_2,
436 typename MeshT_2,
typename HandleTypeIterator_2>
437 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
439 HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end)
const {
441 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
442 dst_propmanager[*dst_begin] = (*this)[*begin];
446 template<
typename RangeType,
typename PROPTYPE_2,
447 typename MeshT_2,
typename RangeType_2>
448 void copy_to(
const RangeType &range,
450 const RangeType_2 &dst_range)
const {
451 copy_to(range.begin(), range.end(), dst_propmanager,
452 dst_range.begin(), dst_range.end());
469 template<
typename RangeType,
typename MeshT_2,
typename RangeType_2>
470 static void copy(
const char *prop_name,
471 MeshT &src_mesh,
const RangeType &src_range,
472 MeshT_2 &dst_mesh,
const RangeType_2 &dst_range) {
475 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
478 SrcPM src(src_mesh, prop_name,
true);
480 src.copy_to(src_range, dst, dst_range);
484 void deleteProperty() {
486 mesh_->remove_property(prop_);
503 template<
typename PROPTYPE,
typename MeshT>
518 template<
typename PROPTYPE,
typename MeshT>
529 template<
typename PROPTYPE,
typename MeshT>
545 template<
typename PROPTYPE,
typename MeshT,
546 typename ITERATOR_TYPE,
typename PROP_VALUE>
548 MeshT &mesh,
const char *propname,
549 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
550 const PROP_VALUE &init_value) {
552 mesh, propname, begin, end, init_value);
566 template<
typename PROPTYPE,
typename MeshT,
567 typename ITERATOR_RANGE,
typename PROP_VALUE>
569 MeshT &mesh,
const char *propname,
570 const ITERATOR_RANGE &range,
571 const PROP_VALUE &init_value) {
572 return makePropertyManagerFromExistingOrNew<PROPTYPE, MeshT>(
573 mesh, propname, range.begin(), range.end(), init_value);
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:94
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname, const ITERATOR_RANGE &range, const PROP_VALUE &init_value)
Definition: PropertyManager.hh:568
PropertyManager(MeshT &mesh, const char *propname, bool existing=false)
Constructor.
Definition: PropertyManager.hh:130
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname, const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end, const PROP_VALUE &init_value)
Definition: PropertyManager.hh:547
PROPTYPE & operator*()
Access the encapsulated property.
Definition: PropertyManager.hh:347
Definition: PropertyManager.hh:262
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExisting(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:519
static Proxy createIfNotExists(MeshT &mesh, const char *propname)
Create a property manager for the supplied property and mesh.
Definition: PropertyManager.hh:299
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:437
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:530
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:407
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
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:470
void retain(bool doRetain=true)
Disable lifecycle management for this property.
Definition: PropertyManager.hh:340
PROPTYPE::reference operator[](const HandleType &handle)
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:366
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromNew(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:504
static Proxy createIfNotExists(MeshT &mesh, const char *propname, const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end, const PROP_VALUE &init_value)
Like createIfNotExists() with two parameters except, if the property doesn't exist, it is initialized with the supplied value over the supplied range after creation.
Definition: PropertyManager.hh:316