source: XMLIO_V2/external/include/Poco/SAX/AttributesImpl.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 9.1 KB
Line 
1//
2// AttributesImpl.h
3//
4// $Id: //poco/1.3/XML/include/Poco/SAX/AttributesImpl.h#3 $
5//
6// Library: XML
7// Package: SAX
8// Module:  SAX
9//
10// Implementation of the SAX2 Attributes Interface.
11//
12// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef SAX_AttributesImpl_INCLUDED
40#define SAX_AttributesImpl_INCLUDED
41
42
43#include "Poco/XML/XML.h"
44#include "Poco/SAX/Attributes.h"
45#include <vector>
46
47
48namespace Poco {
49namespace XML {
50
51
52class XML_API AttributesImpl: public Attributes
53        /// This class provides a default implementation of the SAX2 Attributes interface,
54        /// with the addition of manipulators so that the list can be modified or reused.
55        ///
56        /// There are two typical uses of this class:
57        ///     1. to take a persistent snapshot of an Attributes object in a startElement event; or
58        ///     2. to construct or modify an Attributes object in a SAX2 driver or filter.
59{
60public:
61        struct Attribute
62        {
63                XMLString localName;
64                XMLString namespaceURI;
65                XMLString qname;
66                XMLString value;
67                XMLString type;
68                bool      specified;
69        };
70        typedef std::vector<Attribute> AttributeVec;
71        typedef AttributeVec::const_iterator iterator;
72
73        AttributesImpl();
74                /// Creates the AttributesImpl.
75               
76        AttributesImpl(const Attributes& attributes);
77                /// Creates the AttributesImpl by copying another one.
78
79        AttributesImpl(const AttributesImpl& attributes);
80                /// Creates the AttributesImpl by copying another one.
81
82        ~AttributesImpl();
83                /// Destroys the AttributesImpl.
84
85        AttributesImpl& operator = (const AttributesImpl& attributes);
86                /// Assignment operator.
87
88        int getIndex(const XMLString& name) const;
89        int getIndex(const XMLString& namespaceURI, const XMLString& localName) const;
90        int getLength() const;
91        const XMLString& getLocalName(int i) const;
92        const XMLString& getQName(int i) const;
93        const XMLString& getType(int i) const;
94        const XMLString& getType(const XMLString& qname) const;
95        const XMLString& getType(const XMLString& namespaceURI, const XMLString& localName) const;
96        const XMLString& getValue(int i) const;
97        const XMLString& getValue(const XMLString& qname) const;
98        const XMLString& getValue(const XMLString& namespaceURI, const XMLString& localName) const;
99        const XMLString& getURI(int i) const;
100
101        bool isSpecified(int i) const;
102                /// Returns true unless the attribute value was provided by DTD defaulting.
103                /// Extension from Attributes2 interface.
104
105        bool isSpecified(const XMLString& qname) const;
106                /// Returns true unless the attribute value was provided by DTD defaulting.
107                /// Extension from Attributes2 interface.
108
109        bool isSpecified(const XMLString& namespaceURI, const XMLString& localName) const;
110                /// Returns true unless the attribute value was provided by DTD defaulting.
111                /// Extension from Attributes2 interface.
112
113        void setValue(int i, const XMLString& value);
114                /// Sets the value of an attribute.
115
116        void setValue(const XMLString& qname, const XMLString& value);
117                /// Sets the value of an attribute.
118
119        void setValue(const XMLString& namespaceURI, const XMLString& localName, const XMLString& value);
120                /// Sets the value of an attribute.
121
122        void setAttributes(const Attributes& attributes);
123                /// Copies the attributes from another Attributes object.
124
125        void setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value);
126                /// Sets an attribute.
127
128        void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value);
129                /// Adds an attribute to the end of the list.
130
131        void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value, bool specified);
132                /// Adds an attribute to the end of the list.
133
134        void addAttribute(const XMLChar* namespaceURI, const XMLChar* localName, const XMLChar* qname, const XMLChar* type, const XMLChar* value, bool specified);
135                /// Adds an attribute to the end of the list.
136
137        Attribute& addAttribute();
138                /// Add an (empty) attribute to the end of the list.
139                /// For internal use only.
140                /// The returned Attribute element must be filled by the caller.
141
142        void removeAttribute(int i);
143                /// Removes an attribute.
144
145        void removeAttribute(const XMLString& qname);
146                /// Removes an attribute.
147
148        void removeAttribute(const XMLString& namespaceURI, const XMLString& localName);
149                /// Removes an attribute.
150
151        void clear();
152                /// Removes all attributes.
153               
154        void reserve(std::size_t capacity);
155                /// Reserves capacity in the internal vector.
156
157        void setLocalName(int i, const XMLString& localName);
158                /// Sets the local name of an attribute.
159
160        void setQName(int i, const XMLString& qname);
161                /// Sets the qualified name of an attribute.
162
163        void setType(int i, const XMLString& type);
164                /// Sets the type of an attribute.
165
166        void setURI(int i, const XMLString& namespaceURI);
167                /// Sets the namespace URI of an attribute.
168
169        iterator begin() const;
170                /// Iterator support.
171               
172        iterator end() const;
173                /// Iterator support.
174
175protected:     
176        Attribute* find(const XMLString& qname) const;
177        Attribute* find(const XMLString& namespaceURI, const XMLString& localName) const;
178
179private:
180        AttributeVec _attributes;
181        Attribute _empty;
182};
183
184
185//
186// inlines
187//
188inline AttributesImpl::iterator AttributesImpl::begin() const
189{
190        return _attributes.begin();
191}
192
193
194inline AttributesImpl::iterator AttributesImpl::end() const
195{
196        return _attributes.end();
197}
198
199
200inline AttributesImpl::Attribute& AttributesImpl::addAttribute()
201{
202        _attributes.push_back(_empty);
203        return _attributes.back();
204}
205
206
207inline int AttributesImpl::getLength() const
208{
209        return (int) _attributes.size();
210}
211
212
213inline const XMLString& AttributesImpl::getLocalName(int i) const
214{
215        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
216        return _attributes[i].localName;
217}
218
219
220inline const XMLString& AttributesImpl::getQName(int i) const
221{
222        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
223        return _attributes[i].qname;
224}
225
226
227inline const XMLString& AttributesImpl::getType(int i) const
228{
229        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
230        return _attributes[i].type;
231}
232
233
234inline const XMLString& AttributesImpl::getType(const XMLString& qname) const
235{
236        Attribute* pAttr = find(qname);
237        if (pAttr)
238                return pAttr->type;
239        else
240                return _empty.type;
241}
242
243
244inline const XMLString& AttributesImpl::getType(const XMLString& namespaceURI, const XMLString& localName) const
245{
246        Attribute* pAttr = find(namespaceURI, localName);
247        if (pAttr)
248                return pAttr->type;
249        else
250                return _empty.type;
251}
252
253
254inline const XMLString& AttributesImpl::getValue(int i) const
255{
256        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
257        return _attributes[i].value;
258}
259
260
261inline const XMLString& AttributesImpl::getValue(const XMLString& qname) const
262{
263        Attribute* pAttr = find(qname);
264        if (pAttr)
265                return pAttr->value;
266        else
267                return _empty.value;
268}
269
270
271inline const XMLString& AttributesImpl::getValue(const XMLString& namespaceURI, const XMLString& localName) const
272{
273        Attribute* pAttr = find(namespaceURI, localName);
274        if (pAttr)
275                return pAttr->value;
276        else
277                return _empty.value;
278}
279
280
281inline const XMLString& AttributesImpl::getURI(int i) const
282{
283        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
284        return _attributes[i].namespaceURI;
285}
286
287
288inline bool AttributesImpl::isSpecified(int i) const
289{
290        poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
291        return _attributes[i].specified;
292}
293
294
295inline bool AttributesImpl::isSpecified(const XMLString& qname) const
296{
297        Attribute* pAttr = find(qname);
298        if (pAttr)
299                return pAttr->specified;
300        else
301                return false;
302}
303
304
305inline bool AttributesImpl::isSpecified(const XMLString& namespaceURI, const XMLString& localName) const
306{
307        Attribute* pAttr = find(namespaceURI, localName);
308        if (pAttr)
309                return pAttr->specified;
310        else
311                return false;
312}
313
314
315} } // namespace Poco::XML
316
317
318#endif // SAX_AttributesImpl_INCLUDED
Note: See TracBrowser for help on using the repository browser.