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(XALANSOURCETREEELEMENTAALLOCATOR_INCLUDE_GUARD_12455133)
20 #define XALANSOURCETREEELEMENTAALLOCATOR_INCLUDE_GUARD_12455133
21 
22 
23 
24 #include <xalanc/XalanSourceTree/XalanSourceTreeDefinitions.hpp>
25 
26 
27 
28 #include <xalanc/PlatformSupport/ArenaAllocator.hpp>
29 
30 
31 
32 #include <xalanc/XalanSourceTree/XalanSourceTreeElementA.hpp>
33 
34 
35 
36 namespace XALAN_CPP_NAMESPACE {
37 
38 
39 
40 class XALAN_XALANSOURCETREE_EXPORT XalanSourceTreeElementAAllocator
41 {
42 public:
43 
44     typedef XalanSourceTreeElementA                 ObjectType;
45 
46     typedef ObjectType::IndexType                   IndexType;
47 
48 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
49     typedef ArenaBlock<ObjectType>                  ArenaBlockType;
50 
51     typedef ArenaAllocator<ObjectType,
52                            ArenaBlockType>          ArenaAllocatorType;
53 #else
54     typedef ArenaAllocator<ObjectType>              ArenaAllocatorType;
55 #endif
56 
57     typedef ArenaAllocatorType::size_type           size_type;
58 
59     /**
60      * Construct an instance that will allocate blocks of the specified size.
61      *
62      * @param theBlockSize The block size.
63      */
64     XalanSourceTreeElementAAllocator(
65                 MemoryManager&  theManager,
66                 size_type       theBlockCount);
67 
68     ~XalanSourceTreeElementAAllocator();
69 
70     /**
71      * Create an instance.
72      *
73      * @param theTagName The tag name of the element
74      * @param theOwnerDocument The document that owns the instance
75      * @param theAttributes An array of pointers to the attribute instances for the element
76      * @param theAttributeCount The number of attributes.
77      * @param theParentNode The parent node, if any.
78      * @param thePreviousSibling The previous sibling, if any.
79      * @param theNextSibling The next sibling, if any.
80      * @param theIndex The document-order index of the node.
81      *
82      * @return pointer to the instance
83      */
84     ObjectType*
85     create(
86             const XalanDOMString&       theTagName,
87             XalanSourceTreeDocument*    theOwnerDocument,
88             XalanSourceTreeAttr**       theAttributes,
89             XalanSize_t                 theAttributeCount,
90             XalanNode*                  theParentNode = 0,
91             XalanNode*                  thePreviousSibling = 0,
92             XalanNode*                  theNextSibling = 0,
93             IndexType                   theIndex = 0);
94 
95     /**
96      * Delete all objects from allocator.
97      */
98     void
99     reset();
100 
101     /**
102      * Get size of an ArenaBlock, that is, the number
103      * of objects in each block.
104      *
105      * @return The size of the block
106      */
107     size_type
getBlockCount() const108     getBlockCount() const
109     {
110         return m_allocator.getBlockCount();
111     }
112 
113     /**
114      * Get the number of ArenaBlocks currently allocated.
115      *
116      * @return The number of blocks.
117      */
118     size_type
getBlockSize() const119     getBlockSize() const
120     {
121         return m_allocator.getBlockSize();
122     }
123 
124 private:
125 
126     // Not implemented...
127     XalanSourceTreeElementAAllocator(const XalanSourceTreeElementAAllocator&);
128 
129     XalanSourceTreeElementAAllocator&
130     operator=(const XalanSourceTreeElementAAllocator&);
131 
132     // Data members...
133     ArenaAllocatorType  m_allocator;
134 };
135 
136 
137 
138 }
139 
140 
141 
142 #endif  // XALANSOURCETREEELEMENTAALLOCATOR_INCLUDE_GUARD_12455133
143