From 58b9e4085a7320f3e973d3aad754a7a999f7ee59 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 8 Jun 2016 10:29:18 +0200 Subject: [PATCH] - ADD a macro OM_HAS_HASH in the config file. - Based on the macro provide partial specializations for std::hash<> - for vertex,halfede,edge, and face handles. - Add a free function hash_value(BaseHandle) for boost::unordered_set/map --- src/OpenMesh/Core/Mesh/Handles.hh | 76 +++++++++++++++++++++++++++++ src/OpenMesh/Core/Mesh/PolyMeshT.hh | 5 -- src/OpenMesh/Core/System/config.h | 5 ++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/Handles.hh b/src/OpenMesh/Core/Mesh/Handles.hh index 1488ce09..94c11b70 100644 --- a/src/OpenMesh/Core/Mesh/Handles.hh +++ b/src/OpenMesh/Core/Mesh/Handles.hh @@ -106,6 +106,8 @@ private: int idx_; }; +// this is used by boost::unordered_set/map +inline size_t hash_value(const BaseHandle& h) { return h.idx(); } //----------------------------------------------------------------------------- @@ -150,5 +152,79 @@ struct FaceHandle : public BaseHandle //============================================================================= } // namespace OpenMesh //============================================================================= + +#ifdef OM_HAS_HASH +#include +namespace std { + +#if defined(_MSVC_VER) +# pragma warning(push) +# pragma warning(disable:4099) // For VC++ it is class hash +#endif + + +template <> +class hash + : public std::unary_function +{ + + std::size_t operator()(const OpenMesh::BaseHandle& h) const + { + return h.idx(); + } +}; + +template <> +struct hash + : public std::unary_function +{ + + std::size_t operator()(const OpenMesh::VertexHandle& h) const + { + return h.idx(); + } +}; + +template <> +struct hash + : public std::unary_function +{ + + std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const + { + return h.idx(); + } +}; + +template <> +struct hash + : public std::unary_function +{ + + std::size_t operator()(const OpenMesh::EdgeHandle& h) const + { + return h.idx(); + } +}; + +template <> +struct hash + : public std::unary_function +{ + + std::size_t operator()(const OpenMesh::FaceHandle& h) const + { + return h.idx(); + } +}; + +#if defined(_MSVC_VER) +# pragma warning(pop) +#endif + +} +#endif // OM_HAS_HASH + + #endif // OPENMESH_HANDLES_HH //============================================================================= diff --git a/src/OpenMesh/Core/Mesh/PolyMeshT.hh b/src/OpenMesh/Core/Mesh/PolyMeshT.hh index 93e40ad0..d0e4d4f8 100644 --- a/src/OpenMesh/Core/Mesh/PolyMeshT.hh +++ b/src/OpenMesh/Core/Mesh/PolyMeshT.hh @@ -608,11 +608,6 @@ const LHS mesh_cast(const PolyMeshT *rhs) { return MeshCast*>::cast(rhs); } -inline size_t hash_value(const VertexHandle& i) { return i.idx(); } -inline size_t hash_value(const HalfedgeHandle& i) { return i.idx(); } -inline size_t hash_value(const FaceHandle& i) { return i.idx(); } - - //============================================================================= } // namespace OpenMesh //============================================================================= diff --git a/src/OpenMesh/Core/System/config.h b/src/OpenMesh/Core/System/config.h index b85d9719..31537b5e 100644 --- a/src/OpenMesh/Core/System/config.h +++ b/src/OpenMesh/Core/System/config.h @@ -101,6 +101,11 @@ #endif typedef unsigned int uint; + +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define OM_HAS_HASH +#endif + //============================================================================= #endif // OPENMESH_CONFIG_H defined //=============================================================================