source: NonGTP/Xerces/xercesc/dom/impl/DOMDeepNodeListPool.hpp @ 188

Revision 188, 10.1 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: DOMDeepNodeListPool.hpp,v 1.7 2004/01/29 11:44:26 cargilld Exp $
59 */
60
61//
62//  This file is part of the internal implementation of the C++ XML DOM.
63//  It should NOT be included or used directly by application programs.
64//
65//  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
66//  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
67//  name is substituded for the *.
68//
69
70#if !defined(DOMDeepNODELISTPOOL_HPP)
71#define DOMDeepNODELISTPOOL_HPP
72
73
74#include <xercesc/util/HashBase.hpp>
75#include <xercesc/util/IllegalArgumentException.hpp>
76#include <xercesc/util/NoSuchElementException.hpp>
77#include <xercesc/util/RuntimeException.hpp>
78#include <xercesc/util/XMLExceptMsgs.hpp>
79#include <xercesc/util/XMLEnumerator.hpp>
80#include <xercesc/util/XMLString.hpp>
81#include <xercesc/util/HashXMLCh.hpp>
82#include <xercesc/util/HashPtr.hpp>
83
84XERCES_CPP_NAMESPACE_BEGIN
85
86
87// This hash table is modified from RefHash3KeysIdPool with first key as object ptr (DOMNode),
88// second and third keys are both XMLCh* string
89
90template <class TVal> struct DOMDeepNodeListPoolTableBucketElem;
91
92
93//
94//  This should really be a nested class, but some of the compilers we
95//  have to support cannot deal with that!
96//
97template <class TVal>
98struct DOMDeepNodeListPoolTableBucketElem : public XMemory
99{
100    DOMDeepNodeListPoolTableBucketElem
101    (
102        void* key1
103        , XMLCh* key2
104        , XMLCh* key3
105        , TVal* const value
106        , DOMDeepNodeListPoolTableBucketElem<TVal>* next
107        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
108    ) :
109    fData(value)
110    , fNext(next)
111    , fKey1(key1)
112    , fKey2(0)
113    , fKey3(0)
114    {
115        if (key2)
116            fKey2 = XMLString::replicate(key2, manager);
117
118        if (key3)
119            fKey3 = XMLString::replicate(key3, manager);
120    }
121
122    TVal*                                     fData;
123    DOMDeepNodeListPoolTableBucketElem<TVal>* fNext;
124    void*                                     fKey1;
125    XMLCh*                                    fKey2;
126    XMLCh*                                    fKey3;
127
128    ~DOMDeepNodeListPoolTableBucketElem() {};
129};
130
131
132template <class TVal> class DOMDeepNodeListPool
133{
134public:
135    // -----------------------------------------------------------------------
136    //  Constructors and Destructor
137    // -----------------------------------------------------------------------
138    // backwards compatability - default hasher is HashXMLCh
139    DOMDeepNodeListPool
140    (
141        const XMLSize_t modulus
142      , const XMLSize_t initSize = 128
143    );
144
145    // backwards compatability - default hasher is HashXMLCh
146    DOMDeepNodeListPool
147    (
148        const XMLSize_t modulus
149      , const bool adoptElems
150      , const XMLSize_t initSize = 128
151    );
152
153    // if a hash function is passed in, it will be deleted when the hashtable is deleted.
154    // use a new instance of the hasher class for each hashtable, otherwise one hashtable
155    // may delete the hasher of a different hashtable if both use the same hasher.
156    DOMDeepNodeListPool
157    (
158         const XMLSize_t modulus
159       , const bool adoptElems
160       , HashBase* hash
161       , const XMLSize_t initSize = 128
162    );
163
164    ~DOMDeepNodeListPool();
165
166    // -----------------------------------------------------------------------
167    //  Element management
168    // -----------------------------------------------------------------------
169    bool isEmpty() const;
170    bool containsKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
171    void removeAll();
172    void cleanup();
173
174
175    // -----------------------------------------------------------------------
176    //  Getters
177    // -----------------------------------------------------------------------
178    TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3);
179    const TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
180
181    TVal* getById(const XMLSize_t elemId);
182    const TVal* getById(const XMLSize_t elemId) const;
183
184    // -----------------------------------------------------------------------
185    //  Putters
186    // -----------------------------------------------------------------------
187        XMLSize_t put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt);
188
189private:
190
191    // -----------------------------------------------------------------------
192    //  Private methods
193    // -----------------------------------------------------------------------
194    DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal);
195    const DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const;
196    void initialize(const XMLSize_t modulus);
197
198    // -----------------------------------------------------------------------
199    // Unimplemented constructors and operators
200    // -----------------------------------------------------------------------
201    DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal> &);
202    DOMDeepNodeListPool<TVal> & operator = (const DOMDeepNodeListPool<TVal> &);
203
204    // -----------------------------------------------------------------------
205    //  Data members
206    //
207    //  fAdoptedElems
208    //      Indicates whether the values added are adopted or just referenced.
209    //      If adopted, then they are deleted when they are removed from the
210    //      hash table.
211    //
212    //  fBucketList
213    //      This is the array that contains the heads of all of the list
214    //      buckets, one for each possible hash value.
215    //
216    //  fHashModulus
217    //      The modulus used for this hash table, to hash the keys. This is
218    //      also the number of elements in the bucket list.
219    //
220    //  fHash
221    //      The hasher for the key1 data type.
222    //
223    //  fIdPtrs
224    //  fIdPtrsCount
225    //      This is the array of pointers to the bucket elements in order of
226    //      their assigned ids. So taking id N and referencing this array
227    //      gives you the element with that id. The count field indicates
228    //      the current size of this list. When fIdCounter+1 reaches this
229    //      value the list must be expanded.
230    //
231    //  fIdCounter
232    //      This is used to give out unique ids to added elements. It starts
233    //      at zero (which means empty), and is bumped up for each newly added
234    //      element. So the first element is 1, the next is 2, etc... This
235    //      means that this value is set to the top index of the fIdPtrs array.
236    // -----------------------------------------------------------------------
237    bool                                       fAdoptedElems;
238    DOMDeepNodeListPoolTableBucketElem<TVal>** fBucketList;
239    XMLSize_t                                  fHashModulus;
240    HashBase*                                  fHash;
241    TVal**                                     fIdPtrs;
242    XMLSize_t                                  fIdPtrsCount;
243    XMLSize_t                                  fIdCounter;
244    MemoryManager*                             fMemoryManager;
245};
246
247XERCES_CPP_NAMESPACE_END
248
249#if !defined(XERCES_TMPLSINC)
250#include <xercesc/dom/impl/DOMDeepNodeListPool.c>
251#endif
252
253#endif
Note: See TracBrowser for help on using the repository browser.