source: obsolete/tags/VUT/0.4/GtpVisibilityPreprocessor/support/xerces/include/xercesc/framework/psvi/XSNamedMap.c @ 358

Revision 358, 4.6 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2003,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * $Log: XSNamedMap.c,v $
19 * Revision 1.4  2004/09/08 13:56:09  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.3  2003/11/07 20:30:28  neilg
23 * fix compilation errors on AIX and HPUX; thanks to David Cargill
24 *
25 * Revision 1.2  2003/11/06 15:30:04  neilg
26 * first part of PSVI/schema component model implementation, thanks to David Cargill.  This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse.
27 *
28 * Revision 1.1  2003/09/16 14:33:36  neilg
29 * PSVI/schema component model classes, with Makefile/configuration changes necessary to build them
30 *
31 */
32
33
34// ---------------------------------------------------------------------------
35//  Include
36// ---------------------------------------------------------------------------
37#if defined(XERCES_TMPLSINC)
38#include <xercesc/framework/psvi/XSNamedMap.hpp>
39#endif
40
41#include <xercesc/util/RefVectorOf.hpp>
42#include <xercesc/util/StringPool.hpp>
43
44XERCES_CPP_NAMESPACE_BEGIN
45
46// ---------------------------------------------------------------------------
47//  XSNamedMap: Constructors and Destructor
48// ---------------------------------------------------------------------------
49template <class TVal>
50XSNamedMap<TVal>::XSNamedMap(const unsigned int maxElems,
51                             const unsigned int modulus,
52                             XMLStringPool* uriStringPool,
53                             const bool adoptElems,
54                             MemoryManager* const manager)
55    : fMemoryManager(manager)
56    , fURIStringPool(uriStringPool)
57{
58    // allow one of the Vector or Hash to own the data... but not both...
59    fVector = new (manager) RefVectorOf<TVal> (maxElems, false, manager);
60    fHash = new (manager) RefHash2KeysTableOf<TVal> (modulus, adoptElems, manager);
61}
62template <class TVal> XSNamedMap<TVal>::~XSNamedMap()
63{
64    delete fVector;
65    delete fHash;
66}
67
68
69/**
70 * The number of <code>XSObjects</code> in the <code>XSObjectList</code>.
71 * The range of valid child object indices is 0 to
72 * <code>mapLength-1</code> inclusive.
73 */
74template <class TVal>
75unsigned int XSNamedMap<TVal>::getLength()
76{
77    return fVector->size();
78}
79
80/**
81 * Returns the <code>index</code>th item in the collection. The index
82 * starts at 0. If <code>index</code> is greater than or equal to the
83 * number of objects in the list, this returns <code>null</code>.
84 * @param index  index into the collection.
85 * @return  The <code>XSObject</code> at the <code>index</code>th
86 *   position in the <code>XSObjectList</code>, or <code>null</code> if
87 *   that is not a valid index.
88 */
89template <class TVal>
90TVal* XSNamedMap<TVal>::item(unsigned int index)
91{
92    if (index >= fVector->size())
93    {
94        return 0;
95    }
96    return fVector->elementAt(index);
97}
98
99/**
100 * Retrieves a component specified by local name and namespace URI.
101 * <br>applications must use the value null as the
102 * <code>compNamespace</code> parameter for components whose targetNamespace property
103 * is absent.
104 * @param compNamespace The namespace URI of the component to retrieve.
105 * @param localName The local name of the component to retrieve.
106 * @return A component (of any type) with the specified local
107 *   name and namespace URI, or <code>null</code> if they do not
108 *   identify any node in this map.
109 */
110template <class TVal>
111TVal *XSNamedMap<TVal>::itemByName(const XMLCh *compNamespace,
112                          const XMLCh *localName)
113{
114    return fHash->get((void*)localName, fURIStringPool->getId(compNamespace));
115}
116
117
118template <class TVal>
119void XSNamedMap<TVal>::addElement(TVal* const toAdd, const XMLCh* key1, const XMLCh* key2)
120{
121    fVector->addElement(toAdd);
122    fHash->put((void*)key1, fURIStringPool->getId(key2), toAdd);
123}
124
125XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.