source: icXML/icXML-devel/src/xercesc/internal/VecAttrListImpl.cpp @ 2722

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

Original Xerces files with import mods for icxercesc

File size: 4.8 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: VecAttrListImpl.cpp 672273 2008-06-27 13:57:00Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/Janitor.hpp>
27#include <xercesc/internal/VecAttrListImpl.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31// ---------------------------------------------------------------------------
32//  Constructors and Destructor
33// ---------------------------------------------------------------------------
34VecAttrListImpl::VecAttrListImpl() :
35
36    fAdopt(false)
37    , fCount(0)
38    , fVector(0)
39{
40}
41
42VecAttrListImpl::~VecAttrListImpl()
43{
44    //
45    //  Note that some compilers can't deal with the fact that the pointer
46    //  is to a const object, so we have to cast off the const'ness here!
47    //
48    if (fAdopt)
49        delete (RefVectorOf<XMLAttr>*)fVector;
50}
51
52
53// ---------------------------------------------------------------------------
54//  Implementation of the attribute list interface
55// ---------------------------------------------------------------------------
56XMLSize_t VecAttrListImpl::getLength() const
57{
58    return fCount;
59}
60
61const XMLCh* VecAttrListImpl::getName(const XMLSize_t index) const
62{
63    if (index >= fCount) {
64        return 0;
65    }
66    return fVector->elementAt(index)->getQName();
67}
68
69const XMLCh* VecAttrListImpl::getType(const XMLSize_t index) const
70{
71    if (index >= fCount) {
72        return 0;
73    }
74    return XMLAttDef::getAttTypeString(fVector->elementAt(index)->getType(), fVector->getMemoryManager());
75}
76
77const XMLCh* VecAttrListImpl::getValue(const XMLSize_t index) const
78{
79    if (index >= fCount) {
80        return 0;
81    }
82    return fVector->elementAt(index)->getValue();
83}
84
85const XMLCh* VecAttrListImpl::getType(const XMLCh* const name) const
86{
87    //
88    //  Search the vector for the attribute with the given name and return
89    //  its type.
90    //
91    for (XMLSize_t index = 0; index < fCount; index++)
92    {
93        const XMLAttr* curElem = fVector->elementAt(index);
94
95        if (XMLString::equals(curElem->getQName(), name))
96            return XMLAttDef::getAttTypeString(curElem->getType(), fVector->getMemoryManager());
97    }
98    return 0;
99}
100
101const XMLCh* VecAttrListImpl::getValue(const XMLCh* const name) const
102{
103    //
104    //  Search the vector for the attribute with the given name and return
105    //  its type.
106    //
107    for (XMLSize_t index = 0; index < fCount; index++)
108    {
109        const XMLAttr* curElem = fVector->elementAt(index);
110
111        if (XMLString::equals(curElem->getQName(), name))
112            return curElem->getValue();
113    }
114    return 0;
115}
116
117const XMLCh* VecAttrListImpl::getValue(const char* const name) const
118{
119    // Temporarily transcode the name for lookup
120    XMLCh* wideName = XMLString::transcode(name, XMLPlatformUtils::fgMemoryManager);
121    ArrayJanitor<XMLCh> janName(wideName, XMLPlatformUtils::fgMemoryManager);
122
123    //
124    //  Search the vector for the attribute with the given name and return
125    //  its type.
126    //
127    for (XMLSize_t index = 0; index < fCount; index++)
128    {
129        const XMLAttr* curElem = fVector->elementAt(index);
130
131        if (XMLString::equals(curElem->getQName(), wideName))
132            return curElem->getValue();
133    }
134    return 0;
135}
136
137
138
139// ---------------------------------------------------------------------------
140//  Setter methods
141// ---------------------------------------------------------------------------
142void VecAttrListImpl::setVector(const   RefVectorOf<XMLAttr>* const srcVec
143                                , const XMLSize_t                   count
144                                , const bool                        adopt)
145{
146    //
147    //  Delete the previous vector (if any) if we are adopting. Note that some
148    //  compilers can't deal with the fact that the pointer is to a const
149    //  object, so we have to cast off the const'ness here!
150    //
151    if (fAdopt)
152        delete (RefVectorOf<XMLAttr>*)fVector;
153
154    fAdopt = adopt;
155    fCount = count;
156    fVector = srcVec;
157}
158
159XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.