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