From 9f3f29a79d08a4d1a5081ffe2bd9d59436a873bf Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 23 Sep 2021 10:14:19 -0400 Subject: Add comparison operators for SizeWithConfidence and OffsetWithConfidence --- python/types.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'python') diff --git a/python/types.py b/python/types.py index 2a141846..c5ce1924 100644 --- a/python/types.py +++ b/python/types.py @@ -346,6 +346,27 @@ class OffsetWithConfidence: def __int__(self): return self.value + def __eq__(self, other): + if not isinstance(other, self.__class__): + return self.value == int(other) + else: + return (self.value, self.confidence) == (other.value, other.confidence) + + def __ne__(self, other): + return not (self == other) + + def __gt__(self, other): + return self.value > int(other) + + def __le__(self, other): + return self.value <= int(other) + + def __ge__(self, other): + return self.value >= int(other) + + def __lt__(self, other): + return self.value < int(other) + def _to_core_struct(self) -> core.BNOffsetWithConfidence: result = core.BNOffsetWithConfidence() result.value = self.value @@ -419,6 +440,27 @@ class SizeWithConfidence: def __int__(self): return self.value + def __eq__(self, other): + if not isinstance(other, self.__class__): + return self.value == int(other) + else: + return (self.value, self.confidence) == (other.value, other.confidence) + + def __ne__(self, other): + return not (self == other) + + def __gt__(self, other): + return self.value > int(other) + + def __le__(self, other): + return self.value <= int(other) + + def __ge__(self, other): + return self.value >= int(other) + + def __lt__(self, other): + return self.value < int(other) + def _to_core_struct(self) -> core.BNSizeWithConfidence: result = core.BNSizeWithConfidence() result.value = self.value -- cgit v1.3.1