Xalan-C++ API Reference  1.12.0
XalanDOMStringAllocator.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(XALANDOMSTRINGALLOCATOR_INCLUDE_GUARD_12455133)
20 #define XALANDOMSTRINGALLOCATOR_INCLUDE_GUARD_12455133
21 
22 
23 
24 // Base include file. Must be first.
26 
27 
28 
30 
31 
32 
34 
35 
36 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
42 {
43 public:
44 
47 
48 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
49  typedef ArenaBlock<data_type> ArenaBlockType;
50 
51  typedef ArenaAllocator<data_type,
52  ArenaBlockType> ArenaAllocatorType;
53 #else
55 #endif
56 
58 
59  enum { eDefaultBlockSize = 32 };
60 
61 
62  /**
63  * Construct an instance that will allocate in blocks of the specified size.
64  *
65  * @param theBlockSize The block size.
66  */
67  XalanDOMStringAllocator(MemoryManager& theManager, size_type theBlockCount);
68 
70 
71  /**
72  * Create a XalanDOMString object.
73  *
74  * @return pointer to the new instance
75  */
76  data_type*
77  create();
78 
79  /**
80  * Create a XalanDOMString object.
81  *
82  * @param theString A pointer to a character string
83  * @param theCount The number of characters in the string, or npos if the string is null-terminated.
84  *
85  * @return pointer to the new instance
86  */
87  data_type*
88  create(
89  const char* theString,
90 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
91  // $$$ ToDo: Some strange bug in MSVC++ complains when using data_type::npos here.
92  data_type_size_type theCount = data_type_size_type(-1));
93 #else
94  data_type_size_type theCount = data_type_size_type(data_type::npos));
95 #endif
96 
97  /**
98  * Copy constructor
99  *
100  * @param theSource The source string for the copy
101  * @param theStartPosition The position to start in the source string.
102  * @param theCount The number of characters to copy from the source string.
103  *
104  * @return pointer to the new instance
105  */
106  data_type*
107  create(
108  const data_type& theSource,
109  data_type_size_type theStartPosition = 0,
110  data_type_size_type theCount = data_type_size_type(data_type::npos));
111 
112  /**
113  * Create a XalanDOMString object.
114  *
115  * @param theString A pointer to a wide character string
116  * @param theCount The number of characters in the string, or npos if the string is null-terminated.
117  *
118  * @return pointer to the new instance
119  */
120  data_type*
121  create(
122  const XalanDOMChar* theString,
123  data_type_size_type theCount = data_type_size_type(data_type::npos));
124 
125  /**
126  * Create a XalanDOMString object.
127  *
128  * @param theCount the size of the string
129  * @param theChar the character used to initialize the string
130  *
131  * @return pointer to the new instance
132  */
133  data_type*
134  create(
135  data_type_size_type theCount,
136  XalanDOMChar theChar);
137 
138  /**
139  * Determine if an object is owned by the allocator...
140  */
141  bool
142  ownsObject(const data_type* theObject)
143  {
144  return m_allocator.ownsObject(theObject);
145  }
146 
147  /**
148  * Delete all instance objects from allocator.
149  */
150  void
152  {
153  m_allocator.reset();
154  }
155 
156  /**
157  * Get the number of ArenaBlocks currently allocated.
158  *
159  * @return The number of blocks.
160  */
161  size_type
163  {
164  return m_allocator.getBlockCount();
165  }
166 
167  /**
168  * Get size of an ArenaBlock, that is, the number
169  * of objects in each block.
170  *
171  * @return The size of the block
172  */
173  size_type
174  getBlockSize() const
175  {
176  return m_allocator.getBlockSize();
177  }
178 
179  /**
180  * Get a reference to the MemoryManager instance
181  * for this instance.
182  *
183  * @return A reference to the MemoryManager instance.
184  */
185  MemoryManager&
187  {
188  return m_allocator.getMemoryManager();
189  }
190 
191  /**
192  * Get a reference to the MemoryManager instance
193  * for this instance.
194  *
195  * @return A reference to the MemoryManager instance.
196  */
197  const MemoryManager&
199  {
200  return m_allocator.getMemoryManager();
201  }
202 
203 private:
204 
205  // Not implemented...
207 
209  operator=(const XalanDOMStringAllocator&);
210 
211  // Data members...
212  ArenaAllocatorType m_allocator;
213 };
214 
215 
216 
217 }
218 
219 
220 
221 #endif // XALANDOMSTRINGALLOCATOR_INCLUDE_GUARD_12455133
xalanc::XalanDOMStringAllocator::data_type
XalanDOMString data_type
Definition: XalanDOMStringAllocator.hpp:45
xalanc::ArenaAllocator< data_type >::size_type
ArenaBlock< data_type > ::size_type size_type
Definition: ArenaAllocator.hpp:55
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanDOMStringAllocator::ownsObject
bool ownsObject(const data_type *theObject)
Determine if an object is owned by the allocator...
Definition: XalanDOMStringAllocator.hpp:142
XalanDOMString.hpp
xalanc::XalanDOMStringAllocator
Definition: XalanDOMStringAllocator.hpp:41
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanDOMStringAllocator::ArenaAllocatorType
ArenaAllocator< data_type > ArenaAllocatorType
Definition: XalanDOMStringAllocator.hpp:54
xalanc::XalanDOMStringAllocator::getMemoryManager
MemoryManager & getMemoryManager()
Get a reference to the MemoryManager instance for this instance.
Definition: XalanDOMStringAllocator.hpp:186
xalanc::XalanDOMStringAllocator::size_type
ArenaAllocatorType::size_type size_type
Definition: XalanDOMStringAllocator.hpp:57
xalanc::ArenaBlock< data_type >
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::XalanDOMStringAllocator::reset
void reset()
Delete all instance objects from allocator.
Definition: XalanDOMStringAllocator.hpp:151
xalanc::ArenaAllocator
Definition: ArenaAllocator.hpp:47
ArenaAllocator.hpp
xalanc::XalanDOMStringAllocator::data_type_size_type
data_type::size_type data_type_size_type
Definition: XalanDOMStringAllocator.hpp:46
xalanc::XalanDOMStringAllocator::getMemoryManager
const MemoryManager & getMemoryManager() const
Get a reference to the MemoryManager instance for this instance.
Definition: XalanDOMStringAllocator.hpp:198
xalanc::XalanDOMString::size_type
XalanSize_t size_type
Definition: XalanDOMString.hpp:57
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanDOMStringAllocator::getBlockSize
size_type getBlockSize() const
Get size of an ArenaBlock, that is, the number of objects in each block.
Definition: XalanDOMStringAllocator.hpp:174
xalanc::XalanDOMStringAllocator::getBlockCount
size_type getBlockCount() const
Get the number of ArenaBlocks currently allocated.
Definition: XalanDOMStringAllocator.hpp:162