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 |
|
---|
44 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
45 |
|
---|
46 | // ---------------------------------------------------------------------------
|
---|
47 | // XSNamedMap: Constructors and Destructor
|
---|
48 | // ---------------------------------------------------------------------------
|
---|
49 | template <class TVal>
|
---|
50 | XSNamedMap<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 | }
|
---|
62 | template <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 | */
|
---|
74 | template <class TVal>
|
---|
75 | unsigned 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 | */
|
---|
89 | template <class TVal>
|
---|
90 | TVal* 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 | */
|
---|
110 | template <class TVal>
|
---|
111 | TVal *XSNamedMap<TVal>::itemByName(const XMLCh *compNamespace,
|
---|
112 | const XMLCh *localName)
|
---|
113 | {
|
---|
114 | return fHash->get((void*)localName, fURIStringPool->getId(compNamespace));
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | template <class TVal>
|
---|
119 | void 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 |
|
---|
125 | XERCES_CPP_NAMESPACE_END
|
---|