source: icXML/icXML-devel/src/xercesc/validators/DTD/DTDAttDefList.hpp @ 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.4 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.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DTDATTDEFLIST_HPP)
23#define XERCESC_INCLUDE_GUARD_DTDATTDEFLIST_HPP
24
25#include <icxercesc/util/RefHashTableOf.hpp>
26#include <icxercesc/validators/DTD/DTDElementDecl.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30//
31//  This is a derivative of the framework abstract class which defines the
32//  interface to a list of attribute defs that belong to a particular
33//  element. The scanner needs to be able to get a list of the attributes
34//  that an element supports, for use during the validation process and for
35//  fixed/default attribute processing.
36//
37//  Since each validator can store attributes differently, this abstract
38//  interface allows each validator to provide an implementation of this
39//  data structure that works best for it.
40//
41//  For us, we just wrap the RefHashTableOf collection that the DTDElementDecl
42//  class uses to store the attributes that belong to it.
43//
44//  This clss does not adopt the hash table, it just references it. The
45//  hash table is owned by the element decl it is a member of.
46//
47class VALIDATORS_EXPORT DTDAttDefList : public XMLAttDefList
48{
49public :
50    // -----------------------------------------------------------------------
51    //  Constructors and Destructor
52    // -----------------------------------------------------------------------
53    DTDAttDefList
54    (
55        RefHashTableOf<DTDAttDef>* const    listToUse,
56        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
57    );
58
59    ~DTDAttDefList();
60
61
62    // -----------------------------------------------------------------------
63    //  Implementation of the virtual interface
64    // -----------------------------------------------------------------------
65
66    virtual bool isEmpty() const;
67    virtual XMLAttDef* findAttDef
68    (
69        const   unsigned int       uriID
70        , const XMLCh* const        attName
71    );
72    virtual const XMLAttDef* findAttDef
73    (
74        const   unsigned int       uriID
75        , const XMLCh* const        attName
76    )   const;
77    virtual XMLAttDef* findAttDef
78    (
79        const   XMLCh* const        attURI
80        , const XMLCh* const        attName
81    );
82    virtual const XMLAttDef* findAttDef
83    (
84        const   XMLCh* const        attURI
85        , const XMLCh* const        attName
86    )   const;
87
88    /**
89     * return total number of attributes in this list
90     */
91    virtual XMLSize_t getAttDefCount() const ;
92
93    /**
94     * return attribute at the index-th position in the list.
95     */
96    virtual XMLAttDef &getAttDef(XMLSize_t index) ;
97
98    /**
99     * return attribute at the index-th position in the list.
100     */
101    virtual const XMLAttDef &getAttDef(XMLSize_t index) const ;
102
103    /***
104     * Support for Serialization/De-serialization
105     ***/
106    DECL_XSERIALIZABLE(DTDAttDefList)
107
108        DTDAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
109
110private :
111
112    void addAttDef(DTDAttDef *toAdd);
113    // -----------------------------------------------------------------------
114    // Unimplemented constructors and operators
115    // -----------------------------------------------------------------------
116    DTDAttDefList(const DTDAttDefList &);
117    DTDAttDefList& operator = (const  DTDAttDefList&);
118
119    // -----------------------------------------------------------------------
120    //  Private data members
121    //
122    //  fEnum
123    //      This is an enerator for the list that we use to do the enumerator
124    //      type methods of this class.
125    //
126    //  fList
127    //      The list of DTDAttDef objects that represent the attributes that
128    //      a particular element supports.
129    //  fArray
130    //      vector of pointers to the DTDAttDef objects contained in this list
131    //  fSize
132    //      size of fArray
133    //  fCount
134    //      number of DTDAttDef objects currently stored in this list
135    // -----------------------------------------------------------------------
136    RefHashTableOfEnumerator<DTDAttDef>*    fEnum;
137    RefHashTableOf<DTDAttDef>*              fList;
138    DTDAttDef**                             fArray;
139    XMLSize_t                               fSize;
140    XMLSize_t                               fCount;
141
142    friend class DTDElementDecl;
143};
144
145inline void DTDAttDefList::addAttDef(DTDAttDef *toAdd)
146{
147    if(fCount == fSize)
148    {
149        // need to grow fArray
150        fSize <<= 1;
151        DTDAttDef** newArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize ));
152        memcpy(newArray, fArray, fCount * sizeof(DTDAttDef *));
153        (getMemoryManager())->deallocate(fArray);
154        fArray = newArray;
155    }
156    fArray[fCount++] = toAdd;
157}
158
159XERCES_CPP_NAMESPACE_END
160
161#endif
Note: See TracBrowser for help on using the repository browser.