Xalan-C++ API Reference 1.12.0
XalanAutoPtr.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALANAUTOPTR_HEADER_GUARD_1357924680)
19#define XALANAUTOPTR_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
28#include <cstddef>
29
30
31
32namespace XALAN_CPP_NAMESPACE {
33
34
35
36// We're using our own auto_ptr-like class due to wide
37// variations amongst the varous platforms we have to
38// support
39template<class Type>
41{
42public:
43
45 m_pointer(thePointer)
46 {
47 }
48
50 m_pointer(const_cast<XalanAutoPtr<Type>&>(theSource).release())
51 {
52 }
53
56 {
57 if (this != &theRHS)
58 {
59 // This test ought not to be necessary, but
60 // MSVC 6.0 calls delete, which checks for 0.
61 // The problem with that is the locking is
62 // extremely expensive.
63 if (m_pointer != 0)
64 {
65 delete m_pointer;
66 }
67
68 m_pointer = theRHS.release();
69 }
70
71 return *this;
72 }
73
75 {
76 // See note in operator=() about this...
77 if (m_pointer != 0)
78 {
79 delete m_pointer;
80 }
81 }
82
83 Type&
84 operator*() const
85 {
86 return *m_pointer;
87 }
88
89 Type*
90 operator->() const
91 {
92 return m_pointer;
93 }
94
95 Type*
96 get() const
97 {
98 return m_pointer;
99 }
100
101 Type*
103 {
104 Type* const temp = m_pointer;
105
106 m_pointer = 0;
107
108 return temp;
109 }
110
111 void
113 {
114 // See note in operator=() about this...
115 if (m_pointer != 0)
116 {
117 delete m_pointer;
118 }
119
120 m_pointer = thePointer;
121 }
122
123private:
124
125 Type* m_pointer;
126};
127
128
129
130// A class similar to XalanAutoPtr, but for arrays.
131template<class Type>
133{
134public:
135
137 m_pointer(thePointer)
138 {
139 }
140
142 m_pointer(((XalanArrayAutoPtr<Type>&)theSource).release())
143 {
144 }
145
148 {
149 if (this != &theRHS)
150 {
151 // This test ought not to be necessary, but
152 // MSVC 6.0 calls delete, which checks for 0.
153 // The problem with that is the locking is
154 // extremely expensive.
155 if (m_pointer != 0)
156 {
157 delete [] m_pointer;
158 }
159
160 m_pointer = theRHS.release();
161 }
162
163 return *this;
164 }
165
167 {
168 // See note in operator=() about this...
169 if (m_pointer != 0)
170 {
171 delete [] m_pointer;
172 }
173 }
174
175 Type&
176 operator*() const
177 {
178 return *m_pointer;
179 }
180
181 Type&
182 operator[](std::size_t index) const
183 {
184 return m_pointer[index];
185 }
186
187 Type*
188 get() const
189 {
190 return m_pointer;
191 }
192
193 Type*
195 {
196 Type* const temp = m_pointer;
197
198 m_pointer = 0;
199
200 return temp;
201 }
202
203 void
205 {
206 // See note in operator=() about this...
207 if (m_pointer != 0)
208 {
209 delete [] m_pointer;
210 }
211
212 m_pointer = thePointer;
213 }
214
215private:
216
217 Type* m_pointer;
218};
219
220
221
222}
223
224
225
226#endif // if !defined(XALANAUTOPTR_HEADER_GUARD_1357924680)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
void reset(Type *thePointer=0)
Type & operator[](std::size_t index) const
XalanArrayAutoPtr(Type *thePointer=0)
XalanArrayAutoPtr(const XalanArrayAutoPtr< Type > &theSource)
XalanArrayAutoPtr< Type > & operator=(XalanArrayAutoPtr< Type > &theRHS)
XalanAutoPtr< Type > & operator=(XalanAutoPtr< Type > &theRHS)
XalanAutoPtr(Type *thePointer=0)
XalanAutoPtr(const XalanAutoPtr< Type > &theSource)
Type * operator->() const
Type & operator*() const
void reset(Type *thePointer=0)