Przeglądaj źródła

express: Allow WeakPointer comparisons to nullptr

This saves us from having to do casts like:
if (foo == (const FooType *)nullptr) {
  ...
}
Sam Edwards 7 lat temu
rodzic
commit
ebe1b0763f

+ 54 - 0
panda/src/express/weakPointerToBase.I

@@ -292,6 +292,51 @@ operator >= (To *other) const {
   return (To *)_void_ptr >= other;
 }
 
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator == (nullptr_t) const {
+  return _void_ptr == nullptr;
+}
+
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator != (nullptr_t) const {
+  return _void_ptr != nullptr;
+}
+
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator > (nullptr_t) const {
+  return _void_ptr != nullptr;
+}
+
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator <= (nullptr_t) const {
+  return _void_ptr == nullptr;
+}
+
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator >= (nullptr_t) const {
+  return true;
+}
+
 /**
  *
  */
@@ -392,6 +437,15 @@ operator < (const To *other) const {
   return (To *)_void_ptr < other;
 }
 
+/**
+ *
+ */
+template<class T>
+INLINE bool WeakPointerToBase<T>::
+operator < (nullptr_t) const {
+  return false;
+}
+
 /**
  *
  */

+ 7 - 0
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<To> &other) const;
   INLINE bool operator != (const WeakPointerToBase<To> &other) const;
   INLINE bool operator > (const WeakPointerToBase<To> &other) const;
@@ -73,6 +79,7 @@ public:
   INLINE bool operator >= (const PointerToBase<To> &other) const;
 #endif  // WIN32_VC
   INLINE bool operator < (const To *other) const;
+  INLINE bool operator < (nullptr_t) const;
   INLINE bool operator < (const WeakPointerToBase<To> &other) const;
   INLINE bool operator < (const PointerToBase<To> &other) const;
 #endif  // CPPPARSER