2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2001 Peter Kelly (pmk@post.com)
7 * (C) 2001 Dirk Mueller (mueller@kde.org)
8 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
27 #ifndef NamedAttrMap_h
28 #define NamedAttrMap_h
30 #include "Attribute.h"
31 #include "NamedNodeMap.h"
32 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h>
36 #define id id_AVOID_KEYWORD
41 // the map of attributes of an element
42 class NamedAttrMap
: public NamedNodeMap
{
45 NamedAttrMap(Element
* element
) : m_element(element
) { }
47 static PassRefPtr
<NamedAttrMap
> create(Element
* element
) { return adoptRef(new NamedAttrMap(element
)); }
49 virtual ~NamedAttrMap();
51 void setAttributes(const NamedAttrMap
&);
53 // DOM methods & attributes for NamedNodeMap
55 virtual PassRefPtr
<Node
> getNamedItem(const String
& name
) const;
56 virtual PassRefPtr
<Node
> removeNamedItem(const String
& name
, ExceptionCode
&);
58 virtual PassRefPtr
<Node
> getNamedItemNS(const String
& namespaceURI
, const String
& localName
) const;
59 virtual PassRefPtr
<Node
> removeNamedItemNS(const String
& namespaceURI
, const String
& localName
, ExceptionCode
&);
61 virtual PassRefPtr
<Node
> getNamedItem(const QualifiedName
& name
) const;
62 virtual PassRefPtr
<Node
> removeNamedItem(const QualifiedName
& name
, ExceptionCode
&);
63 virtual PassRefPtr
<Node
> setNamedItem(Node
* arg
, ExceptionCode
&);
65 virtual PassRefPtr
<Node
> item(unsigned index
) const;
66 size_t length() const { return m_attributes
.size(); }
68 // Other methods (not part of DOM)
69 Attribute
* attributeItem(unsigned index
) const { return m_attributes
[index
].get(); }
70 Attribute
* getAttributeItem(const QualifiedName
& name
) const;
71 Attribute
* getAttributeItem(const String
& name
, bool shouldIgnoreAttributeCase
) const;
73 void shrinkToLength() { m_attributes
.shrinkCapacity(length()); }
74 void reserveInitialCapacity(unsigned capacity
) { m_attributes
.reserveInitialCapacity(capacity
); }
76 // used during parsing: only inserts if not already there
78 void insertAttribute(PassRefPtr
<Attribute
> newAttribute
, bool allowDuplicates
)
81 if (allowDuplicates
|| !getAttributeItem(newAttribute
->name()))
82 addAttribute(newAttribute
);
85 virtual bool isMappedAttributeMap() const;
87 const AtomicString
& id() const { return m_id
; }
88 void setID(const AtomicString
& _id
) { m_id
= _id
; }
90 bool mapsEquivalent(const NamedAttrMap
* otherMap
) const;
92 // These functions are internal, and do no error checking.
93 void addAttribute(PassRefPtr
<Attribute
>);
94 void removeAttribute(const QualifiedName
& name
);
97 virtual void clearAttributes();
99 void detachFromElement();
102 Vector
<RefPtr
<Attribute
> > m_attributes
;