From ebe1b0763f3b33073826593006829b4e3982e328 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sun, 27 May 2018 17:31:49 -0600 Subject: [PATCH] express: Allow WeakPointer comparisons to nullptr This saves us from having to do casts like: if (foo == (const FooType *)nullptr) { ... } --- panda/src/express/weakPointerToBase.I | 54 +++++++++++++++++++++++++++ panda/src/express/weakPointerToBase.h | 7 ++++ 2 files changed, 61 insertions(+) diff --git a/panda/src/express/weakPointerToBase.I b/panda/src/express/weakPointerToBase.I index 1c831529a1..5ba737d507 100644 --- a/panda/src/express/weakPointerToBase.I +++ b/panda/src/express/weakPointerToBase.I @@ -292,6 +292,51 @@ operator >= (To *other) const { return (To *)_void_ptr >= other; } +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator == (nullptr_t) const { + return _void_ptr == nullptr; +} + +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator != (nullptr_t) const { + return _void_ptr != nullptr; +} + +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator > (nullptr_t) const { + return _void_ptr != nullptr; +} + +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator <= (nullptr_t) const { + return _void_ptr == nullptr; +} + +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator >= (nullptr_t) const { + return true; +} + /** * */ @@ -392,6 +437,15 @@ operator < (const To *other) const { return (To *)_void_ptr < other; } +/** + * + */ +template +INLINE bool WeakPointerToBase:: +operator < (nullptr_t) const { + return false; +} + /** * */ diff --git a/panda/src/express/weakPointerToBase.h b/panda/src/express/weakPointerToBase.h index 4870ef21d8..20505191e3 100644 --- a/panda/src/express/weakPointerToBase.h +++ b/panda/src/express/weakPointerToBase.h @@ -60,6 +60,12 @@ public: INLINE bool operator <= (To *other) const; INLINE bool operator >= (To *other) const; + INLINE bool operator == (nullptr_t) const; + INLINE bool operator != (nullptr_t) const; + INLINE bool operator > (nullptr_t) const; + INLINE bool operator <= (nullptr_t) const; + INLINE bool operator >= (nullptr_t) const; + INLINE bool operator == (const WeakPointerToBase &other) const; INLINE bool operator != (const WeakPointerToBase &other) const; INLINE bool operator > (const WeakPointerToBase &other) const; @@ -73,6 +79,7 @@ public: INLINE bool operator >= (const PointerToBase &other) const; #endif // WIN32_VC INLINE bool operator < (const To *other) const; + INLINE bool operator < (nullptr_t) const; INLINE bool operator < (const WeakPointerToBase &other) const; INLINE bool operator < (const PointerToBase &other) const; #endif // CPPPARSER