Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:24

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 
0023 // ---------------------------------------------------------------------------
0024 //  Includes
0025 // ---------------------------------------------------------------------------
0026 #if defined(XERCES_TMPLSINC)
0027 #include <xercesc/util/Janitor.hpp>
0028 #endif
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 // ---------------------------------------------------------------------------
0033 //  Janitor: Constructors and Destructor
0034 // ---------------------------------------------------------------------------
0035 template <class T> Janitor<T>::Janitor(T* const toDelete) :
0036     fData(toDelete)
0037 {
0038 }
0039 
0040 
0041 template <class T> Janitor<T>::~Janitor()
0042 {
0043     reset();
0044 }
0045 
0046 
0047 // ---------------------------------------------------------------------------
0048 //  Janitor: Public, non-virtual methods
0049 // ---------------------------------------------------------------------------
0050 template <class T> void
0051 Janitor<T>::orphan()
0052 {
0053    release();
0054 }
0055 
0056 
0057 template <class T> T&
0058 Janitor<T>::operator*() const
0059 {
0060     return *fData;
0061 }
0062 
0063 
0064 template <class T> T*
0065 Janitor<T>::operator->() const
0066 {
0067     return fData;
0068 }
0069 
0070 
0071 template <class T> T*
0072 Janitor<T>::get() const
0073 {
0074     return fData;
0075 }
0076 
0077 
0078 template <class T> T*
0079 Janitor<T>::release()
0080 {
0081     T* p = fData;
0082     fData = 0;
0083     return p;
0084 }
0085 
0086 
0087 template <class T> void Janitor<T>::reset(T* p)
0088 {
0089     if (fData)
0090         delete fData;
0091 
0092     fData = p;
0093 }
0094 
0095 template <class T> bool Janitor<T>::isDataNull()
0096 {
0097     return (fData == 0);
0098 }
0099 
0100 
0101 // -----------------------------------------------------------------------
0102 //  ArrayJanitor: Constructors and Destructor
0103 // -----------------------------------------------------------------------
0104 template <class T> ArrayJanitor<T>::ArrayJanitor(T* const toDelete) :
0105     fData(toDelete)
0106     , fMemoryManager(0)
0107 {
0108 }
0109 
0110 template <class T>
0111 ArrayJanitor<T>::ArrayJanitor(T* const toDelete,
0112                               MemoryManager* const manager) :
0113     fData(toDelete)
0114     , fMemoryManager(manager)
0115 {
0116 }
0117 
0118 
0119 template <class T> ArrayJanitor<T>::~ArrayJanitor()
0120 {
0121     reset();
0122 }
0123 
0124 
0125 // -----------------------------------------------------------------------
0126 //  ArrayJanitor: Public, non-virtual methods
0127 // -----------------------------------------------------------------------
0128 template <class T> void
0129 ArrayJanitor<T>::orphan()
0130 {
0131    release();
0132 }
0133 
0134 
0135 //  Look, Ma! No hands! Don't call this with null data!
0136 template <class T> T&
0137 ArrayJanitor<T>::operator[](XMLSize_t index) const
0138 {
0139     //  TODO: Add appropriate exception
0140     return fData[index];
0141 }
0142 
0143 
0144 template <class T> T*
0145 ArrayJanitor<T>::get() const
0146 {
0147     return fData;
0148 }
0149 
0150 
0151 template <class T> T*
0152 ArrayJanitor<T>::release()
0153 {
0154     T* p = fData;
0155     fData = 0;
0156     return p;
0157 }
0158 
0159 
0160 template <class T> void
0161 ArrayJanitor<T>::reset(T* p)
0162 {
0163     if (fData) {
0164 
0165         if (fMemoryManager)
0166             fMemoryManager->deallocate((void*)fData);
0167         else
0168             delete [] fData;
0169     }
0170 
0171     fData = p;
0172     fMemoryManager = 0;
0173 }
0174 
0175 template <class T> void
0176 ArrayJanitor<T>::reset(T* p, MemoryManager* const manager)
0177 {
0178     if (fData) {
0179 
0180         if (fMemoryManager)
0181             fMemoryManager->deallocate((void*)fData);
0182         else
0183             delete [] fData;
0184     }
0185 
0186     fData = p;
0187     fMemoryManager = manager;
0188 }
0189 
0190 //
0191 // JanitorMemFunCall
0192 //
0193 
0194 template <class T>
0195 JanitorMemFunCall<T>::JanitorMemFunCall(
0196             T*      object,
0197             MFPT    toCall) :
0198     fObject(object),
0199     fToCall(toCall)
0200 {
0201 }
0202 
0203 template <class T>
0204 JanitorMemFunCall<T>::~JanitorMemFunCall()
0205 {
0206   reset ();
0207 }
0208 
0209 template <class T>
0210 T& JanitorMemFunCall<T>::operator*() const
0211 {
0212   return *fObject;
0213 }
0214 
0215 
0216 template <class T>
0217 T* JanitorMemFunCall<T>::operator->() const
0218 {
0219   return fObject;
0220 }
0221 
0222 
0223 template <class T>
0224 T* JanitorMemFunCall<T>::get() const
0225 {
0226   return fObject;
0227 }
0228 
0229 
0230 template <class T>
0231 T* JanitorMemFunCall<T>::release()
0232 {
0233   T* p = fObject;
0234   fObject = 0;
0235   return p;
0236 }
0237 
0238 template <class T>
0239 void JanitorMemFunCall<T>::reset(T* p)
0240 {
0241   if (fObject != 0 && fToCall != 0)
0242     (fObject->*fToCall)();
0243 
0244   fObject = p;
0245 }
0246 
0247 
0248 XERCES_CPP_NAMESPACE_END