OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef DocumentOrderedMap_h | 31 #ifndef DocumentOrderedMap_h |
32 #define DocumentOrderedMap_h | 32 #define DocumentOrderedMap_h |
33 | 33 |
34 #include "wtf/HashCountedSet.h" | 34 #include "wtf/HashCountedSet.h" |
35 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 36 #include "wtf/Vector.h" |
36 #include "wtf/text/StringImpl.h" | 37 #include "wtf/text/StringImpl.h" |
37 | 38 |
38 namespace WebCore { | 39 namespace WebCore { |
39 | 40 |
40 class Element; | 41 class Element; |
41 class TreeScope; | 42 class TreeScope; |
42 | 43 |
43 class DocumentOrderedMap { | 44 class DocumentOrderedMap { |
44 public: | 45 public: |
45 void add(StringImpl*, Element*); | 46 void add(StringImpl*, Element*); |
46 void remove(StringImpl*, Element*); | 47 void remove(StringImpl*, Element*); |
47 void clear(); | 48 void clear(); |
48 | 49 |
49 bool contains(StringImpl*) const; | 50 bool contains(StringImpl*) const; |
50 bool containsMultiple(StringImpl*) const; | 51 bool containsMultiple(StringImpl*) const; |
51 // concrete instantiations of the get<>() method template | 52 // concrete instantiations of the get<>() method template |
52 Element* getElementById(StringImpl*, const TreeScope*) const; | 53 Element* getElementById(StringImpl*, const TreeScope*) const; |
| 54 const Vector<Element*>& getAllElementsById(StringImpl*, const TreeScope*) co
nst; |
53 Element* getElementByMapName(StringImpl*, const TreeScope*) const; | 55 Element* getElementByMapName(StringImpl*, const TreeScope*) const; |
54 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; | 56 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; |
55 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; | 57 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; |
56 | 58 |
57 void checkConsistency() const; | 59 void checkConsistency() const; |
58 | 60 |
59 private: | 61 private: |
60 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c
onst TreeScope*) const; | 62 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c
onst TreeScope*) const; |
61 | 63 |
62 struct MapEntry { | 64 struct MapEntry { |
63 MapEntry() | 65 MapEntry() |
64 : element(0) | 66 : element(0) |
65 , count(0) | 67 , count(0) |
66 { } | 68 { } |
67 | 69 |
68 explicit MapEntry(Element* firstElement) | 70 explicit MapEntry(Element* firstElement) |
69 : element(firstElement) | 71 : element(firstElement) |
70 , count(1) | 72 , count(1) |
71 { } | 73 { } |
72 | 74 |
73 Element* element; | 75 Element* element; |
74 unsigned count; | 76 unsigned count; |
| 77 Vector<Element*> orderedList; |
75 }; | 78 }; |
76 | 79 |
77 typedef HashMap<StringImpl*, MapEntry> Map; | 80 typedef HashMap<StringImpl*, MapEntry> Map; |
78 | 81 |
79 mutable Map m_map; | 82 mutable Map m_map; |
80 }; | 83 }; |
81 | 84 |
82 inline bool DocumentOrderedMap::contains(StringImpl* id) const | 85 inline bool DocumentOrderedMap::contains(StringImpl* id) const |
83 { | 86 { |
84 return m_map.contains(id); | 87 return m_map.contains(id); |
85 } | 88 } |
86 | 89 |
87 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const | 90 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const |
88 { | 91 { |
89 Map::const_iterator it = m_map.find(id); | 92 Map::const_iterator it = m_map.find(id); |
90 return it != m_map.end() && it->value.count > 1; | 93 return it != m_map.end() && it->value.count > 1; |
91 } | 94 } |
92 | 95 |
93 } // namespace WebCore | 96 } // namespace WebCore |
94 | 97 |
95 #endif // DocumentOrderedMap_h | 98 #endif // DocumentOrderedMap_h |
OLD | NEW |