Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XalanAutoPtr.hpp

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

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo