Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Support / Pointer.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 librararies 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 /*      Copyright (c) 1995 FUJITSU LIMITED      */
24 /*      All Rights Reserved                     */
25
26 /*
27  * $XConsortium: Pointer.C /main/4 1996/09/27 19:02:17 drk $
28  *
29  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
30  * All rights reserved.  Unpublished -- rights reserved under
31  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
32  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
33  * OR DISCLOSURE.
34  * 
35  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
36  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
37  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
38  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
39  * INTERNATIONAL, LTD.
40  * 
41  *                         RESTRICTED RIGHTS LEGEND
42  * Use, duplication, or disclosure by the Government is subject
43  * to the restrictions as set forth in subparagraph (c)(l)(ii)
44  * of the Rights in Technical Data and Computer Software clause
45  * at DFARS 252.227-7013.
46  *
47  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
48  *                  1315 Dell Avenue
49  *                  Campbell, CA  95008
50  * 
51  */
52
53 template <class T> 
54 Pointer<T>::Pointer (const Pointer<T> &pointer)
55 : f_pointer (pointer.f_pointer)
56 {
57   ON_DEBUG (printf ("Pointer& (0x%p) @ 0x%p\n", f_pointer, this));
58   if (f_pointer) f_pointer->reference();
59 }
60
61 template <class T> 
62 Pointer<T>::Pointer (T *pointer)
63 : f_pointer (pointer)
64 {
65   ON_DEBUG (printf ("Pointer* (0x%p) @ 0x%p\n", f_pointer, this));
66   if (f_pointer) f_pointer->reference();
67 }
68
69 #if 0
70 template <class T> 
71 Pointer<T>::Pointer (T &object)
72 : f_pointer (&object)
73 {
74   if (f_pointer) f_pointer->reference();
75 }
76 #endif
77
78 template <class T> 
79 Pointer<T>::~Pointer()
80 {
81   ON_DEBUG (printf ("~Pointer (0x%p) @ 0x%p\n", f_pointer, this));
82   if (f_pointer) f_pointer->unreference();
83 }
84
85 template <class T>
86 Pointer<T> &
87 Pointer<T>::operator= (T *pointer)
88 {
89   if (f_pointer) f_pointer->unreference();
90   f_pointer = pointer;
91   ON_DEBUG (printf ("Pointer = 0x%p @ 0x%p\n", f_pointer, this));
92   if (f_pointer) f_pointer->reference();
93   return (*this);
94 }
95
96 template <class T>
97 Pointer<T> &
98 Pointer<T>::operator= (const Pointer<T> &pointer)
99 {
100   if (f_pointer) f_pointer->unreference();
101   f_pointer = pointer.f_pointer;
102   ON_DEBUG (printf ("Pointer<T> = 0x%p @ 0x%p\n", f_pointer, this));
103   if (f_pointer) f_pointer->reference();
104   return (*this);
105 }
106
107 template <class T>
108  bool
109 Pointer<T>::operator== (const Pointer<T> &pointer) const
110 {
111   ON_DEBUG (printf ("Pointer== this = 0x%p, ", this));
112   ON_DEBUG (printf ("Pointer== this->f_pointer = 0x%p, ", f_pointer));
113   ON_DEBUG (printf ("arg = 0x%p, ", &pointer));
114   ON_DEBUG (printf ("arg->f_pointer = 0x%p\n", pointer.f_pointer));
115   if ((f_pointer == NULL && pointer.f_pointer != NULL) ||
116       (f_pointer != NULL && pointer.f_pointer == NULL))
117     {
118       ON_DEBUG (puts ("1 Done Pointer =="));
119       return (0);
120     }
121   else if (f_pointer == pointer.f_pointer)
122     {
123       ON_DEBUG (puts ("2 Done Pointer =="));
124       return (1);
125     }
126   else
127     {
128       ON_DEBUG (puts ("3 Done Pointer =="));
129       return (*f_pointer == *pointer.f_pointer);
130     }
131 }
132
133
134 template <class T>
135  bool
136 Pointer<T>::operator!= (const Pointer<T> &pointer) const
137 {
138   if ((f_pointer == NULL && pointer.f_pointer != NULL) ||
139       (f_pointer != NULL && pointer.f_pointer == NULL))
140     return (1);
141   else if (f_pointer == NULL && pointer.f_pointer == NULL)
142     return (0);
143   else
144     return (!(*f_pointer == *pointer.f_pointer));
145 }
146
147
148 template <class T>
149 bool
150 Pointer<T>::operator==(const int) const
151 {
152   return f_pointer == NULL ;
153 }
154
155 template <class T>
156 bool
157 Pointer<T>::operator!=(const int) const
158 {
159   return f_pointer != NULL ;
160 }