secureswitools/swisistools/source/xmlparser/xerces/include/xercesc/util/RefHash3KeysIdPool.hpp
changeset 0 ba25891c3a9e
child 1 c42dffbd5b4f
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 /*
       
    18  * Licensed to the Apache Software Foundation (ASF) under one or more
       
    19  * contributor license agreements.  See the NOTICE file distributed with
       
    20  * this work for additional information regarding copyright ownership.
       
    21  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    22  * (the "License"); you may not use this file except in compliance with
       
    23  * the License.  You may obtain a copy of the License at
       
    24  * 
       
    25  *      http://www.apache.org/licenses/LICENSE-2.0
       
    26  * 
       
    27  * Unless required by applicable law or agreed to in writing, software
       
    28  * distributed under the License is distributed on an "AS IS" BASIS,
       
    29  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    30  * See the License for the specific language governing permissions and
       
    31  * limitations under the License.
       
    32  */
       
    33 
       
    34 /*
       
    35  * $Id: RefHash3KeysIdPool.hpp 568078 2007-08-21 11:43:25Z amassari $
       
    36  */
       
    37 
       
    38 
       
    39 #if !defined(REFHASH3KEYSIDPOOL_HPP)
       
    40 #define REFHASH3KEYSIDPOOL_HPP
       
    41 
       
    42 
       
    43 #include <xercesc/util/HashBase.hpp>
       
    44 #include <xercesc/util/IllegalArgumentException.hpp>
       
    45 #include <xercesc/util/NoSuchElementException.hpp>
       
    46 #include <xercesc/util/RuntimeException.hpp>
       
    47 #include <xercesc/util/PlatformUtils.hpp>
       
    48 #include <xercesc/util/XMLString.hpp>
       
    49 #include <xercesc/util/HashXMLCh.hpp>
       
    50 
       
    51 XERCES_CPP_NAMESPACE_BEGIN
       
    52 
       
    53 // This hash table is a combination of RefHash2KeyTableOf (with an additional integer as key3)
       
    54 // and NameIdPool with an id as index
       
    55 
       
    56 //
       
    57 //  Forward declare the enumerator so he can be our friend. Can you say
       
    58 //  friend? Sure...
       
    59 //
       
    60 template <class TVal> class RefHash3KeysIdPoolEnumerator;
       
    61 template <class TVal> struct RefHash3KeysTableBucketElem;
       
    62 
       
    63 
       
    64 //
       
    65 //  This should really be a nested class, but some of the compilers we
       
    66 //  have to support cannot deal with that!
       
    67 //
       
    68 template <class TVal> struct RefHash3KeysTableBucketElem
       
    69 {
       
    70     RefHash3KeysTableBucketElem(
       
    71               void* key1
       
    72               , int key2
       
    73               , int key3
       
    74               , TVal* const value
       
    75               , RefHash3KeysTableBucketElem<TVal>* next) :
       
    76 		fData(value)
       
    77     , fNext(next)
       
    78     , fKey1(key1)
       
    79     , fKey2(key2)
       
    80     , fKey3(key3)
       
    81     {
       
    82     }
       
    83     
       
    84     RefHash3KeysTableBucketElem() {};
       
    85     ~RefHash3KeysTableBucketElem() {};
       
    86 
       
    87     TVal*  fData;
       
    88     RefHash3KeysTableBucketElem<TVal>*   fNext;
       
    89     void*  fKey1;
       
    90     int    fKey2;
       
    91     int    fKey3;
       
    92 
       
    93 private:
       
    94     // -----------------------------------------------------------------------
       
    95     //  Unimplemented constructors and operators
       
    96     // -----------------------------------------------------------------------
       
    97     RefHash3KeysTableBucketElem(const RefHash3KeysTableBucketElem<TVal>&);
       
    98     RefHash3KeysTableBucketElem<TVal>& operator=(const RefHash3KeysTableBucketElem<TVal>&);
       
    99 };
       
   100 
       
   101 
       
   102 template <class TVal> class RefHash3KeysIdPool : public XMemory
       
   103 {
       
   104 public:
       
   105     // -----------------------------------------------------------------------
       
   106     //  Constructors and Destructor
       
   107     // -----------------------------------------------------------------------
       
   108     // backwards compatability - default hasher is HashXMLCh
       
   109     RefHash3KeysIdPool
       
   110     (
       
   111           const unsigned int   modulus
       
   112         , const unsigned int   initSize = 128
       
   113         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
       
   114     );
       
   115 
       
   116     // backwards compatability - default hasher is HashXMLCh
       
   117     RefHash3KeysIdPool
       
   118     (
       
   119           const unsigned int   modulus
       
   120         , const bool           adoptElems
       
   121         , const unsigned int   initSize = 128
       
   122         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
       
   123     );
       
   124 
       
   125     // if a hash function is passed in, it will be deleted when the hashtable is deleted.
       
   126     // use a new instance of the hasher class for each hashtable, otherwise one hashtable
       
   127     // may delete the hasher of a different hashtable if both use the same hasher.
       
   128     RefHash3KeysIdPool
       
   129     (
       
   130           const unsigned int   modulus
       
   131         , const bool           adoptElems
       
   132         , HashBase* hashBase
       
   133         , const unsigned int initSize = 128
       
   134         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
       
   135     );
       
   136 
       
   137     ~RefHash3KeysIdPool();
       
   138 
       
   139     // -----------------------------------------------------------------------
       
   140     //  Element management
       
   141     // -----------------------------------------------------------------------
       
   142     bool isEmpty() const;
       
   143     bool containsKey(const void* const key1, const int key2, const int key3) const;
       
   144     void removeAll();
       
   145 
       
   146 
       
   147     // -----------------------------------------------------------------------
       
   148     //  Getters
       
   149     // -----------------------------------------------------------------------
       
   150     TVal* getByKey(const void* const key1, const int key2, const int key3);
       
   151     const TVal* getByKey(const void* const key1, const int key2, const int key3) const;
       
   152 
       
   153     TVal* getById(const unsigned elemId);
       
   154     const TVal* getById(const unsigned elemId) const;
       
   155 
       
   156     MemoryManager* getMemoryManager() const;
       
   157     unsigned int   getHashModulus()   const;
       
   158 
       
   159     // -----------------------------------------------------------------------
       
   160     //  Putters
       
   161     // -----------------------------------------------------------------------
       
   162 	unsigned int put(void* key1, int key2, int key3, TVal* const valueToAdopt);
       
   163 
       
   164 
       
   165 private :
       
   166     // -----------------------------------------------------------------------
       
   167     //  Declare our friends
       
   168     // -----------------------------------------------------------------------
       
   169     friend class RefHash3KeysIdPoolEnumerator<TVal>;
       
   170 
       
   171 private:
       
   172     // -----------------------------------------------------------------------
       
   173     //  Unimplemented constructors and operators
       
   174     // -----------------------------------------------------------------------
       
   175     RefHash3KeysIdPool(const RefHash3KeysIdPool<TVal>&);
       
   176     RefHash3KeysIdPool<TVal>& operator=(const RefHash3KeysIdPool<TVal>&);
       
   177 
       
   178     // -----------------------------------------------------------------------
       
   179     //  Private methods
       
   180     // -----------------------------------------------------------------------
       
   181     RefHash3KeysTableBucketElem<TVal>* findBucketElem(const void* const key1, const int key2, const int key3, unsigned int& hashVal);
       
   182     const RefHash3KeysTableBucketElem<TVal>* findBucketElem(const void* const key1, const int key2, const int key3, unsigned int& hashVal) const;
       
   183     void initialize(const unsigned int modulus);
       
   184 
       
   185 
       
   186     // -----------------------------------------------------------------------
       
   187     //  Data members
       
   188     //
       
   189     //  fAdoptedElems
       
   190     //      Indicates whether the values added are adopted or just referenced.
       
   191     //      If adopted, then they are deleted when they are removed from the
       
   192     //      hash table.
       
   193     //
       
   194     //  fBucketList
       
   195     //      This is the array that contains the heads of all of the list
       
   196     //      buckets, one for each possible hash value.
       
   197     //
       
   198     //  fHashModulus
       
   199     //      The modulus used for this hash table, to hash the keys. This is
       
   200     //      also the number of elements in the bucket list.
       
   201     //
       
   202     //  fHash
       
   203     //      The hasher for the key1 data type.
       
   204     //
       
   205     //  fIdPtrs
       
   206     //  fIdPtrsCount
       
   207     //      This is the array of pointers to the bucket elements in order of
       
   208     //      their assigned ids. So taking id N and referencing this array
       
   209     //      gives you the element with that id. The count field indicates
       
   210     //      the current size of this list. When fIdCounter+1 reaches this
       
   211     //      value the list must be expanded.
       
   212     //
       
   213     //  fIdCounter
       
   214     //      This is used to give out unique ids to added elements. It starts
       
   215     //      at zero (which means empty), and is bumped up for each newly added
       
   216     //      element. So the first element is 1, the next is 2, etc... This
       
   217     //      means that this value is set to the top index of the fIdPtrs array.
       
   218     // -----------------------------------------------------------------------
       
   219     MemoryManager*                      fMemoryManager;
       
   220     bool                                fAdoptedElems;
       
   221     RefHash3KeysTableBucketElem<TVal>** fBucketList;
       
   222     unsigned int                        fHashModulus;
       
   223     HashBase*                           fHash;
       
   224     TVal**                              fIdPtrs;
       
   225     unsigned int                        fIdPtrsCount;
       
   226     unsigned int                        fIdCounter;
       
   227 };
       
   228 
       
   229 
       
   230 
       
   231 //
       
   232 //  An enumerator for a value array. It derives from the basic enumerator
       
   233 //  class, so that value vectors can be generically enumerated.
       
   234 //
       
   235 template <class TVal> class RefHash3KeysIdPoolEnumerator : public XMLEnumerator<TVal>, public XMemory
       
   236 {
       
   237 public :
       
   238     // -----------------------------------------------------------------------
       
   239     //  Constructors and Destructor
       
   240     // -----------------------------------------------------------------------
       
   241     RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal>* const toEnum
       
   242         , const bool adopt = false
       
   243         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
       
   244     virtual ~RefHash3KeysIdPoolEnumerator();
       
   245 
       
   246     RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal>&);
       
   247     // -----------------------------------------------------------------------
       
   248     //  Enum interface
       
   249     // -----------------------------------------------------------------------
       
   250     bool hasMoreElements() const;
       
   251     TVal& nextElement();
       
   252     void Reset();
       
   253     int  size() const;
       
   254 
       
   255     // -----------------------------------------------------------------------
       
   256     //  New interface 
       
   257     // -----------------------------------------------------------------------
       
   258     void resetKey();
       
   259     void nextElementKey(void*&, int&, int&);
       
   260     bool hasMoreKeys()   const;
       
   261 
       
   262 private :
       
   263     // -----------------------------------------------------------------------
       
   264     //  Unimplemented constructors and operators
       
   265     // -----------------------------------------------------------------------    
       
   266     RefHash3KeysIdPoolEnumerator<TVal>& operator=(const RefHash3KeysIdPoolEnumerator<TVal>&);
       
   267 
       
   268     // -----------------------------------------------------------------------
       
   269     //  Private methods
       
   270     // -----------------------------------------------------------------------
       
   271     void findNext();
       
   272 
       
   273     // -----------------------------------------------------------------------
       
   274     //  Data Members
       
   275     //  fAdoptedElems
       
   276     //      Indicates whether the values added are adopted or just referenced.
       
   277     //      If adopted, then they are deleted when they are removed from the
       
   278     //      hash table
       
   279     //
       
   280     //  fCurIndex
       
   281     //      This is the current index into the pool's id mapping array. This
       
   282     //      is now we enumerate it.
       
   283     //
       
   284     //  fToEnum
       
   285     //      The name id pool that is being enumerated.
       
   286     // -----------------------------------------------------------------------
       
   287     bool                                fAdoptedElems;
       
   288     unsigned int                        fCurIndex;
       
   289     RefHash3KeysIdPool<TVal>*           fToEnum;
       
   290     RefHash3KeysTableBucketElem<TVal>*  fCurElem;
       
   291     unsigned int                        fCurHash;
       
   292     MemoryManager* const                fMemoryManager;
       
   293 };
       
   294 
       
   295 XERCES_CPP_NAMESPACE_END
       
   296 
       
   297 #if !defined(XERCES_TMPLSINC)
       
   298 #include <xercesc/util/RefHash3KeysIdPool.c>
       
   299 #endif
       
   300 
       
   301 #endif