source: icXML/icXML-devel/src/xercesc/validators/DTD/DTDAttDefList.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: 5.1 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: DTDAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/DTD/DTDAttDefList.hpp>
27#include <xercesc/internal/XTemplateSerializer.hpp>
28#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  DTDAttDefList: Constructors and Destructor
34// ---------------------------------------------------------------------------
35DTDAttDefList::DTDAttDefList(RefHashTableOf<DTDAttDef>* const listToUse, MemoryManager* const manager)
36: XMLAttDefList(manager)
37,fEnum(0)
38,fList(listToUse)
39,fArray(0)
40,fSize(0)
41,fCount(0)
42{
43    fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(listToUse, false, manager);
44    fArray = (DTDAttDef **)(manager->allocate( sizeof(DTDAttDef*) << 1));
45    fSize = 2;
46}
47
48DTDAttDefList::~DTDAttDefList()
49{
50    delete fEnum;
51    (getMemoryManager())->deallocate(fArray);
52}
53
54
55// ---------------------------------------------------------------------------
56//  DTDAttDefList: Implementation of the virtual interface
57// ---------------------------------------------------------------------------
58
59bool DTDAttDefList::isEmpty() const
60{
61    return fList->isEmpty();
62}
63
64
65XMLAttDef* DTDAttDefList::findAttDef(const  unsigned int
66                                    , const XMLCh* const    attName)
67{
68    // We don't use the URI, so we just look up the name
69    return fList->get(attName);
70}
71
72
73const XMLAttDef*
74DTDAttDefList::findAttDef(  const   unsigned int
75                            , const XMLCh* const    attName) const
76{
77    // We don't use the URI, so we just look up the name
78    return fList->get(attName);
79}
80
81
82XMLAttDef* DTDAttDefList::findAttDef(   const   XMLCh* const
83                                        , const XMLCh* const    attName)
84{
85    // We don't use the URI, so we just look up the name
86    return fList->get(attName);
87}
88
89
90const XMLAttDef*
91DTDAttDefList::findAttDef(  const   XMLCh* const
92                            , const XMLCh* const    attName) const
93{
94    // We don't use the URI, so we just look up the name
95    return fList->get(attName);
96}
97
98/**
99 * return total number of attributes in this list
100 */
101XMLSize_t DTDAttDefList::getAttDefCount() const
102{
103    return fCount;
104}
105
106/**
107 * return attribute at the index-th position in the list.
108 */
109XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index)
110{
111    if(index >= fCount)
112        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
113    return *(fArray[index]);
114}
115
116/**
117 * return attribute at the index-th position in the list.
118 */
119const XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index) const
120{
121    if(index >= fCount)
122        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
123    return *(fArray[index]);
124}
125
126/***
127 * Support for Serialization/De-serialization
128 ***/
129
130IMPL_XSERIALIZABLE_TOCREATE(DTDAttDefList)
131
132void DTDAttDefList::serialize(XSerializeEngine& serEng)
133{
134
135    XMLAttDefList::serialize(serEng);
136
137    if (serEng.isStoring())
138    {
139        /***
140         *
141         * Serialize RefHashTableOf<DTDAttDef>
142         *
143         ***/
144        XTemplateSerializer::storeObject(fList, serEng);
145        serEng.writeSize (fCount);
146
147        // do not serialize fEnum
148    }
149    else
150    {
151        /***
152         *
153         * Deserialize RefHashTableOf<DTDAttDef>
154         *
155         ***/
156        XTemplateSerializer::loadObject(&fList, 29, true, serEng);
157        // assume empty so we can size fArray just right
158        serEng.readSize (fSize);
159        if (!fEnum && fList)
160        {
161             fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(fList, false, getMemoryManager());
162        }
163        if(fSize)
164        {
165            (getMemoryManager())->deallocate(fArray);
166            fArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize));
167            fCount = 0;
168            while(fEnum->hasMoreElements())
169            {
170                fArray[fCount++] = &fEnum->nextElement();
171            }
172        }
173    }
174
175}
176
177
178DTDAttDefList::DTDAttDefList(MemoryManager* const manager)
179: XMLAttDefList(manager)
180,fEnum(0)
181,fList(0)
182,fArray(0)
183,fSize(0)
184,fCount(0)
185{
186}
187
188XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.