GME  13
XSNamedMap.c
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00023 // ---------------------------------------------------------------------------
00024 //  Include
00025 // ---------------------------------------------------------------------------
00026 #if defined(XERCES_TMPLSINC)
00027 #include <xercesc/framework/psvi/XSNamedMap.hpp>
00028 #endif
00029 
00030 #include <xercesc/util/RefVectorOf.hpp>
00031 #include <xercesc/util/StringPool.hpp>
00032 
00033 XERCES_CPP_NAMESPACE_BEGIN
00034 
00035 // ---------------------------------------------------------------------------
00036 //  XSNamedMap: Constructors and Destructor
00037 // ---------------------------------------------------------------------------
00038 template <class TVal>
00039 XSNamedMap<TVal>::XSNamedMap(const XMLSize_t maxElems,
00040                              const XMLSize_t modulus,
00041                              XMLStringPool* uriStringPool,
00042                              const bool adoptElems,
00043                              MemoryManager* const manager)
00044     : fMemoryManager(manager)
00045     , fURIStringPool(uriStringPool)
00046 {
00047     // allow one of the Vector or Hash to own the data... but not both...
00048     fVector = new (manager) RefVectorOf<TVal> (maxElems, false, manager);
00049     fHash = new (manager) RefHash2KeysTableOf<TVal> (modulus, adoptElems, manager);
00050 }
00051 template <class TVal> XSNamedMap<TVal>::~XSNamedMap()
00052 {
00053     delete fVector;
00054     delete fHash;
00055 }
00056 
00057 
00063 template <class TVal>
00064 XMLSize_t XSNamedMap<TVal>::getLength() const
00065 {
00066     return fVector->size();
00067 }
00068 
00078 template <class TVal>
00079 TVal* XSNamedMap<TVal>::item(XMLSize_t index)
00080 {
00081     if (index >= fVector->size())
00082     {
00083         return 0;
00084     }
00085     return fVector->elementAt(index);
00086 }
00087 
00088 template <class TVal>
00089 const TVal* XSNamedMap<TVal>::item(XMLSize_t index) const
00090 {
00091     if (index >= fVector->size())
00092     {
00093         return 0;
00094     }
00095     return fVector->elementAt(index);
00096 }
00097 
00109 template <class TVal>
00110 TVal *XSNamedMap<TVal>::itemByName(const XMLCh *compNamespace,
00111                           const XMLCh *localName)
00112 {
00113     return fHash->get((void*)localName, fURIStringPool->getId(compNamespace));
00114 }
00115 
00116 
00117 template <class TVal>
00118 void XSNamedMap<TVal>::addElement(TVal* const toAdd, const XMLCh* key1, const XMLCh* key2)
00119 {
00120     fVector->addElement(toAdd);
00121     fHash->put((void*)key1, fURIStringPool->getId(key2), toAdd);
00122 }
00123 
00124 XERCES_CPP_NAMESPACE_END