00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALANAUTOPTR_HEADER_GUARD_1357924680) 00019 #define XALANAUTOPTR_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00025 00026 00027 00028 #include <cstddef> 00029 00030 00031 00032 XALAN_CPP_NAMESPACE_BEGIN 00033 00034 00035 00036 // We're using our own auto_ptr-like class due to wide 00037 // variations amongst the varous platforms we have to 00038 // support 00039 template<class Type> 00040 class XalanAutoPtr 00041 { 00042 public: 00043 00044 XalanAutoPtr(Type* thePointer = 0) : 00045 m_pointer(thePointer) 00046 { 00047 } 00048 00049 XalanAutoPtr(const XalanAutoPtr<Type>& theSource) : 00050 m_pointer(const_cast<XalanAutoPtr<Type>&>(theSource).release()) 00051 { 00052 } 00053 00054 XalanAutoPtr<Type>& 00055 operator=(XalanAutoPtr<Type>& theRHS) 00056 { 00057 if (this != &theRHS) 00058 { 00059 // This test ought not to be necessary, but 00060 // MSVC 6.0 calls delete, which checks for 0. 00061 // The problem with that is the locking is 00062 // extremely expensive. 00063 if (m_pointer != 0) 00064 { 00065 delete m_pointer; 00066 } 00067 00068 m_pointer = theRHS.release(); 00069 } 00070 00071 return *this; 00072 } 00073 00074 ~XalanAutoPtr() 00075 { 00076 // See note in operator=() about this... 00077 if (m_pointer != 0) 00078 { 00079 delete m_pointer; 00080 } 00081 } 00082 00083 Type& 00084 operator*() const 00085 { 00086 return *m_pointer; 00087 } 00088 00089 Type* 00090 operator->() const 00091 { 00092 return m_pointer; 00093 } 00094 00095 Type* 00096 get() const 00097 { 00098 return m_pointer; 00099 } 00100 00101 Type* 00102 release() 00103 { 00104 Type* const temp = m_pointer; 00105 00106 m_pointer = 0; 00107 00108 return temp; 00109 } 00110 00111 void 00112 reset(Type* thePointer = 0) 00113 { 00114 // See note in operator=() about this... 00115 if (m_pointer != 0) 00116 { 00117 delete m_pointer; 00118 } 00119 00120 m_pointer = thePointer; 00121 } 00122 00123 private: 00124 00125 Type* m_pointer; 00126 }; 00127 00128 00129 00130 // A class similar to XalanAutoPtr, but for arrays. 00131 template<class Type> 00132 class XalanArrayAutoPtr 00133 { 00134 public: 00135 00136 XalanArrayAutoPtr(Type* thePointer = 0) : 00137 m_pointer(thePointer) 00138 { 00139 } 00140 00141 XalanArrayAutoPtr(const XalanArrayAutoPtr<Type>& theSource) : 00142 m_pointer(((XalanArrayAutoPtr<Type>&)theSource).release()) 00143 { 00144 } 00145 00146 XalanArrayAutoPtr<Type>& 00147 operator=(XalanArrayAutoPtr<Type>& theRHS) 00148 { 00149 if (this != &theRHS) 00150 { 00151 // This test ought not to be necessary, but 00152 // MSVC 6.0 calls delete, which checks for 0. 00153 // The problem with that is the locking is 00154 // extremely expensive. 00155 if (m_pointer != 0) 00156 { 00157 delete [] m_pointer; 00158 } 00159 00160 m_pointer = theRHS.release(); 00161 } 00162 00163 return *this; 00164 } 00165 00166 ~XalanArrayAutoPtr() 00167 { 00168 // See note in operator=() about this... 00169 if (m_pointer != 0) 00170 { 00171 delete [] m_pointer; 00172 } 00173 } 00174 00175 Type& 00176 operator*() const 00177 { 00178 return *m_pointer; 00179 } 00180 00181 Type& 00182 #if defined(XALAN_STRICT_ANSI_HEADERS) 00183 operator[](std::size_t index) const 00184 #else 00185 operator[](size_t index) const 00186 #endif 00187 { 00188 return m_pointer[index]; 00189 } 00190 00191 Type* 00192 get() const 00193 { 00194 return m_pointer; 00195 } 00196 00197 Type* 00198 release() 00199 { 00200 Type* const temp = m_pointer; 00201 00202 m_pointer = 0; 00203 00204 return temp; 00205 } 00206 00207 void 00208 reset(Type* thePointer = 0) 00209 { 00210 // See note in operator=() about this... 00211 if (m_pointer != 0) 00212 { 00213 delete [] m_pointer; 00214 } 00215 00216 m_pointer = thePointer; 00217 } 00218 00219 private: 00220 00221 Type* m_pointer; 00222 }; 00223 00224 00225 00226 XALAN_CPP_NAMESPACE_END 00227 00228 00229 00230 #endif // if !defined(XALANAUTOPTR_HEADER_GUARD_1357924680)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|