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: XMemory.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #if !defined(XMEMORY_HPP) |
---|
24 | #define XMEMORY_HPP |
---|
25 | |
---|
26 | #include <xercesc/util/XercesDefs.hpp> |
---|
27 | #include <stdlib.h> |
---|
28 | |
---|
29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
30 | |
---|
31 | class MemoryManager; |
---|
32 | |
---|
33 | /** |
---|
34 | * This class makes it possible to override the C++ memory management by |
---|
35 | * adding new/delete operators to this base class. |
---|
36 | * |
---|
37 | * This class is used in conjuction with the pluggable memory manager. It |
---|
38 | * allows applications to control Xerces memory management. |
---|
39 | */ |
---|
40 | |
---|
41 | class XMLUTIL_EXPORT XMemory |
---|
42 | { |
---|
43 | public : |
---|
44 | // ----------------------------------------------------------------------- |
---|
45 | // The C++ memory management |
---|
46 | // ----------------------------------------------------------------------- |
---|
47 | /** @name The C++ memory management */ |
---|
48 | //@{ |
---|
49 | |
---|
50 | /** |
---|
51 | * This method overrides operator new |
---|
52 | * |
---|
53 | * @param size The requested memory size |
---|
54 | */ |
---|
55 | void* operator new(size_t size); |
---|
56 | |
---|
57 | #if defined(XML_VISUALCPP) |
---|
58 | /** |
---|
59 | * This method overrides the MFC debug version of the operator new |
---|
60 | * |
---|
61 | * @param size The requested memory size |
---|
62 | * @param file The file where the allocation was requested |
---|
63 | * @param line The line where the allocation was requested |
---|
64 | */ |
---|
65 | void* operator new(size_t size, const char* file, int line); |
---|
66 | /** |
---|
67 | * This method provides a matching delete for the MFC debug new |
---|
68 | * |
---|
69 | * @param p The pointer to the allocated memory |
---|
70 | * @param file The file where the allocation was requested |
---|
71 | * @param line The line where the allocation was requested |
---|
72 | */ |
---|
73 | void operator delete(void* p, const char* file, int line); |
---|
74 | #endif |
---|
75 | |
---|
76 | /** |
---|
77 | * This method defines a custom operator new, that will use the provided |
---|
78 | * memory manager to perform the allocation |
---|
79 | * |
---|
80 | * @param size The requested memory size |
---|
81 | * @param memMgr An application's memory manager |
---|
82 | */ |
---|
83 | void* operator new(size_t size, MemoryManager* memMgr); |
---|
84 | |
---|
85 | /** |
---|
86 | * This method overrides placement operator new |
---|
87 | * |
---|
88 | * @param size The requested memory size |
---|
89 | * @param ptr The memory location where the object should be allocated |
---|
90 | */ |
---|
91 | void* operator new(size_t size, void* ptr); |
---|
92 | |
---|
93 | /** |
---|
94 | * This method overrides operator delete |
---|
95 | * |
---|
96 | * @param p The pointer to the allocated memory |
---|
97 | */ |
---|
98 | void operator delete(void* p); |
---|
99 | |
---|
100 | //The Borland compiler is complaining about duplicate overloading of delete |
---|
101 | #if !defined(XML_BORLAND) |
---|
102 | /** |
---|
103 | * This method provides a matching delete for the custom operator new |
---|
104 | * |
---|
105 | * @param p The pointer to the allocated memory |
---|
106 | * @param memMgr An application's memory manager |
---|
107 | */ |
---|
108 | void operator delete(void* p, MemoryManager* memMgr); |
---|
109 | |
---|
110 | /** |
---|
111 | * This method provides a matching delete for the placement new |
---|
112 | * |
---|
113 | * @param p The pointer to the allocated memory |
---|
114 | * @param ptr The memory location where the object had to be allocated |
---|
115 | */ |
---|
116 | void operator delete(void* p, void* ptr); |
---|
117 | #endif |
---|
118 | |
---|
119 | //@} |
---|
120 | |
---|
121 | protected : |
---|
122 | // ----------------------------------------------------------------------- |
---|
123 | // Hidden Constructors |
---|
124 | // ----------------------------------------------------------------------- |
---|
125 | /** @name Constructor */ |
---|
126 | //@{ |
---|
127 | |
---|
128 | /** |
---|
129 | * Protected default constructor |
---|
130 | */ |
---|
131 | XMemory() |
---|
132 | { |
---|
133 | } |
---|
134 | //@} |
---|
135 | |
---|
136 | #if defined(XML_BORLAND) |
---|
137 | virtual ~XMemory() |
---|
138 | { |
---|
139 | } |
---|
140 | #endif |
---|
141 | |
---|
142 | }; |
---|
143 | |
---|
144 | XERCES_CPP_NAMESPACE_END |
---|
145 | |
---|
146 | #endif |
---|