Xalan-C++ API Reference  1.12.0
XalanAllocator.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(XALANALLOCATOR_INCLUDE_GUARD_1357924680)
20 #define XALANALLOCATOR_INCLUDE_GUARD_1357924680
21 
22 
23 
24 #include <cstddef>
25 
26 
27 
28 namespace XALAN_CPP_NAMESPACE {
29 
30 
31 
32 template <class Type>
34 {
35 public:
36  typedef size_t size_type;
37  typedef ptrdiff_t difference_type;
38  typedef Type* pointer;
39  typedef const Type* const_pointer;
40  typedef Type& reference;
41  typedef const Type& const_reference;
42  typedef Type value_type;
43 
44 
45  XalanAllocator(MemoryManager& theManager) :
46  m_memoryManager(theManager)
47  {
48  }
49 
50 
52  {
53  }
54 
55  MemoryManager&
57  {
58  return m_memoryManager;
59  }
60 
61  pointer
62  address(reference x) const
63  {
64  return &x;
65  }
66 
67  const_pointer
68  address(const_reference x) const
69  {
70  return &x;
71  }
72 
73  pointer
75  size_type size,
76  const void* /* hint */ = 0)
77  {
78  return (pointer)m_memoryManager.allocate(size * sizeof(Type));
79  }
80 
81  void
83  pointer p,
84  size_type /* n */)
85  {
86  if( p == 0 )
87  {
88  return;
89  }
90 
91  m_memoryManager.deallocate(p);
92  }
93 
94  size_type
95  max_size() const
96  {
97  return ~0;
98  }
99 
100  void
102  pointer p,
103  const Type& val)
104  {
105  new (p) Type(val);
106  }
107 
108  void
110  {
111  p->Type::~Type();
112  }
113 
114 private:
116 
118  operator=(const XalanAllocator<Type>&);
119 
120  MemoryManager& m_memoryManager;
121 };
122 
123 
124 
125 }
126 
127 
128 
129 #endif // XALANALLOCATOR_INCLUDE_GUARD_1357924680
xalanc::XalanAllocator::construct
void construct(pointer p, const Type &val)
Definition: XalanAllocator.hpp:101
xalanc::XalanAllocator::const_pointer
const typedef Type * const_pointer
Definition: XalanAllocator.hpp:39
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanAllocator::pointer
Type * pointer
Definition: XalanAllocator.hpp:38
xalanc::XalanAllocator::size_type
size_t size_type
Definition: XalanAllocator.hpp:36
xalanc::XalanAllocator::~XalanAllocator
~XalanAllocator()
Definition: XalanAllocator.hpp:51
xalanc::XalanAllocator::deallocate
void deallocate(pointer p, size_type)
Definition: XalanAllocator.hpp:82
xalanc::XalanAllocator
Definition: XalanAllocator.hpp:33
xalanc::XalanAllocator::const_reference
const typedef Type & const_reference
Definition: XalanAllocator.hpp:41
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanAllocator::reference
Type & reference
Definition: XalanAllocator.hpp:40
xalanc::XalanAllocator::XalanAllocator
XalanAllocator(MemoryManager &theManager)
Definition: XalanAllocator.hpp:45
xalanc::XalanAllocator::address
pointer address(reference x) const
Definition: XalanAllocator.hpp:62
xalanc::XalanAllocator::address
const_pointer address(const_reference x) const
Definition: XalanAllocator.hpp:68
xalanc::XalanAllocator::destroy
void destroy(pointer p)
Definition: XalanAllocator.hpp:109
xalanc::XalanAllocator::allocate
pointer allocate(size_type size, const void *=0)
Definition: XalanAllocator.hpp:74
xalanc::XalanAllocator::getMemoryManager
MemoryManager & getMemoryManager()
Definition: XalanAllocator.hpp:56
xalanc::XalanAllocator::difference_type
ptrdiff_t difference_type
Definition: XalanAllocator.hpp:37
xalanc::XalanAllocator::max_size
size_type max_size() const
Definition: XalanAllocator.hpp:95
xalanc::XalanAllocator::value_type
Type value_type
Definition: XalanAllocator.hpp:42