Xalan-C++ API Reference  1.12.0
XalanDOMStringPool.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 #if !defined(XALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)
19 #define XALANDOMSTRINGPOOL_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
32 
33 
34 
35 namespace XALAN_CPP_NAMESPACE {
36 
37 
38 
40 {
41 public:
42 
43  enum { eDefaultBlockSize = 32,
44  eDefaultBucketCount = XalanDOMStringHashTable::eDefaultBucketCount,
45  eDefaultBucketSize = XalanDOMStringHashTable::eDefaultBucketSize };
46 
48 
50  typedef size_t bucket_count_type;
52 
53  /**
54  * Create a string pool.
55  *
56  * @param theBlockSize The block size for the allocator.
57  * @param theBucketCount The number of buckets to use for the hash table. This should be a prime number for best results.
58  * @param theBucketSize The initial size of each bucket in the hash table.
59  */
60  explicit
62  MemoryManager& theManager,
63  block_size_type theBlockSize = eDefaultBlockSize,
64  bucket_count_type theBucketCount = eDefaultBucketCount,
65  bucket_size_type theBucketSize = eDefaultBucketSize);
66 
67  static XalanDOMStringPool*
68  create(
69  MemoryManager& theManager,
70  block_size_type theBlockSize = eDefaultBlockSize,
71  bucket_count_type theBucketCount = eDefaultBucketCount,
72  bucket_size_type theBucketSize = eDefaultBucketSize);
73 
74 
75  virtual
77 
78  /**
79  * Clear the pool.
80  *
81  */
82  virtual void
83  clear();
84 
85  /**
86  * Get the number of strings in the pool
87  *
88  * @return the size of the pool.
89  */
90  virtual size_t
91  size() const;
92 
93  /**
94  * Get a pooled string. If the string is not pooled, it is added.
95  *
96  * @param theString The string to pool.
97  * @return a const reference to the pooled string.
98  */
99  virtual const XalanDOMString&
100  get(const XalanDOMString& theString);
101 
102  /**
103  * Get a pooled string. If the string is not pooled, it is added.
104  *
105  * @param theString The string to pool.
106  * @param theLength The length of the string. If XalanDOMString::npos, the string is assumed to be null-terminated.
107  * @return a const reference to the pooled string.
108  */
109  virtual const XalanDOMString&
110  get(
111  const XalanDOMChar* theString,
112  XalanDOMString::size_type theLength = XalanDOMString::npos);
113 
114  /**
115  * Get a reference to the pool's hash table. Useful for diagnostic
116  * purposes.
117  *
118  * @return a const reference to the hash table.
119  */
121  getHashTable() const
122  {
123  return m_hashTable;
124  }
125 
126  MemoryManager&
128  {
129  return m_hashTable.getMemoryManager();
130  }
131 
132  const MemoryManager&
134  {
135  return m_hashTable.getMemoryManager();
136  }
137 
138 private:
139 
140  // Not implemented, for now...
142 
144  operator=(const XalanDOMStringPool&);
145 
146  bool
147  operator==(const XalanDOMStringPool&) const;
148 
149  // Data members...
150  AllocatorType m_stringAllocator;
151 
152  size_t m_stringCount;
153 
154  XalanDOMStringHashTable m_hashTable;
155 
156  static const XalanDOMString s_emptyString;
157 };
158 
159 
160 
161 }
162 
163 
164 
165 #endif // !defined(XALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)
xalanc::XalanDOMStringPool::getMemoryManager
MemoryManager & getMemoryManager()
Definition: XalanDOMStringPool.hpp:127
xalanc::XalanDOMStringPool::AllocatorType
XalanDOMStringAllocator AllocatorType
Definition: XalanDOMStringPool.hpp:47
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::clear
void clear(XalanDOMString &theString)
Remove all elements from target string.
Definition: DOMStringHelper.hpp:2475
xalanc::XalanDOMStringAllocator
Definition: XalanDOMStringAllocator.hpp:41
XalanDOMStringHashTable.hpp
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::XalanDOMStringAllocator::size_type
ArenaAllocatorType::size_type size_type
Definition: XalanDOMStringAllocator.hpp:57
DOMStringHelper.hpp
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::XalanDOMStringPool::getMemoryManager
const MemoryManager & getMemoryManager() const
Definition: XalanDOMStringPool.hpp:133
xalanc::XalanDOMStringPool::getHashTable
const XalanDOMStringHashTable & getHashTable() const
Get a reference to the pool's hash table.
Definition: XalanDOMStringPool.hpp:121
ArenaAllocator.hpp
xalanc::XalanDOMStringPool::bucket_count_type
size_t bucket_count_type
Definition: XalanDOMStringPool.hpp:50
xalanc::XalanDOMStringHashTable
Definition: XalanDOMStringHashTable.hpp:40
xalanc::XalanDOMStringHashTable::bucket_size_type
BucketType::size_type bucket_size_type
Definition: XalanDOMStringHashTable.hpp:45
XalanDOMStringAllocator.hpp
xalanc::XalanDOMStringPool
Definition: XalanDOMStringPool.hpp:39
xalanc::XalanDOMString::size_type
XalanSize_t size_type
Definition: XalanDOMString.hpp:57
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanDOMStringPool::bucket_size_type
XalanDOMStringHashTable::bucket_size_type bucket_size_type
Definition: XalanDOMStringPool.hpp:51
xalanc::XalanDOMStringPool::block_size_type
AllocatorType::size_type block_size_type
Definition: XalanDOMStringPool.hpp:49