X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=include%2Fllvm%2FADT%2FIntrusiveRefCntPtr.h;h=8057ec10be00953e5ffcb3a1d6d857a85e9eefd0;hb=2b762697564ca1e12e0e974e93ceeb4c3420505c;hp=449f445e71b12b118fbcd4039781385a02980ba6;hpb=34bc6b6e787f27b5c9e05c82de4c1b4ac9b117bc;p=oota-llvm.git diff --git a/include/llvm/ADT/IntrusiveRefCntPtr.h b/include/llvm/ADT/IntrusiveRefCntPtr.h index 449f445e71b..8057ec10be0 100644 --- a/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -21,10 +21,9 @@ #ifndef LLVM_ADT_INTRUSIVEREFCNTPTR_H #define LLVM_ADT_INTRUSIVEREFCNTPTR_H -#include "llvm/Support/Casting.h" -#include "llvm/Support/Compiler.h" #include -#include +#include +#include namespace llvm { @@ -84,7 +83,7 @@ namespace llvm { friend struct IntrusiveRefCntPtrInfo; }; - + template struct IntrusiveRefCntPtrInfo { static void retain(T *obj) { obj->Retain(); } static void release(T *obj) { obj->Release(); } @@ -114,7 +113,7 @@ public: delete static_cast(this); } }; - + //===----------------------------------------------------------------------===// /// IntrusiveRefCntPtr - A template class that implements a "smart pointer" /// that assumes the wrapped object has a reference count associated @@ -154,13 +153,13 @@ public: } template - IntrusiveRefCntPtr(IntrusiveRefCntPtr&& S) : Obj(S.getPtr()) { - S.Obj = 0; + IntrusiveRefCntPtr(IntrusiveRefCntPtr&& S) : Obj(S.get()) { + S.Obj = nullptr; } template IntrusiveRefCntPtr(const IntrusiveRefCntPtr& S) - : Obj(S.getPtr()) { + : Obj(S.get()) { retain(); } @@ -175,12 +174,9 @@ public: T* operator->() const { return Obj; } - T* getPtr() const { return Obj; } + T* get() const { return Obj; } - typedef T* (IntrusiveRefCntPtr::*unspecified_bool_type) () const; - operator unspecified_bool_type() const { - return Obj == nullptr ? nullptr : &IntrusiveRefCntPtr::getPtr; - } + explicit operator bool() const { return Obj; } void swap(IntrusiveRefCntPtr& other) { T* tmp = other.Obj; @@ -194,71 +190,96 @@ public: } void resetWithoutRelease() { - Obj = 0; + Obj = nullptr; } private: void retain() { if (Obj) IntrusiveRefCntPtrInfo::retain(Obj); } void release() { if (Obj) IntrusiveRefCntPtrInfo::release(Obj); } + + template + friend class IntrusiveRefCntPtr; }; template inline bool operator==(const IntrusiveRefCntPtr& A, const IntrusiveRefCntPtr& B) { - return A.getPtr() == B.getPtr(); + return A.get() == B.get(); } template inline bool operator!=(const IntrusiveRefCntPtr& A, const IntrusiveRefCntPtr& B) { - return A.getPtr() != B.getPtr(); + return A.get() != B.get(); } template inline bool operator==(const IntrusiveRefCntPtr& A, U* B) { - return A.getPtr() == B; + return A.get() == B; } template inline bool operator!=(const IntrusiveRefCntPtr& A, U* B) { - return A.getPtr() != B; + return A.get() != B; } template inline bool operator==(T* A, const IntrusiveRefCntPtr& B) { - return A == B.getPtr(); + return A == B.get(); } template inline bool operator!=(T* A, const IntrusiveRefCntPtr& B) { - return A != B.getPtr(); + return A != B.get(); + } + + template + bool operator==(std::nullptr_t A, const IntrusiveRefCntPtr &B) { + return !B; + } + + template + bool operator==(const IntrusiveRefCntPtr &A, std::nullptr_t B) { + return B == A; + } + + template + bool operator!=(std::nullptr_t A, const IntrusiveRefCntPtr &B) { + return !(A == B); + } + + template + bool operator!=(const IntrusiveRefCntPtr &A, std::nullptr_t B) { + return !(A == B); } //===----------------------------------------------------------------------===// // LLVM-style downcasting support for IntrusiveRefCntPtr objects //===----------------------------------------------------------------------===// + template struct simplify_type; + template struct simplify_type > { typedef T* SimpleType; static SimpleType getSimplifiedValue(IntrusiveRefCntPtr& Val) { - return Val.getPtr(); + return Val.get(); } }; template struct simplify_type > { typedef /*const*/ T* SimpleType; static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr& Val) { - return Val.getPtr(); + return Val.get(); } };