source: NonGTP/Xerces/xerces/include/xercesc/util/CountedPointer.c @ 358

Revision 358, 3.6 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2000,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * $Log: CountedPointer.c,v $
19 * Revision 1.4  2004/09/08 13:56:21  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.3  2003/12/17 00:18:35  cargilld
23 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
24 *
25 * Revision 1.2  2002/11/04 15:22:03  tng
26 * C++ Namespace Support.
27 *
28 * Revision 1.1.1.1  2002/02/01 22:22:10  peiyongz
29 * sane_include
30 *
31 * Revision 1.3  2000/03/02 19:54:38  roddey
32 * This checkin includes many changes done while waiting for the
33 * 1.1.0 code to be finished. I can't list them all here, but a list is
34 * available elsewhere.
35 *
36 * Revision 1.2  2000/02/06 07:48:01  rahulj
37 * Year 2K copyright swat.
38 *
39 * Revision 1.1.1.1  1999/11/09 01:04:12  twl
40 * Initial checkin
41 *
42 * Revision 1.2  1999/11/08 20:45:05  rahul
43 * Swat for adding in Product name and CVS comment log variable.
44 *
45 */
46
47
48// ---------------------------------------------------------------------------
49//  Includes
50// ---------------------------------------------------------------------------
51#if defined(XERCES_TMPLSINC)
52#include <xercesc/util/CountedPointer.hpp>
53#endif
54
55XERCES_CPP_NAMESPACE_BEGIN
56
57// ---------------------------------------------------------------------------
58//  CountedPointerTo: Constructors and Destructor
59// ---------------------------------------------------------------------------
60template <class T> CountedPointerTo<T>::
61CountedPointerTo(const CountedPointerTo<T>& toCopy) :
62
63    fPtr(toCopy.fPtr)
64{
65    if (fPtr)
66        fPtr->addRef();
67}
68
69template <class T> CountedPointerTo<T>::CountedPointerTo(T* p) :
70
71    fPtr(p)
72{
73    if (fPtr)
74        fPtr->addRef();
75}
76
77template <class T> CountedPointerTo<T>::~CountedPointerTo()
78{
79    if (fPtr)
80        fPtr->removeRef();
81}
82
83
84// ---------------------------------------------------------------------------
85//  CountedPointerTo: Operators
86// ---------------------------------------------------------------------------
87template <class T> CountedPointerTo<T>&
88CountedPointerTo<T>::operator=(const CountedPointerTo<T>& other)
89{
90    if (this == &other)
91        return *this;
92
93    if (other.fPtr)
94        other.fPtr->addRef();
95
96    if (fPtr)
97        fPtr->removeRef();
98
99    fPtr = other.fPtr;
100    return *this;
101}
102
103template <class T> CountedPointerTo<T>::operator T*()
104{
105    return fPtr;
106}
107
108template <class T> const T* CountedPointerTo<T>::operator->() const
109{
110    return fPtr;
111}
112
113template <class T> T* CountedPointerTo<T>::operator->()
114{
115    return fPtr;
116}
117
118template <class T> const T& CountedPointerTo<T>::operator*() const
119{
120    if (!fPtr)
121        ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero);
122    return *fPtr;
123}
124
125template <class T> T& CountedPointerTo<T>::operator*()
126{
127    if (!fPtr)
128        ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero);
129    return *fPtr;
130}
131
132XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.