]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/ListRefPtr.h
0f807b0550ae5cc29b030cc0826621c99d8dcf1b
1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * Copyright (C) 2005, 2006 Apple Computer, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef WTF_ListRefPtr_h
23 #define WTF_ListRefPtr_h
25 #include <wtf/RefPtr.h>
29 // Specialized version of RefPtr desgined for use in singly-linked lists.
30 // Derefs the list iteratively to avoid recursive derefing that can overflow the stack.
31 template <typename T
> class ListRefPtr
: public RefPtr
<T
> {
33 ListRefPtr() : RefPtr
<T
>() {}
34 ListRefPtr(T
* ptr
) : RefPtr
<T
>(ptr
) {}
35 ListRefPtr(const RefPtr
<T
>& o
) : RefPtr
<T
>(o
) {}
36 // see comment in PassRefPtr.h for why this takes const reference
37 template <typename U
> ListRefPtr(const PassRefPtr
<U
>& o
) : RefPtr
<T
>(o
) {}
40 RefPtr
<T
> reaper
= this->release();
41 while (reaper
&& reaper
->refcount() == 1)
42 reaper
= reaper
->releaseNext(); // implicitly protects reaper->next, then derefs reaper
45 ListRefPtr
& operator=(T
* optr
) { RefPtr
<T
>::operator=(optr
); return *this; }
46 ListRefPtr
& operator=(const RefPtr
<T
>& o
) { RefPtr
<T
>::operator=(o
); return *this; }
47 ListRefPtr
& operator=(const PassRefPtr
<T
>& o
) { RefPtr
<T
>::operator=(o
); return *this; }
48 template <typename U
> ListRefPtr
& operator=(const RefPtr
<U
>& o
) { RefPtr
<T
>::operator=(o
); return *this; }
49 template <typename U
> ListRefPtr
& operator=(const PassRefPtr
<U
>& o
) { RefPtr
<T
>::operator=(o
); return *this; }
52 template <typename T
> inline T
* getPtr(const ListRefPtr
<T
>& p
)
59 using WTF::ListRefPtr
;
61 #endif // WTF_ListRefPtr_h