Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: Source/core/dom/AttributeCollection.h

Issue 674553002: Move parts of core/dom to C++11 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make Windows shut up when I just try following the style guide Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/dom/ContainerNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved. 3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 4 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 24 matching lines...) Expand all
35 35
36 #include "core/dom/Attr.h" 36 #include "core/dom/Attr.h"
37 #include "core/dom/Attribute.h" 37 #include "core/dom/Attribute.h"
38 #include "wtf/Vector.h" 38 #include "wtf/Vector.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 template <typename Container, typename ContainerMemberType = Container> 42 template <typename Container, typename ContainerMemberType = Container>
43 class AttributeCollectionGeneric { 43 class AttributeCollectionGeneric {
44 public: 44 public:
45 typedef typename Container::ValueType ValueType; 45 using ValueType = typename Container::ValueType;
46 typedef ValueType* iterator; 46 using iterator = ValueType*;
47 47
48 AttributeCollectionGeneric(Container& attributes) 48 AttributeCollectionGeneric(Container& attributes)
49 : m_attributes(attributes) 49 : m_attributes(attributes)
50 { } 50 { }
51 51
52 ValueType& operator[](unsigned index) const { return at(index); } 52 ValueType& operator[](unsigned index) const { return at(index); }
53 ValueType& at(unsigned index) const 53 ValueType& at(unsigned index) const
54 { 54 {
55 RELEASE_ASSERT(index < size()); 55 RELEASE_ASSERT(index < size());
56 return begin()[index]; 56 return begin()[index];
(...skipping 12 matching lines...) Expand all
69 size_t findIndex(Attr*) const; 69 size_t findIndex(Attr*) const;
70 70
71 protected: 71 protected:
72 size_t findSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase ) const; 72 size_t findSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase ) const;
73 73
74 ContainerMemberType m_attributes; 74 ContainerMemberType m_attributes;
75 }; 75 };
76 76
77 class AttributeArray { 77 class AttributeArray {
78 public: 78 public:
79 typedef const Attribute ValueType; 79 using ValueType = const Attribute;
80 80
81 AttributeArray(const Attribute* array, unsigned size) 81 AttributeArray(const Attribute* array, unsigned size)
82 : m_array(array) 82 : m_array(array)
83 , m_size(size) 83 , m_size(size)
84 { } 84 { }
85 85
86 const Attribute* data() const { return m_array; } 86 const Attribute* data() const { return m_array; }
87 unsigned size() const { return m_size; } 87 unsigned size() const { return m_size; }
88 88
89 private: 89 private:
90 const Attribute* m_array; 90 const Attribute* m_array;
91 unsigned m_size; 91 unsigned m_size;
92 }; 92 };
93 93
94 class AttributeCollection : public AttributeCollectionGeneric<const AttributeArr ay> { 94 class AttributeCollection : public AttributeCollectionGeneric<const AttributeArr ay> {
95 public: 95 public:
96 AttributeCollection() 96 AttributeCollection()
97 : AttributeCollectionGeneric<const AttributeArray>(AttributeArray(nullpt r, 0)) 97 : AttributeCollectionGeneric<const AttributeArray>(AttributeArray(nullpt r, 0))
98 { } 98 { }
99 99
100 AttributeCollection(const Attribute* array, unsigned size) 100 AttributeCollection(const Attribute* array, unsigned size)
101 : AttributeCollectionGeneric<const AttributeArray>(AttributeArray(array, size)) 101 : AttributeCollectionGeneric<const AttributeArray>(AttributeArray(array, size))
102 { } 102 { }
103 }; 103 };
104 104
105 typedef Vector<Attribute, 4> AttributeVector; 105 using AttributeVector = Vector<Attribute, 4>;
106 class MutableAttributeCollection : public AttributeCollectionGeneric<AttributeVe ctor, AttributeVector&> { 106 class MutableAttributeCollection : public AttributeCollectionGeneric<AttributeVe ctor, AttributeVector&> {
107 public: 107 public:
108 explicit MutableAttributeCollection(AttributeVector& attributes) 108 explicit MutableAttributeCollection(AttributeVector& attributes)
109 : AttributeCollectionGeneric<AttributeVector, AttributeVector&>(attribut es) 109 : AttributeCollectionGeneric<AttributeVector, AttributeVector&>(attribut es)
110 { } 110 { }
111 111
112 // These functions do no error/duplicate checking. 112 // These functions do no error/duplicate checking.
113 void append(const QualifiedName&, const AtomicString& value); 113 void append(const QualifiedName&, const AtomicString& value);
114 void remove(unsigned index); 114 void remove(unsigned index);
115 }; 115 };
116 116
117 inline void MutableAttributeCollection::append(const QualifiedName& name, const AtomicString& value) 117 inline void MutableAttributeCollection::append(const QualifiedName& name, const AtomicString& value)
118 { 118 {
119 m_attributes.append(Attribute(name, value)); 119 m_attributes.append(Attribute(name, value));
120 } 120 }
121 121
122 inline void MutableAttributeCollection::remove(unsigned index) 122 inline void MutableAttributeCollection::remove(unsigned index)
123 { 123 {
124 m_attributes.remove(index); 124 m_attributes.remove(index);
125 } 125 }
126 126
127 template <typename Container, typename ContainerMemberType> 127 template <typename Container, typename ContainerMemberType>
128 inline typename AttributeCollectionGeneric<Container, ContainerMemberType>::iter ator AttributeCollectionGeneric<Container, ContainerMemberType>::find(const Atom icString& name, bool shouldIgnoreCase) const 128 inline typename AttributeCollectionGeneric<Container, ContainerMemberType>::iter ator AttributeCollectionGeneric<Container, ContainerMemberType>::find(const Atom icString& name, bool shouldIgnoreCase) const
129 { 129 {
130 size_t index = findIndex(name, shouldIgnoreCase); 130 size_t index = findIndex(name, shouldIgnoreCase);
131 return index != kNotFound ? &at(index) : 0; 131 return index != kNotFound ? &at(index) : nullptr;
132 } 132 }
133 133
134 template <typename Container, typename ContainerMemberType> 134 template <typename Container, typename ContainerMemberType>
135 inline size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findIn dex(const QualifiedName& name, bool shouldIgnoreCase) const 135 inline size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findIn dex(const QualifiedName& name, bool shouldIgnoreCase) const
136 { 136 {
137 iterator end = this->end(); 137 iterator end = this->end();
138 unsigned index = 0; 138 unsigned index = 0;
139 for (iterator it = begin(); it != end; ++it, ++index) { 139 for (iterator it = begin(); it != end; ++it, ++index) {
140 if (it->name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase)) 140 if (it->name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase))
141 return index; 141 return index;
(...skipping 28 matching lines...) Expand all
170 } 170 }
171 171
172 template <typename Container, typename ContainerMemberType> 172 template <typename Container, typename ContainerMemberType>
173 inline typename AttributeCollectionGeneric<Container, ContainerMemberType>::iter ator AttributeCollectionGeneric<Container, ContainerMemberType>::find(const Qual ifiedName& name) const 173 inline typename AttributeCollectionGeneric<Container, ContainerMemberType>::iter ator AttributeCollectionGeneric<Container, ContainerMemberType>::find(const Qual ifiedName& name) const
174 { 174 {
175 iterator end = this->end(); 175 iterator end = this->end();
176 for (iterator it = begin(); it != end; ++it) { 176 for (iterator it = begin(); it != end; ++it) {
177 if (it->name().matches(name)) 177 if (it->name().matches(name))
178 return it; 178 return it;
179 } 179 }
180 return 0; 180 return nullptr;
181 } 181 }
182 182
183 template <typename Container, typename ContainerMemberType> 183 template <typename Container, typename ContainerMemberType>
184 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findIndex(Att r* attr) const 184 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findIndex(Att r* attr) const
185 { 185 {
186 // This relies on the fact that Attr's QualifiedName == the Attribute's name . 186 // This relies on the fact that Attr's QualifiedName == the Attribute's name .
187 iterator end = this->end(); 187 iterator end = this->end();
188 unsigned index = 0; 188 unsigned index = 0;
189 for (iterator it = begin(); it != end; ++it, ++index) { 189 for (iterator it = begin(); it != end; ++it, ++index) {
190 if (it->name() == attr->qualifiedName()) 190 if (it->name() == attr->qualifiedName())
(...skipping 21 matching lines...) Expand all
212 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn oreAttributeCase)) 212 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn oreAttributeCase))
213 return index; 213 return index;
214 } 214 }
215 } 215 }
216 return kNotFound; 216 return kNotFound;
217 } 217 }
218 218
219 } // namespace blink 219 } // namespace blink
220 220
221 #endif // AttributeCollection_h 221 #endif // AttributeCollection_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/ContainerNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698