source: NonGTP/Xerces/xercesc/util/Janitor.c @ 188

Revision 188, 7.3 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/**
58 * $Log: Janitor.c,v $
59 * Revision 1.5  2003/11/06 19:28:11  knoaman
60 * PSVI support for annotations.
61 *
62 * Revision 1.4  2003/05/21 03:34:52  jberry
63 * Cast away CodeWarrior complaint of casting away const if we're holding a const obj
64 *
65 * Revision 1.3  2003/05/15 19:04:35  knoaman
66 * Partial implementation of the configurable memory manager.
67 *
68 * Revision 1.2  2002/11/04 15:22:04  tng
69 * C++ Namespace Support.
70 *
71 * Revision 1.1.1.1  2002/02/01 22:22:10  peiyongz
72 * sane_include
73 *
74 * Revision 1.6  2000/10/13 22:45:11  andyh
75 * Complete removal of ArrayJanitory::operator->().  Was just commented out earlier.
76 *
77 * Revision 1.5  2000/10/10 23:52:10  andyh
78 * From Janitor, remove the addition that is having compile problems in MSVC.
79 *
80 * Revision 1.4  2000/10/09 18:32:31  jberry
81 * Add some auto_ptr functionality to allow modification of monitored
82 * pointer value. This eases use of Janitor in some situations.
83 *
84 * Revision 1.3  2000/03/02 19:54:40  roddey
85 * This checkin includes many changes done while waiting for the
86 * 1.1.0 code to be finished. I can't list them all here, but a list is
87 * available elsewhere.
88 *
89 * Revision 1.2  2000/02/06 07:48:02  rahulj
90 * Year 2K copyright swat.
91 *
92 * Revision 1.1.1.1  1999/11/09 01:04:26  twl
93 * Initial checkin
94 *
95 * Revision 1.2  1999/11/08 20:45:08  rahul
96 * Swat for adding in Product name and CVS comment log variable.
97 *
98 */
99
100
101// ---------------------------------------------------------------------------
102//  Includes
103// ---------------------------------------------------------------------------
104#if defined(XERCES_TMPLSINC)
105#include <xercesc/util/Janitor.hpp>
106#endif
107
108XERCES_CPP_NAMESPACE_BEGIN
109
110// ---------------------------------------------------------------------------
111//  Janitor: Constructors and Destructor
112// ---------------------------------------------------------------------------
113template <class T> Janitor<T>::Janitor(T* const toDelete) :
114    fData(toDelete)
115{
116}
117
118
119template <class T> Janitor<T>::~Janitor()
120{
121    reset();
122}
123
124
125// ---------------------------------------------------------------------------
126//  Janitor: Public, non-virtual methods
127// ---------------------------------------------------------------------------
128template <class T> void
129Janitor<T>::orphan()
130{
131   release();
132}
133
134
135template <class T> T&
136Janitor<T>::operator*() const
137{
138        return *fData;
139}
140
141
142template <class T> T*
143Janitor<T>::operator->() const
144{
145        return fData;
146}
147
148
149template <class T> T*
150Janitor<T>::get() const
151{
152        return fData;
153}
154
155
156template <class T> T*
157Janitor<T>::release()
158{
159        T* p = fData;
160        fData = 0;
161        return p;
162}
163
164
165template <class T> void Janitor<T>::reset(T* p)
166{
167    if (fData)
168        delete fData;
169
170    fData = p;
171}
172
173template <class T> bool Janitor<T>::isDataNull()
174{
175    return (fData == 0);
176}
177
178
179// -----------------------------------------------------------------------
180//  ArrayJanitor: Constructors and Destructor
181// -----------------------------------------------------------------------
182template <class T> ArrayJanitor<T>::ArrayJanitor(T* const toDelete) :
183    fData(toDelete)
184    , fMemoryManager(0)
185{
186}
187
188template <class T>
189ArrayJanitor<T>::ArrayJanitor(T* const toDelete,
190                              MemoryManager* const manager) :
191    fData(toDelete)
192    , fMemoryManager(manager)
193{
194}
195
196
197template <class T> ArrayJanitor<T>::~ArrayJanitor()
198{
199        reset();
200}
201
202
203// -----------------------------------------------------------------------
204//  ArrayJanitor: Public, non-virtual methods
205// -----------------------------------------------------------------------
206template <class T> void
207ArrayJanitor<T>::orphan()
208{
209   release();
210}
211
212
213//      Look, Ma! No hands! Don't call this with null data!
214template <class T> T&
215ArrayJanitor<T>::operator[](int index) const
216{
217        //      TODO: Add appropriate exception
218        return fData[index];
219}
220
221
222template <class T> T*
223ArrayJanitor<T>::get() const
224{
225        return fData;
226}
227
228
229template <class T> T*
230ArrayJanitor<T>::release()
231{
232        T* p = fData;
233        fData = 0;
234        return p;
235}
236
237
238template <class T> void
239ArrayJanitor<T>::reset(T* p)
240{
241        if (fData) {
242
243                if (fMemoryManager)
244            fMemoryManager->deallocate((void*)fData);
245        else
246            delete [] fData;
247    }
248
249        fData = p;
250    fMemoryManager = 0;
251}
252
253template <class T> void
254ArrayJanitor<T>::reset(T* p, MemoryManager* manager)
255{
256        if (fData) {
257
258                if (fMemoryManager)
259            fMemoryManager->deallocate((void*)fData);
260        else
261            delete [] fData;
262    }
263
264        fData = p;
265    fMemoryManager = manager;
266}
267
268XERCES_CPP_NAMESPACE_END
269
Note: See TracBrowser for help on using the repository browser.