nsgmls: remove register keyword
[oweals/cde.git] / cde / programs / nsgmls / Ptr.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Ptr.C /main/1 1996/07/29 17:02:08 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Ptr_DEF_INCLUDED
28 #define Ptr_DEF_INCLUDED 1
29
30 #ifdef SP_NAMESPACE
31 namespace SP_NAMESPACE {
32 #endif
33
34 template<class T>
35 Ptr<T>::Ptr(T *ptr) : ptr_(ptr)
36 {
37   if (ptr_)
38     ptr_->ref();
39 }
40
41 template<class T>
42 Ptr<T>::~Ptr()
43 {
44   if (ptr_) {
45     if (ptr_->unref())
46       delete ptr_;
47     ptr_ = 0;
48   }
49 }
50
51 template<class T>
52 Ptr<T>::Ptr(const Ptr<T> &p)
53 : ptr_(p.ptr_)
54 {
55   if (p.ptr_)
56     p.ptr_->ref();
57 }
58
59 template<class T>
60 Ptr<T> &Ptr<T>::operator=(const Ptr<T> &p)
61 {
62   if (p.ptr_)
63     p.ptr_->ref();
64   if (ptr_ && ptr_->unref())
65     delete ptr_;
66   ptr_ = p.ptr_;
67   return *this;
68 }
69
70 template<class T>
71 Ptr<T> &Ptr<T>::operator=(T *p)
72 {
73   if (p)
74     p->ref();
75   if (ptr_ && ptr_->unref())
76     delete ptr_;
77   ptr_ = p;
78   return *this;
79 }
80
81 template<class T>
82 void Ptr<T>::clear()
83 {
84   if (ptr_) {
85     if (ptr_->unref())
86       delete ptr_;
87     ptr_ = 0;
88   }
89 }
90
91 #ifdef SP_NAMESPACE
92 }
93 #endif
94
95 #endif /* not Ptr_DEF_INCLUDED */