source: icXML/icXML-devel/src/xercesc/util/Janitor.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 5.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: Janitor.hpp 669844 2008-06-20 10:11:44Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_JANITOR_HPP)
23#define XERCESC_INCLUDE_GUARD_JANITOR_HPP
24
25#include <xercesc/util/XMemory.hpp>
26#include <xercesc/framework/MemoryManager.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30template <class T> class Janitor : public XMemory
31{
32public  :
33    // -----------------------------------------------------------------------
34    //  Constructors and Destructor
35    // -----------------------------------------------------------------------
36    Janitor(T* const toDelete);
37    ~Janitor();
38
39    // -----------------------------------------------------------------------
40    //  Public, non-virtual methods
41    // -----------------------------------------------------------------------
42    void orphan();
43
44    //  small amount of auto_ptr compatibility
45    T& operator*() const;
46    T* operator->() const;
47    T* get() const;
48    T* release();
49    void reset(T* p = 0);
50    bool isDataNull();
51
52private :
53    // -----------------------------------------------------------------------
54    //  Unimplemented constructors and operators
55    // -----------------------------------------------------------------------
56    Janitor();
57    Janitor(const Janitor<T>&);
58    Janitor<T>& operator=(const Janitor<T>&);
59
60    // -----------------------------------------------------------------------
61    //  Private data members
62    //
63    //  fData
64    //      This is the pointer to the object or structure that must be
65    //      destroyed when this object is destroyed.
66    // -----------------------------------------------------------------------
67    T*  fData;
68};
69
70
71
72template <class T> class ArrayJanitor : public XMemory
73{
74public  :
75    // -----------------------------------------------------------------------
76    //  Constructors and Destructor
77    // -----------------------------------------------------------------------
78    ArrayJanitor(T* const toDelete);
79    ArrayJanitor(T* const toDelete, MemoryManager* const manager);
80    ~ArrayJanitor();
81
82
83    // -----------------------------------------------------------------------
84    //  Public, non-virtual methods
85    // -----------------------------------------------------------------------
86    void orphan();
87
88        //      small amount of auto_ptr compatibility
89        T&      operator[](int index) const;
90        T*      get() const;
91        T*      release();
92        void reset(T* p = 0);
93        void reset(T* p, MemoryManager* const manager);
94
95private :
96    // -----------------------------------------------------------------------
97    //  Unimplemented constructors and operators
98    // -----------------------------------------------------------------------
99        ArrayJanitor();
100    ArrayJanitor(const ArrayJanitor<T>& copy);
101    ArrayJanitor<T>& operator=(const ArrayJanitor<T>& copy);
102
103    // -----------------------------------------------------------------------
104    //  Private data members
105    //
106    //  fData
107    //      This is the pointer to the object or structure that must be
108    //      destroyed when this object is destroyed.
109    // -----------------------------------------------------------------------
110    T*  fData;
111    MemoryManager* fMemoryManager;
112};
113
114
115
116template <class T> class JanitorMemFunCall
117{
118public  :
119
120    typedef void (T::*MFPT) ();
121
122    // -----------------------------------------------------------------------
123    //  Constructors and Destructor
124    // -----------------------------------------------------------------------
125    JanitorMemFunCall(
126        T*      object,
127        MFPT    toCall);
128
129    ~JanitorMemFunCall();
130
131    //  small amount of auto_ptr compatibility
132    T& operator*() const;
133    T* operator->() const;
134    T* get() const;
135    T* release();
136    void reset(T* p = 0);
137
138private :
139    // -----------------------------------------------------------------------
140    //  Unimplemented constructors and operators
141    // -----------------------------------------------------------------------
142    JanitorMemFunCall();
143    JanitorMemFunCall(const JanitorMemFunCall<T>&);
144    JanitorMemFunCall<T>& operator=(const JanitorMemFunCall<T>&);
145
146    // -----------------------------------------------------------------------
147    //  Private data members
148    //
149    //  fObject
150    //      This is the pointer to the object for which we will call the
151    //      member function when this object is destroyed.
152    // -----------------------------------------------------------------------
153    T*      fObject;
154    MFPT    fToCall;
155};
156
157
158
159
160XERCES_CPP_NAMESPACE_END
161
162#if !defined(XERCES_TMPLSINC)
163#include <xercesc/util/Janitor.c>
164#endif
165
166#endif
Note: See TracBrowser for help on using the repository browser.