source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/CountedPointer.c @ 2674

Revision 2674, 2.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: CountedPointer.c 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#if defined(XERCES_TMPLSINC)
27#include <xercesc/util/CountedPointer.hpp>
28#endif
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  CountedPointerTo: Constructors and Destructor
34// ---------------------------------------------------------------------------
35template <class T> CountedPointerTo<T>::
36CountedPointerTo(const CountedPointerTo<T>& toCopy) :
37
38    fPtr(toCopy.fPtr)
39{
40    if (fPtr)
41        fPtr->addRef();
42}
43
44template <class T> CountedPointerTo<T>::CountedPointerTo(T* p) :
45
46    fPtr(p)
47{
48    if (fPtr)
49        fPtr->addRef();
50}
51
52template <class T> CountedPointerTo<T>::~CountedPointerTo()
53{
54    if (fPtr)
55        fPtr->removeRef();
56}
57
58
59// ---------------------------------------------------------------------------
60//  CountedPointerTo: Operators
61// ---------------------------------------------------------------------------
62template <class T> CountedPointerTo<T>&
63CountedPointerTo<T>::operator=(const CountedPointerTo<T>& other)
64{
65    if (this == &other)
66        return *this;
67
68    if (other.fPtr)
69        other.fPtr->addRef();
70
71    if (fPtr)
72        fPtr->removeRef();
73
74    fPtr = other.fPtr;
75    return *this;
76}
77
78template <class T> CountedPointerTo<T>::operator T*()
79{
80    return fPtr;
81}
82
83template <class T> const T* CountedPointerTo<T>::operator->() const
84{
85    return fPtr;
86}
87
88template <class T> T* CountedPointerTo<T>::operator->()
89{
90    return fPtr;
91}
92
93template <class T> const T& CountedPointerTo<T>::operator*() const
94{
95    if (!fPtr)
96        ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, 0);
97    return *fPtr;
98}
99
100template <class T> T& CountedPointerTo<T>::operator*()
101{
102    if (!fPtr)
103        ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, 0);
104    return *fPtr;
105}
106
107XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.