source: icXML/icXML-devel/src/xercesc/dom/impl/DOMDeepNodeListPool.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 7.4 KB
Line 
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: DOMDeepNodeListPool.hpp 883368 2009-11-23 15:28:19Z amassari $
20 */
21
22//
23//  This file is part of the internal implementation of the C++ XML DOM.
24//  It should NOT be included or used directly by application programs.
25//
26//  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
27//  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
28//  name is substituded for the *.
29//
30
31#if !defined(XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP)
32#define XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP
33
34
35#include <icxercesc/util/Hashers.hpp>
36#include <xercesc/util/IllegalArgumentException.hpp>
37#include <xercesc/util/NoSuchElementException.hpp>
38#include <xercesc/util/RuntimeException.hpp>
39#include <xercesc/util/XMLExceptMsgs.hpp>
40#include <xercesc/util/XMLEnumerator.hpp>
41
42XERCES_CPP_NAMESPACE_BEGIN
43
44//
45//  This should really be a nested class, but some of the compilers we
46//  have to support cannot deal with that!
47//
48template <class TVal>
49struct DOMDeepNodeListPoolTableBucketElem : public XMemory
50{
51    DOMDeepNodeListPoolTableBucketElem
52    (
53        void* key1
54        , XMLCh* key2
55        , XMLCh* key3
56        , TVal* const value
57        , DOMDeepNodeListPoolTableBucketElem<TVal>* next
58        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
59    ) :
60    fData(value)
61    , fNext(next)
62    , fKey1(key1)
63    , fKey2(0)
64    , fKey3(0)
65    {
66        if (key2)
67            fKey2 = XMLString::replicate(key2, manager);
68
69        if (key3)
70            fKey3 = XMLString::replicate(key3, manager);
71    }
72
73    TVal*                                     fData;
74    DOMDeepNodeListPoolTableBucketElem<TVal>* fNext;
75    void*                                     fKey1;
76    XMLCh*                                    fKey2;
77    XMLCh*                                    fKey3;
78
79    ~DOMDeepNodeListPoolTableBucketElem() {};
80};
81
82
83template <class TVal, class THasher = PtrHasher>
84class DOMDeepNodeListPool
85{
86public:
87    // -----------------------------------------------------------------------
88    //  Constructors and Destructor
89    // -----------------------------------------------------------------------
90    DOMDeepNodeListPool
91    (
92        const XMLSize_t modulus
93      , const XMLSize_t initSize = 128
94    );
95
96    DOMDeepNodeListPool
97    (
98        const XMLSize_t modulus
99      , const bool adoptElems
100      , const XMLSize_t initSize = 128
101    );
102
103    DOMDeepNodeListPool
104    (
105         const XMLSize_t modulus
106       , const bool adoptElems
107       , const THasher& hasher
108       , const XMLSize_t initSize = 128
109    );
110
111    ~DOMDeepNodeListPool();
112
113    // -----------------------------------------------------------------------
114    //  Element management
115    // -----------------------------------------------------------------------
116    bool isEmpty() const;
117    bool containsKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
118    void removeAll();
119    void cleanup();
120
121
122    // -----------------------------------------------------------------------
123    //  Getters
124    // -----------------------------------------------------------------------
125    TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3);
126    const TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
127
128    TVal* getById(const XMLSize_t elemId);
129    const TVal* getById(const XMLSize_t elemId) const;
130
131    // -----------------------------------------------------------------------
132    //  Putters
133    // -----------------------------------------------------------------------
134    XMLSize_t put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt);
135
136private:
137
138    // -----------------------------------------------------------------------
139    //  Private methods
140    // -----------------------------------------------------------------------
141    DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal);
142    const DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const;
143    void initialize(const XMLSize_t modulus);
144
145    // -----------------------------------------------------------------------
146    // Unimplemented constructors and operators
147    // -----------------------------------------------------------------------
148    DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal, THasher> &);
149    DOMDeepNodeListPool<TVal, THasher> & operator = (const DOMDeepNodeListPool<TVal, THasher> &);
150
151    // -----------------------------------------------------------------------
152    //  Data members
153    //
154    //  fAdoptedElems
155    //      Indicates whether the values added are adopted or just referenced.
156    //      If adopted, then they are deleted when they are removed from the
157    //      hash table.
158    //
159    //  fBucketList
160    //      This is the array that contains the heads of all of the list
161    //      buckets, one for each possible hash value.
162    //
163    //  fHashModulus
164    //      The modulus used for this hash table, to hash the keys. This is
165    //      also the number of elements in the bucket list.
166    //
167    //  fHash
168    //      The hasher for the key1 data type.
169    //
170    //  fIdPtrs
171    //  fIdPtrsCount
172    //      This is the array of pointers to the bucket elements in order of
173    //      their assigned ids. So taking id N and referencing this array
174    //      gives you the element with that id. The count field indicates
175    //      the current size of this list. When fIdCounter+1 reaches this
176    //      value the list must be expanded.
177    //
178    //  fIdCounter
179    //      This is used to give out unique ids to added elements. It starts
180    //      at zero (which means empty), and is bumped up for each newly added
181    //      element. So the first element is 1, the next is 2, etc... This
182    //      means that this value is set to the top index of the fIdPtrs array.
183    // -----------------------------------------------------------------------
184    bool                                       fAdoptedElems;
185    DOMDeepNodeListPoolTableBucketElem<TVal>** fBucketList;
186    XMLSize_t                                  fHashModulus;
187    TVal**                                     fIdPtrs;
188    XMLSize_t                                  fIdPtrsCount;
189    XMLSize_t                                  fIdCounter;
190    MemoryManager*                             fMemoryManager;
191    THasher                                    fHasher;
192};
193
194XERCES_CPP_NAMESPACE_END
195
196#if !defined(XERCES_TMPLSINC)
197#include <xercesc/dom/impl/DOMDeepNodeListPool.c>
198#endif
199
200#endif
Note: See TracBrowser for help on using the repository browser.