]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/RefPtr.h
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / wtf / RefPtr.h
index d43a071f68206cde08ff8666610d596e4c930ca5..929e745b51c5254233fd1fef5a97800f047108ab 100644 (file)
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
 /*
 /*
- *  Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *  Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -31,9 +30,11 @@ namespace WTF {
 
     template <typename T> class PassRefPtr;
 
 
     template <typename T> class PassRefPtr;
 
+    enum HashTableDeletedValueType { HashTableDeletedValue };
+
     template <typename T> class RefPtr {
     public:
     template <typename T> class RefPtr {
     public:
-        RefPtr() : m_ptr(0) {}
+        RefPtr() : m_ptr(0) { }
         RefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
         RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->ref(); }
         // see comment in PassRefPtr.h for why this takes const reference
         RefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
         RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->ref(); }
         // see comment in PassRefPtr.h for why this takes const reference
@@ -42,6 +43,10 @@ namespace WTF {
         // Special constructor for cases where we overwrite an object in place.
         RefPtr(PlacementNewAdoptType) { }
 
         // Special constructor for cases where we overwrite an object in place.
         RefPtr(PlacementNewAdoptType) { }
 
+        // Hash table deleted values, which are only constructed and never copied or destroyed.
+        RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
+        bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
+
         ~RefPtr() { if (T* ptr = m_ptr) ptr->deref(); }
         
         template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); }
         ~RefPtr() { if (T* ptr = m_ptr) ptr->deref(); }
         
         template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); }
@@ -52,13 +57,17 @@ namespace WTF {
         PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; }
 
         T& operator*() const { return *m_ptr; }
         PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; }
 
         T& operator*() const { return *m_ptr; }
-        ALWAYS_INLINE T *operator->() const { return m_ptr; }
+        ALWAYS_INLINE Toperator->() const { return m_ptr; }
         
         bool operator!() const { return !m_ptr; }
     
         // This conversion operator allows implicit conversion to bool but not to other integer types.
         
         bool operator!() const { return !m_ptr; }
     
         // This conversion operator allows implicit conversion to bool but not to other integer types.
+#if COMPILER(WINSCW)
+        operator bool() const { return m_ptr; }
+#else
         typedef T* RefPtr::*UnspecifiedBoolType;
         operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
         typedef T* RefPtr::*UnspecifiedBoolType;
         operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
+#endif
         
         RefPtr& operator=(const RefPtr&);
         RefPtr& operator=(T*);
         
         RefPtr& operator=(const RefPtr&);
         RefPtr& operator=(T*);
@@ -69,6 +78,8 @@ namespace WTF {
         void swap(RefPtr&);
 
     private:
         void swap(RefPtr&);
 
     private:
+        static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
+
         T* m_ptr;
     };
     
         T* m_ptr;
     };