Commit 58b9e408 authored by Andreas Fabri's avatar Andreas Fabri

- 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
parent 7a547cb7
Pipeline #2161 passed with stage
in 79 minutes and 30 seconds
......@@ -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 <functional>
namespace std {
#if defined(_MSVC_VER)
# pragma warning(push)
# pragma warning(disable:4099) // For VC++ it is class hash
#endif
template <>
class hash<OpenMesh::BaseHandle >
: public std::unary_function<OpenMesh::BaseHandle, std::size_t>
{
std::size_t operator()(const OpenMesh::BaseHandle& h) const
{
return h.idx();
}
};
template <>
struct hash<OpenMesh::VertexHandle >
: public std::unary_function<OpenMesh::VertexHandle, std::size_t>
{
std::size_t operator()(const OpenMesh::VertexHandle& h) const
{
return h.idx();
}
};
template <>
struct hash<OpenMesh::HalfedgeHandle >
: public std::unary_function<OpenMesh::HalfedgeHandle, std::size_t>
{
std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const
{
return h.idx();
}
};
template <>
struct hash<OpenMesh::EdgeHandle >
: public std::unary_function<OpenMesh::EdgeHandle, std::size_t>
{
std::size_t operator()(const OpenMesh::EdgeHandle& h) const
{
return h.idx();
}
};
template <>
struct hash<OpenMesh::FaceHandle >
: public std::unary_function<OpenMesh::FaceHandle, std::size_t>
{
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
//=============================================================================
......@@ -608,11 +608,6 @@ const LHS mesh_cast(const PolyMeshT<KERNEL> *rhs) {
return MeshCast<LHS, const PolyMeshT<KERNEL>*>::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
//=============================================================================
......
......@@ -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
//=============================================================================
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