1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(ATTRIBUTELISTIMPL_HEADER_GUARD_1357924680)
19 #define ATTRIBUTELISTIMPL_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file.  Must be first.
24 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp>
25 
26 
27 
28 #include <xalanc/Include/XalanVector.hpp>
29 
30 
31 
32 #include <xercesc/sax/AttributeList.hpp>
33 
34 
35 
36 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
41 class AttributeVectorEntry;
42 
43 
44 
45 typedef xercesc::AttributeList    AttributeListType;
46 
47 
48 
49 class XALAN_PLATFORMSUPPORT_EXPORT AttributeListImpl : public AttributeListType
50 {
51 public:
52 
53     explicit
54     AttributeListImpl(MemoryManager&      theManager);
55 
56     virtual
57     ~AttributeListImpl();
58 
59     AttributeListImpl(const AttributeListImpl&  theSource,
60                         MemoryManager&      theManager);
61 
62     AttributeListImpl(const AttributeListType&  theSource,
63                         MemoryManager&      theManager);
64 
65     AttributeListImpl&
66     operator=(const AttributeListImpl&  theRHS);
67 
68     AttributeListImpl&
69     operator=(const AttributeListType&  theRHS);
70 
71     MemoryManager&
getMemoryManager()72     getMemoryManager()
73     {
74         return m_AttributeVector.getMemoryManager();
75     }
76 
77     // These are inherited from AttributeList
78     virtual XalanSize_t
79     getLength() const;
80 
81     virtual const XMLCh*
82     getName(const XalanSize_t index) const;
83 
84     virtual const XMLCh*
85     getType(const XalanSize_t index) const;
86 
87     virtual const XMLCh*
88     getValue(const XalanSize_t index) const;
89 
90     virtual const XMLCh*
91     getType(const XMLCh* const name) const;
92 
93     virtual const XMLCh*
94     getValue(const XMLCh* const name) const;
95 
96     virtual const XMLCh*
97     getValue(const char* const name) const;
98     // The mutators are new to this class.
99 
100     /**
101      * Remove all attributes from the list
102      */
103     virtual void
104     clear();
105 
106     /**
107      * Adds an attribute to the attribute list
108      *
109      * @param  name   attribute name
110      * @param type   attribute type, "CDATA," for example
111      * @param value  attribute value
112      */
113     virtual bool
114     addAttribute(
115             const XMLCh*    name,
116             const XMLCh*    type,
117             const XMLCh*    value);
118 
119     /**
120      * Removes an attribute from the attribute list
121      *
122      * @param  name   attribute name
123      */
124     virtual bool
125     removeAttribute(const XMLCh*    name);
126 
127     /**
128      * Swap the contents of two instances.  This must _never_
129      * throw an exception.
130      *
131      * @param thOther The instance with which to swap.
132      */
133     void
swap(AttributeListImpl & theOther)134     swap(AttributeListImpl&     theOther)
135     {
136         m_AttributeVector.swap(theOther.m_AttributeVector);
137     }
138 
139     /**
140      * Reserve room for the given number of
141      * attributes.
142      *
143      * @param theCount The number to reserve
144      */
145     void
reserve(XalanSize_t theCount)146     reserve(XalanSize_t     theCount)
147     {
148         m_AttributeVector.reserve(theCount);
149     }
150 
151     // This vector will hold the entries.
152     typedef XalanVector<AttributeVectorEntry*>          AttributeVectorType;
153 
154 private:
155 
156     // This is not implemented.
157     bool
158     operator==(const AttributeListImpl&) const;
159 
160     // Default vector allocation size.
161     enum
162     {
163         eDefaultVectorSize = 5
164     };
165 
166     AttributeVectorEntry*
167     getNewEntry(
168             const XMLCh*    name,
169             const XMLCh*    type,
170             const XMLCh*    value);
171 
172     // Helper function to delete entries...
173     static void
174     deleteEntries(AttributeVectorType&  theVector);
175 
176     AttributeVectorType     m_AttributeVector;
177 
178     AttributeVectorType     m_cacheVector;
179 };
180 
181 
182 
183 }
184 
185 
186 
187 #endif  // ATTRIBUTELISTIMPL_HEADER_GUARD_1357924680
188