2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: Ptr.h /main/2 1996/08/12 16:00:24 mgreess $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #define Ptr_INCLUDED 1
32 // T must have Resource as a public base class
33 // T may be an incomplete type
36 namespace SP_NAMESPACE {
46 Ptr<T> &operator=(const Ptr<T> &);
47 Ptr<T> &operator=(T *);
48 T *pointer() const { return ptr_; }
49 T *operator->() const { return ptr_; }
50 T &operator*() const { return *ptr_; }
51 void swap(Ptr<T> &p) {
56 Boolean isNull() const { return ptr_ == 0; }
57 // operator const void *() const { return ptr_; }
59 Boolean operator==(const Ptr<T> &p) const {
60 return ptr_ == p.ptr_;
62 Boolean operator!=(const Ptr<T> &p) const {
63 return ptr_ != p.ptr_;
65 Boolean operator==(const T *p) const {
68 Boolean operator!=(const T *p) const {
77 class ConstPtr : public Ptr<T> {
79 class ConstPtr : private Ptr<T> {
83 ConstPtr(T *ptr) : Ptr<T>(ptr) { }
84 ConstPtr(const Ptr<T> &p) : Ptr<T>(p) { }
85 ConstPtr(const ConstPtr<T> &p) : Ptr<T>(p) { }
88 ConstPtr<T> &operator=(const Ptr<T> &p) {
89 Ptr<T>::operator=(p); return *this;
92 ConstPtr<T> &operator=(const ConstPtr<T> &p) {
93 Ptr<T>::operator=(p); return *this;
95 ConstPtr<T> &operator=(T *p) {
96 Ptr<T>::operator=(p); return *this;
98 const T *pointer() const { return Ptr<T>::pointer(); }
99 const T *operator->() const { return Ptr<T>::pointer(); }
100 const T &operator*() const { return *Ptr<T>::pointer(); }
101 void swap(ConstPtr<T> &p) { Ptr<T>::swap(p); }
104 Boolean operator==(const Ptr<T> &p) const { return Ptr<T>::operator==(p); }
105 Boolean operator!=(const Ptr<T> &p) const { return Ptr<T>::operator!=(p); }
106 Boolean operator==(const ConstPtr<T> &p) const {
107 return Ptr<T>::operator==(p);
109 Boolean operator!=(const ConstPtr<T> &p) const {
110 return Ptr<T>::operator!=(p);
118 #endif /* not Ptr_INCLUDED */
120 #ifdef SP_DEFINE_TEMPLATES