Skip to content

Commit

Permalink
Fix hashing Tags (close #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
lamyj committed Dec 22, 2016
1 parent 8871f4b commit 6bceb4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/wrappers/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,16 @@ def test_str(self):
tag = odil.Tag(0x1234, 0x5678)
self.assertEqual(str(tag), "12345678")

def test_hash(self):
tag = odil.Tag(
odil.registry.PatientName.group, odil.registry.PatientName.element)
d = {tag: True}

self.assertTrue(tag in d)
self.assertTrue(odil.registry.PatientName in d)

other = odil.Tag(
odil.registry.PatientID.group, odil.registry.PatientID.element)

if __name__ == "__main__":
unittest.main()
6 changes: 6 additions & 0 deletions wrappers/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include "odil/Tag.h"

uint32_t hash(odil::Tag const & tag)
{
return ((tag.group<<16)+tag.element);
}

void wrap_Tag()
{
using namespace boost::python;
Expand All @@ -29,6 +34,7 @@ void wrap_Tag()
.def(self <= self)
.def(self >= self)
.def("__str__", &Tag::operator std::string)
.def("__hash__", &hash)
;
implicitly_convertible<std::string, Tag>();
}

0 comments on commit 6bceb4e

Please sign in to comment.