source: icXML/icXML-devel/src/icxercesc/internal/VecAttributesImpl.cpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

File size: 6.6 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: VecAttributesImpl.cpp 672311 2008-06-27 16:05:01Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/Janitor.hpp>
27#include <xercesc/internal/VecAttributesImpl.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31// ---------------------------------------------------------------------------
32//  Constructors and Destructor
33// ---------------------------------------------------------------------------
34VecAttributesImpl::VecAttributesImpl()
35: fAdopt(false)
36, fCount(0)
37, fVector(0)
38, fScanner(0)
39{
40
41}
42
43VecAttributesImpl::~VecAttributesImpl()
44{
45        //
46        //  Note that some compilers can't deal with the fact that the pointer
47        //  is to a const object, so we have to cast off the const'ness here!
48        //
49        if (fAdopt)
50                delete (RefVectorOf<XMLAttr>*)fVector;
51}
52
53
54// ---------------------------------------------------------------------------
55//  Implementation of the attribute list interface
56// ---------------------------------------------------------------------------
57XMLSize_t VecAttributesImpl::getLength() const
58{
59        return fCount;
60}
61
62const XMLCh* VecAttributesImpl::getURI(const XMLSize_t index) const
63{
64        // since this func really needs to be const, like the rest, not sure how we
65        // make it const and re-use the fURIBuffer member variable.  we're currently
66        // creating a buffer each time you need a URI.  there has to be a better
67        // way to do this...
68
69    DEBUG_NAMESPACE_MESSAGE("VecAttributesImpl::getURI(" << index << ")")
70
71        if (unlikely(index >= fCount)) return 0;
72
73    unsigned int uriId = fVector->elementAt(index)->getURIId();
74
75    DEBUG_NAMESPACE_MESSAGE(" --- uriId=" << uriId)
76
77    const XMLCh * uri = fScanner->getURIText(uriId);
78
79    DEBUG_NAMESPACE_MESSAGE(" --- uri=" << uri)
80
81    return uri;
82}
83
84const XMLCh* VecAttributesImpl::getLocalName(const XMLSize_t index) const
85{
86        if (unlikely(index >= fCount)) return 0;
87        return fVector->elementAt(index)->getName();
88}
89
90const XMLCh* VecAttributesImpl::getQName(const XMLSize_t index) const
91{
92        if (unlikely(index >= fCount)) return 0;
93        return fVector->elementAt(index)->getQName();
94}
95
96const XMLCh* VecAttributesImpl::getType(const XMLSize_t index) const
97{
98        if (unlikely(index >= fCount)) return 0;
99        return XMLAttDef::getAttTypeString(fVector->elementAt(index)->getType(), fVector->getMemoryManager());
100}
101
102const XMLCh* VecAttributesImpl::getValue(const XMLSize_t index) const
103{
104        if (unlikely(index >= fCount)) return 0;
105    const XMLAttr * attr = fVector->elementAt(index);
106    return attr->getValue();
107}
108
109bool VecAttributesImpl::getIndex(const XMLCh * const uri, const XMLCh * const localPart, XMLSize_t & index) const
110{
111        //
112        //  Search the vector for the attribute with the given name and return
113        //  its type.
114        //
115
116        const unsigned int uriId =
117                const_cast<XMLScanner*>(fScanner)->getUriResolver()->resolveUriId(uri);
118        for (XMLSize_t i = 0; i < fCount; i++)
119        {
120                const XMLAttr* curElem = fVector->elementAt(i);
121                if (curElem->getURIId() == uriId && XMLString::equals(curElem->getName(), localPart))
122                {
123                        index = i;
124                        return true;
125                }
126        }
127        index = -1;
128        return false;
129}
130
131int VecAttributesImpl::getIndex(const XMLCh* const uri, const XMLCh* const localPart) const
132{
133        //
134        //  Search the vector for the attribute with the given name and return
135        //  its type.
136        //
137        const unsigned int uriId =
138                const_cast<XMLScanner*>(fScanner)->getUriResolver()->resolveUriId(uri);
139        for (XMLSize_t i = 0; i < fCount; i++)
140        {
141                const XMLAttr* curElem = fVector->elementAt(i);
142                if (curElem->getURIId() == uriId && XMLString::equals(curElem->getName(), localPart))
143                {
144                        return i;
145                }
146        }
147        return -1;
148}
149
150bool VecAttributesImpl::getIndex(const XMLCh* const qName, XMLSize_t& index) const
151{
152        //
153        //  Search the vector for the attribute with the given name and return
154        //  its type.
155        //
156        for (index = 0; index < fCount; index++)
157        {
158                const XMLAttr* curElem = fVector->elementAt(index);
159
160                if (XMLString::equals(curElem->getQName(), qName))
161                        return true;
162        }
163        return false;
164}
165
166int VecAttributesImpl::getIndex(const XMLCh* const qName ) const
167{
168        //
169        //  Search the vector for the attribute with the given name and return
170        //  its type.
171        //
172        for (XMLSize_t index = 0; index < fCount; index++)
173        {
174                const XMLAttr* curElem = fVector->elementAt(index);
175
176                if (XMLString::equals(curElem->getQName(), qName))
177                        return (int)index ;
178        }
179        return -1;
180}
181
182const XMLCh* VecAttributesImpl::getType(const XMLCh* const uri, const XMLCh* const localPart ) const
183{
184        XMLSize_t i;
185
186        if (getIndex(uri, localPart, i))
187                return getType(i);
188        else
189                return 0;
190}
191
192const XMLCh* VecAttributesImpl::getType(const XMLCh* const qName) const
193{
194        XMLSize_t i;
195
196        if (getIndex(qName, i))
197                return getType(i);
198        else
199                return 0;
200}
201
202const XMLCh* VecAttributesImpl::getValue(const XMLCh* const uri, const XMLCh* const localPart ) const
203{
204        XMLSize_t i;
205
206        if (getIndex(uri, localPart, i))
207                return getValue(i);
208        else
209                return 0;
210}
211
212const XMLCh* VecAttributesImpl::getValue(const XMLCh* const qName) const
213{
214        XMLSize_t i;
215
216        if (getIndex(qName, i))
217                return getValue(i);
218        else
219                return 0;
220}
221
222// ---------------------------------------------------------------------------
223//  Setter methods
224// ---------------------------------------------------------------------------
225void VecAttributesImpl::setVector(const   RefVectorOf<XMLAttr>* const srcVec
226                                                                  , const XMLSize_t                count
227                                                                  , const XMLScanner * const        scanner
228                                                                  , const bool                        adopt)
229{
230        //
231        //  Delete the previous vector (if any) if we are adopting. Note that some
232        //  compilers can't deal with the fact that the pointer is to a const
233        //  object, so we have to cast off the const'ness here!
234        //
235        if (fAdopt)
236                delete (RefVectorOf<XMLAttr>*)fVector;
237
238        fAdopt = adopt;
239        fCount = count;
240        fVector = srcVec;
241        fScanner = scanner ;
242}
243
244XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.