Commit f69d1edd authored by Martin Heistermann's avatar Martin Heistermann

Handles: some support for construction from / conversion to size_t

parent 8ec177ed
Pipeline #9179 passed with stage
in 3 minutes and 33 seconds
......@@ -37,6 +37,8 @@
#include <algorithm>
#include <iosfwd>
#include <vector>
#include <cassert>
#include <limits>
#include "Entities.hh"
#include "../System/FunctionalInclude.hh"
......@@ -48,17 +50,15 @@ namespace OpenVolumeMesh {
class OpenVolumeMeshHandle {
public:
// Default constructor
explicit OpenVolumeMeshHandle(int _idx) : idx_(_idx) {};
explicit OpenVolumeMeshHandle(int _idx) : idx_(_idx) {}
OpenVolumeMeshHandle& operator=(int _idx) {
idx_ = _idx;
return *this;
}
OpenVolumeMeshHandle& operator=(const OpenVolumeMeshHandle& _idx) {
idx_ = _idx.idx_;
return *this;
}
OpenVolumeMeshHandle(const OpenVolumeMeshHandle& _idx) = default;
OpenVolumeMeshHandle& operator=(const OpenVolumeMeshHandle& _idx) = default;
inline bool is_valid() const { return idx_ != -1; }
......@@ -76,6 +76,9 @@ public:
inline const int& idx() const { return idx_; }
/// return unsigned idx - handle must be valid
inline size_t uidx() const { assert(is_valid()); return static_cast<size_t>(idx_); }
void idx(const int& _idx) { idx_ = _idx; }
OVM_DEPRECATED("use explicit .idx() instead")
......@@ -95,6 +98,17 @@ class HandleT : public OpenVolumeMeshHandle
public:
using Entity = EntityTag;
explicit HandleT(int _idx = -1) : OpenVolumeMeshHandle(_idx) {}
static HandleT<EntityTag>
from_unsigned(size_t _idx)
{
if (_idx <= std::numeric_limits<int>::max()) {
return HandleT<EntityTag>(static_cast<int>(_idx));
} else {
assert(false);
return HandleT<EntityTag>(-1);
}
}
};
// Default entity handles
......
......@@ -99,7 +99,7 @@ public:
const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.uidx()]; }
virtual void serialize(std::ostream& _ostr) const { ptr::shared_ptr<PropT>::get()->serialize(_ostr); }
virtual void deserialize(std::istream& _istr) { ptr::shared_ptr<PropT>::get()->deserialize(_istr); }
......
......@@ -178,32 +178,32 @@ void ResourceManager::swap_vertex_properties(VertexHandle _h1, VertexHandle _h2)
void ResourceManager::release_property(VertexPropHandle _handle) {
remove_property(vertex_props_, _handle.idx());
remove_property(vertex_props_, _handle.uidx());
}
void ResourceManager::release_property(EdgePropHandle _handle) {
remove_property(edge_props_, _handle.idx());
remove_property(edge_props_, _handle.uidx());
}
void ResourceManager::release_property(HalfEdgePropHandle _handle) {
remove_property(halfedge_props_, _handle.idx());
remove_property(halfedge_props_, _handle.uidx());
}
void ResourceManager::release_property(FacePropHandle _handle) {
remove_property(face_props_, _handle.idx());
remove_property(face_props_, _handle.uidx());
}
void ResourceManager::release_property(HalfFacePropHandle _handle) {
remove_property(halfface_props_, _handle.idx());
remove_property(halfface_props_, _handle.uidx());
}
void ResourceManager::release_property(CellPropHandle _handle) {
remove_property(cell_props_, _handle.idx());
remove_property(cell_props_, _handle.uidx());
}
void ResourceManager::release_property(MeshPropHandle _handle) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment