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 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #if !defined(JANITOR_HPP) |
---|
24 | #define JANITOR_HPP |
---|
25 | |
---|
26 | #include <xercesc/util/XMemory.hpp> |
---|
27 | #include <xercesc/framework/MemoryManager.hpp> |
---|
28 | |
---|
29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
30 | |
---|
31 | template <class T> class Janitor : public XMemory |
---|
32 | { |
---|
33 | public : |
---|
34 | // ----------------------------------------------------------------------- |
---|
35 | // Constructors and Destructor |
---|
36 | // ----------------------------------------------------------------------- |
---|
37 | Janitor(T* const toDelete); |
---|
38 | ~Janitor(); |
---|
39 | |
---|
40 | // ----------------------------------------------------------------------- |
---|
41 | // Public, non-virtual methods |
---|
42 | // ----------------------------------------------------------------------- |
---|
43 | void orphan(); |
---|
44 | |
---|
45 | // small amount of auto_ptr compatibility |
---|
46 | T& operator*() const; |
---|
47 | T* operator->() const; |
---|
48 | T* get() const; |
---|
49 | T* release(); |
---|
50 | void reset(T* p = 0); |
---|
51 | bool isDataNull(); |
---|
52 | |
---|
53 | private : |
---|
54 | // ----------------------------------------------------------------------- |
---|
55 | // Unimplemented constructors and operators |
---|
56 | // ----------------------------------------------------------------------- |
---|
57 | Janitor(); |
---|
58 | Janitor(const Janitor<T>&); |
---|
59 | Janitor<T>& operator=(const Janitor<T>&); |
---|
60 | |
---|
61 | // ----------------------------------------------------------------------- |
---|
62 | // Private data members |
---|
63 | // |
---|
64 | // fData |
---|
65 | // This is the pointer to the object or structure that must be |
---|
66 | // destroyed when this object is destroyed. |
---|
67 | // ----------------------------------------------------------------------- |
---|
68 | T* fData; |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | template <class T> class ArrayJanitor : public XMemory |
---|
74 | { |
---|
75 | public : |
---|
76 | // ----------------------------------------------------------------------- |
---|
77 | // Constructors and Destructor |
---|
78 | // ----------------------------------------------------------------------- |
---|
79 | ArrayJanitor(T* const toDelete); |
---|
80 | ArrayJanitor(T* const toDelete, MemoryManager* const manager); |
---|
81 | ~ArrayJanitor(); |
---|
82 | |
---|
83 | |
---|
84 | // ----------------------------------------------------------------------- |
---|
85 | // Public, non-virtual methods |
---|
86 | // ----------------------------------------------------------------------- |
---|
87 | void orphan(); |
---|
88 | |
---|
89 | // small amount of auto_ptr compatibility |
---|
90 | T& operator[](int index) const; |
---|
91 | T* get() const; |
---|
92 | T* release(); |
---|
93 | void reset(T* p = 0); |
---|
94 | void reset(T* p, MemoryManager* const manager); |
---|
95 | |
---|
96 | private : |
---|
97 | // ----------------------------------------------------------------------- |
---|
98 | // Unimplemented constructors and operators |
---|
99 | // ----------------------------------------------------------------------- |
---|
100 | ArrayJanitor(); |
---|
101 | ArrayJanitor(const ArrayJanitor<T>& copy); |
---|
102 | ArrayJanitor<T>& operator=(const ArrayJanitor<T>& copy); |
---|
103 | |
---|
104 | // ----------------------------------------------------------------------- |
---|
105 | // Private data members |
---|
106 | // |
---|
107 | // fData |
---|
108 | // This is the pointer to the object or structure that must be |
---|
109 | // destroyed when this object is destroyed. |
---|
110 | // ----------------------------------------------------------------------- |
---|
111 | T* fData; |
---|
112 | MemoryManager* fMemoryManager; |
---|
113 | }; |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | template <class T> class JanitorMemFunCall |
---|
118 | { |
---|
119 | public : |
---|
120 | |
---|
121 | typedef void (T::*MFPT) (); |
---|
122 | |
---|
123 | // ----------------------------------------------------------------------- |
---|
124 | // Constructors and Destructor |
---|
125 | // ----------------------------------------------------------------------- |
---|
126 | JanitorMemFunCall( |
---|
127 | T* object, |
---|
128 | MFPT toCall); |
---|
129 | |
---|
130 | ~JanitorMemFunCall(); |
---|
131 | |
---|
132 | // ----------------------------------------------------------------------- |
---|
133 | // Public, non-virtual methods |
---|
134 | // ----------------------------------------------------------------------- |
---|
135 | void release(); |
---|
136 | |
---|
137 | private : |
---|
138 | // ----------------------------------------------------------------------- |
---|
139 | // Unimplemented constructors and operators |
---|
140 | // ----------------------------------------------------------------------- |
---|
141 | JanitorMemFunCall(); |
---|
142 | JanitorMemFunCall(const JanitorMemFunCall<T>&); |
---|
143 | JanitorMemFunCall<T>& operator=(const JanitorMemFunCall<T>&); |
---|
144 | |
---|
145 | // ----------------------------------------------------------------------- |
---|
146 | // Private data members |
---|
147 | // |
---|
148 | // fObject |
---|
149 | // This is the pointer to the object for which we will call the |
---|
150 | // member function when this object is destroyed. |
---|
151 | // ----------------------------------------------------------------------- |
---|
152 | T* fObject; |
---|
153 | MFPT fToCall; |
---|
154 | }; |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | XERCES_CPP_NAMESPACE_END |
---|
160 | |
---|
161 | #if !defined(XERCES_TMPLSINC) |
---|
162 | #include <xercesc/util/Janitor.c> |
---|
163 | #endif |
---|
164 | |
---|
165 | #endif |
---|