From d6c195b694e5309bfd8d0e4fac49a7ddf09d9d81 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Thu, 25 May 2023 10:14:02 +0200 Subject: [PATCH] add GetHashCode function to ost::mol::EntityHandle --- modules/mol/base/pymod/export_entity.cc | 3 ++- modules/mol/base/src/entity_handle.cc | 7 +++++++ modules/mol/base/src/entity_handle.hh | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/mol/base/pymod/export_entity.cc b/modules/mol/base/pymod/export_entity.cc index c0b54781a..bd2e97248 100644 --- a/modules/mol/base/pymod/export_entity.cc +++ b/modules/mol/base/pymod/export_entity.cc @@ -225,7 +225,8 @@ void export_Entity() .def("EditXCS", &EntityHandle::EditXCS, arg("mode")=UNBUFFERED_EDIT) .def("EditICS", &EntityHandle::EditICS, arg("mode")=UNBUFFERED_EDIT) .def("RequestXCSEditor", &depr_request_xcs_editor, arg("mode")=UNBUFFERED_EDIT) - .def("RequestICSEditor", &depr_request_ics_editor, arg("mode")=UNBUFFERED_EDIT) + .def("RequestICSEditor", &depr_request_ics_editor, arg("mode")=UNBUFFERED_EDIT) + .def("GetHashCode", &EntityHandle::GetHashCode) .def(self==self) .def(self!=self) #if OST_NUMPY_SUPPORT_ENABLED diff --git a/modules/mol/base/src/entity_handle.cc b/modules/mol/base/src/entity_handle.cc index b17d23f0b..ade0c4524 100644 --- a/modules/mol/base/src/entity_handle.cc +++ b/modules/mol/base/src/entity_handle.cc @@ -388,4 +388,11 @@ EntityHandle EntityHandle::GetHandle() const { return *this; } + +unsigned long EntityHandle::GetHashCode() const +{ + this->CheckValidity(); + return reinterpret_cast<unsigned long>(Impl().get()); +} + }} // ns diff --git a/modules/mol/base/src/entity_handle.hh b/modules/mol/base/src/entity_handle.hh index 18383529a..a85db21be 100644 --- a/modules/mol/base/src/entity_handle.hh +++ b/modules/mol/base/src/entity_handle.hh @@ -272,6 +272,9 @@ public: /// /// Useful for templated code and duck-typing in Python EntityHandle GetHandle() const; + + unsigned long GetHashCode() const; + bool operator==(const EntityHandle& ref) const; bool operator!=(const EntityHandle& ref) const; }; -- GitLab