Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:01

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 //
0023 //  This file is part of the internal implementation of the C++ XML DOM.
0024 //  It should NOT be included or used directly by application programs.
0025 //
0026 //  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
0027 //  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
0028 //  name is substituded for the *.
0029 //
0030 
0031 #if !defined(XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP)
0032 #define XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP
0033 
0034 
0035 #include <xercesc/util/Hashers.hpp>
0036 #include <xercesc/util/IllegalArgumentException.hpp>
0037 #include <xercesc/util/NoSuchElementException.hpp>
0038 #include <xercesc/util/RuntimeException.hpp>
0039 #include <xercesc/util/XMLExceptMsgs.hpp>
0040 #include <xercesc/util/XMLEnumerator.hpp>
0041 
0042 XERCES_CPP_NAMESPACE_BEGIN
0043 
0044 //
0045 //  This should really be a nested class, but some of the compilers we
0046 //  have to support cannot deal with that!
0047 //
0048 template <class TVal>
0049 struct DOMDeepNodeListPoolTableBucketElem : public XMemory
0050 {
0051     DOMDeepNodeListPoolTableBucketElem
0052     (
0053         void* key1
0054         , XMLCh* key2
0055         , XMLCh* key3
0056         , TVal* const value
0057         , DOMDeepNodeListPoolTableBucketElem<TVal>* next
0058         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0059     ) :
0060     fData(value)
0061     , fNext(next)
0062     , fKey1(key1)
0063     , fKey2(0)
0064     , fKey3(0)
0065     {
0066         if (key2)
0067             fKey2 = XMLString::replicate(key2, manager);
0068 
0069         if (key3)
0070             fKey3 = XMLString::replicate(key3, manager);
0071     }
0072 
0073     TVal*                                     fData;
0074     DOMDeepNodeListPoolTableBucketElem<TVal>* fNext;
0075     void*                                     fKey1;
0076     XMLCh*                                    fKey2;
0077     XMLCh*                                    fKey3;
0078 
0079     ~DOMDeepNodeListPoolTableBucketElem() {};
0080 };
0081 
0082 
0083 template <class TVal, class THasher = PtrHasher>
0084 class DOMDeepNodeListPool
0085 {
0086 public:
0087     // -----------------------------------------------------------------------
0088     //  Constructors and Destructor
0089     // -----------------------------------------------------------------------
0090     DOMDeepNodeListPool
0091     (
0092         const XMLSize_t modulus
0093       , const XMLSize_t initSize = 128
0094     );
0095 
0096     DOMDeepNodeListPool
0097     (
0098         const XMLSize_t modulus
0099       , const bool adoptElems
0100       , const XMLSize_t initSize = 128
0101     );
0102 
0103     DOMDeepNodeListPool
0104     (
0105          const XMLSize_t modulus
0106        , const bool adoptElems
0107        , const THasher& hasher
0108        , const XMLSize_t initSize = 128
0109     );
0110 
0111     ~DOMDeepNodeListPool();
0112 
0113     // -----------------------------------------------------------------------
0114     //  Element management
0115     // -----------------------------------------------------------------------
0116     bool isEmpty() const;
0117     bool containsKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
0118     void removeAll();
0119     void cleanup();
0120 
0121 
0122     // -----------------------------------------------------------------------
0123     //  Getters
0124     // -----------------------------------------------------------------------
0125     TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3);
0126     const TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
0127 
0128     TVal* getById(const XMLSize_t elemId);
0129     const TVal* getById(const XMLSize_t elemId) const;
0130 
0131     // -----------------------------------------------------------------------
0132     //  Putters
0133     // -----------------------------------------------------------------------
0134     XMLSize_t put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt);
0135 
0136 private:
0137 
0138     // -----------------------------------------------------------------------
0139     //  Private methods
0140     // -----------------------------------------------------------------------
0141     DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal);
0142     const DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const;
0143     void initialize(const XMLSize_t modulus);
0144 
0145     // -----------------------------------------------------------------------
0146     // Unimplemented constructors and operators
0147     // -----------------------------------------------------------------------
0148     DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal, THasher> &);
0149     DOMDeepNodeListPool<TVal, THasher> & operator = (const DOMDeepNodeListPool<TVal, THasher> &);
0150 
0151     // -----------------------------------------------------------------------
0152     //  Data members
0153     //
0154     //  fAdoptedElems
0155     //      Indicates whether the values added are adopted or just referenced.
0156     //      If adopted, then they are deleted when they are removed from the
0157     //      hash table.
0158     //
0159     //  fBucketList
0160     //      This is the array that contains the heads of all of the list
0161     //      buckets, one for each possible hash value.
0162     //
0163     //  fHashModulus
0164     //      The modulus used for this hash table, to hash the keys. This is
0165     //      also the number of elements in the bucket list.
0166     //
0167     //  fHash
0168     //      The hasher for the key1 data type.
0169     //
0170     //  fIdPtrs
0171     //  fIdPtrsCount
0172     //      This is the array of pointers to the bucket elements in order of
0173     //      their assigned ids. So taking id N and referencing this array
0174     //      gives you the element with that id. The count field indicates
0175     //      the current size of this list. When fIdCounter+1 reaches this
0176     //      value the list must be expanded.
0177     //
0178     //  fIdCounter
0179     //      This is used to give out unique ids to added elements. It starts
0180     //      at zero (which means empty), and is bumped up for each newly added
0181     //      element. So the first element is 1, the next is 2, etc... This
0182     //      means that this value is set to the top index of the fIdPtrs array.
0183     // -----------------------------------------------------------------------
0184     bool                                       fAdoptedElems;
0185     DOMDeepNodeListPoolTableBucketElem<TVal>** fBucketList;
0186     XMLSize_t                                  fHashModulus;
0187     TVal**                                     fIdPtrs;
0188     XMLSize_t                                  fIdPtrsCount;
0189     XMLSize_t                                  fIdCounter;
0190     MemoryManager*                             fMemoryManager;
0191     THasher                                    fHasher;
0192 };
0193 
0194 XERCES_CPP_NAMESPACE_END
0195 
0196 #if !defined(XERCES_TMPLSINC)
0197 #include <xercesc/dom/impl/DOMDeepNodeListPool.c>
0198 #endif
0199 
0200 #endif