|
||||
File indexing completed on 2025-01-18 10:14:52
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 // --------------------------------------------------------------------------- 0024 // Include 0025 // --------------------------------------------------------------------------- 0026 #if defined(XERCES_TMPLSINC) 0027 #include <xercesc/framework/psvi/XSNamedMap.hpp> 0028 #endif 0029 0030 #include <xercesc/util/RefVectorOf.hpp> 0031 #include <xercesc/util/StringPool.hpp> 0032 0033 XERCES_CPP_NAMESPACE_BEGIN 0034 0035 // --------------------------------------------------------------------------- 0036 // XSNamedMap: Constructors and Destructor 0037 // --------------------------------------------------------------------------- 0038 template <class TVal> 0039 XSNamedMap<TVal>::XSNamedMap(const XMLSize_t maxElems, 0040 const XMLSize_t modulus, 0041 XMLStringPool* uriStringPool, 0042 const bool adoptElems, 0043 MemoryManager* const manager) 0044 : fMemoryManager(manager) 0045 , fURIStringPool(uriStringPool) 0046 { 0047 // allow one of the Vector or Hash to own the data... but not both... 0048 fVector = new (manager) RefVectorOf<TVal> (maxElems, false, manager); 0049 fHash = new (manager) RefHash2KeysTableOf<TVal> (modulus, adoptElems, manager); 0050 } 0051 template <class TVal> XSNamedMap<TVal>::~XSNamedMap() 0052 { 0053 delete fVector; 0054 delete fHash; 0055 } 0056 0057 0058 /** 0059 * The number of <code>XSObjects</code> in the <code>XSObjectList</code>. 0060 * The range of valid child object indices is 0 to 0061 * <code>mapLength-1</code> inclusive. 0062 */ 0063 template <class TVal> 0064 XMLSize_t XSNamedMap<TVal>::getLength() const 0065 { 0066 return fVector->size(); 0067 } 0068 0069 /** 0070 * Returns the <code>index</code>th item in the collection. The index 0071 * starts at 0. If <code>index</code> is greater than or equal to the 0072 * number of objects in the list, this returns <code>null</code>. 0073 * @param index index into the collection. 0074 * @return The <code>XSObject</code> at the <code>index</code>th 0075 * position in the <code>XSObjectList</code>, or <code>null</code> if 0076 * that is not a valid index. 0077 */ 0078 template <class TVal> 0079 TVal* XSNamedMap<TVal>::item(XMLSize_t index) 0080 { 0081 if (index >= fVector->size()) 0082 { 0083 return 0; 0084 } 0085 return fVector->elementAt(index); 0086 } 0087 0088 template <class TVal> 0089 const TVal* XSNamedMap<TVal>::item(XMLSize_t index) const 0090 { 0091 if (index >= fVector->size()) 0092 { 0093 return 0; 0094 } 0095 return fVector->elementAt(index); 0096 } 0097 0098 /** 0099 * Retrieves a component specified by local name and namespace URI. 0100 * <br>applications must use the value null as the 0101 * <code>compNamespace</code> parameter for components whose targetNamespace property 0102 * is absent. 0103 * @param compNamespace The namespace URI of the component to retrieve. 0104 * @param localName The local name of the component to retrieve. 0105 * @return A component (of any type) with the specified local 0106 * name and namespace URI, or <code>null</code> if they do not 0107 * identify any node in this map. 0108 */ 0109 template <class TVal> 0110 TVal *XSNamedMap<TVal>::itemByName(const XMLCh *compNamespace, 0111 const XMLCh *localName) 0112 { 0113 return fHash->get((void*)localName, fURIStringPool->getId(compNamespace)); 0114 } 0115 0116 0117 template <class TVal> 0118 void XSNamedMap<TVal>::addElement(TVal* const toAdd, const XMLCh* key1, const XMLCh* key2) 0119 { 0120 fVector->addElement(toAdd); 0121 fHash->put((void*)key1, fURIStringPool->getId(key2), toAdd); 0122 } 0123 0124 XERCES_CPP_NAMESPACE_END
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |