-// -*- 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
template <typename T> class PassRefPtr;
+ enum HashTableDeletedValueType { HashTableDeletedValue };
+
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
// 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(); }
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 T* operator->() const { return m_ptr; }
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; }
+#endif
RefPtr& operator=(const RefPtr&);
RefPtr& operator=(T*);
void swap(RefPtr&);
private:
+ static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
+
T* m_ptr;
};