]>
git.saurik.com Git - iphone-api.git/blob - WebCore/DocPtr.h
2 * This file is part of the DOM implementation for KDE.
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.
27 template <class T
> class DocPtr
{
29 DocPtr() : m_ptr(0) {}
30 DocPtr(T
*ptr
) : m_ptr(ptr
) { if (ptr
) ptr
->selfOnlyRef(); }
31 DocPtr(const DocPtr
&o
) : m_ptr(o
.m_ptr
) { if (T
*ptr
= m_ptr
) ptr
->selfOnlyRef(); }
32 ~DocPtr() { if (T
*ptr
= m_ptr
) ptr
->selfOnlyDeref(); }
34 template <class U
> DocPtr(const DocPtr
<U
> &o
) : m_ptr(o
.get()) { if (T
*ptr
= m_ptr
) ptr
->selfOnlyRef(); }
36 void resetSkippingRef(T
*o
) { m_ptr
= o
; }
38 T
*get() const { return m_ptr
; }
40 T
&operator*() const { return *m_ptr
; }
41 T
*operator->() const { return m_ptr
; }
43 bool operator!() const { return !m_ptr
; }
45 // this type conversion operator allows implicit conversion to
46 // bool but not to other integer types
48 typedef T
* (DocPtr::*UnspecifiedBoolType
)() const;
49 operator UnspecifiedBoolType() const
51 return m_ptr
? &DocPtr::get
: 0;
54 DocPtr
&operator=(const DocPtr
&);
55 DocPtr
&operator=(T
*);
61 template <class T
> DocPtr
<T
> &DocPtr
<T
>::operator=(const DocPtr
<T
> &o
)
72 template <class T
> inline DocPtr
<T
> &DocPtr
<T
>::operator=(T
*optr
)
82 template <class T
> inline bool operator==(const DocPtr
<T
> &a
, const DocPtr
<T
> &b
)
84 return a
.get() == b
.get();
87 template <class T
> inline bool operator==(const DocPtr
<T
> &a
, const T
*b
)
92 template <class T
> inline bool operator==(const T
*a
, const DocPtr
<T
> &b
)
97 template <class T
> inline bool operator!=(const DocPtr
<T
> &a
, const DocPtr
<T
> &b
)
99 return a
.get() != b
.get();
102 template <class T
> inline bool operator!=(const DocPtr
<T
> &a
, const T
*b
)
107 template <class T
> inline bool operator!=(const T
*a
, const DocPtr
<T
> &b
)
112 } // namespace WebCore