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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/CollectionsSTL.h

Issue 1880833002: Move to protocol::Vector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved hash to a String16STL.h (not yet in this repo) Created 4 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/inspector_protocol/CollectionsWTF.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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CollectionsSTL_h 5 #ifndef CollectionsSTL_h
6 #define CollectionsSTL_h 6 #define CollectionsSTL_h
7 7
8 #include "wtf/Allocator.h" 8 #include "platform/inspector_protocol/String16.h"
9 #include "wtf/HashMap.h" 9 #include "wtf/OwnPtr.h"
10 #include "wtf/PassOwnPtr.h" 10 #include "wtf/PassOwnPtr.h"
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <unordered_map> 13 #include <unordered_map>
14 #include <vector> 14 #include <vector>
15 15
16 namespace std {
17 template<>
18 struct hash<String> {
19 std::size_t operator()(const String& k) const { return StringHash::hash(k); }
20 };
21 }
22 16
23 namespace blink { 17 namespace blink {
24 namespace protocol { 18 namespace protocol {
25 19
26 template <typename T> 20 template <typename T>
27 class Vector { 21 class Vector {
28 public: 22 public:
29 Vector() { } 23 Vector() { }
30 Vector(size_t capacity) : m_impl(capacity) { } 24 Vector(size_t capacity) : m_impl(capacity) { }
31 typedef typename std::vector<T>::iterator iterator; 25 typedef typename std::vector<T>::iterator iterator;
(...skipping 23 matching lines...) Expand all
55 private: 49 private:
56 std::vector<T> m_impl; 50 std::vector<T> m_impl;
57 }; 51 };
58 52
59 template <typename T> 53 template <typename T>
60 class Vector<OwnPtr<T>> { 54 class Vector<OwnPtr<T>> {
61 WTF_MAKE_NONCOPYABLE(Vector); 55 WTF_MAKE_NONCOPYABLE(Vector);
62 public: 56 public:
63 Vector() { } 57 Vector() { }
64 Vector(size_t capacity) : m_impl(capacity) { } 58 Vector(size_t capacity) : m_impl(capacity) { }
59 Vector(Vector&& other) : m_impl(std::move(other.m_impl)) { }
65 ~Vector() { } 60 ~Vector() { }
66 61
67 typedef typename std::vector<OwnPtr<T>>::iterator iterator; 62 typedef typename std::vector<OwnPtr<T>>::iterator iterator;
68 typedef typename std::vector<OwnPtr<T>>::const_iterator const_iterator; 63 typedef typename std::vector<OwnPtr<T>>::const_iterator const_iterator;
69 64
70 iterator begin() { return m_impl.begin(); } 65 iterator begin() { return m_impl.begin(); }
71 iterator end() { return m_impl.end(); } 66 iterator end() { return m_impl.end(); }
72 const_iterator begin() const { return m_impl.begin(); } 67 const_iterator begin() const { return m_impl.begin(); }
73 const_iterator end() const { return m_impl.end(); } 68 const_iterator end() const { return m_impl.end(); }
74 69
75 void resize(size_t s) { m_impl.resize(s); } 70 void resize(size_t s) { m_impl.resize(s); }
76 size_t size() const { return m_impl.size(); } 71 size_t size() const { return m_impl.size(); }
77 bool isEmpty() const { return !m_impl.size(); } 72 bool isEmpty() const { return !m_impl.size(); }
78 OwnPtr<T>& operator[](size_t i) { return at(i); } 73 OwnPtr<T>& operator[](size_t i) { return at(i); }
79 const OwnPtr<T>& operator[](size_t i) const { return at(i); } 74 const OwnPtr<T>& operator[](size_t i) const { return at(i); }
80 OwnPtr<T>& at(size_t i) { return m_impl[i]; } 75 OwnPtr<T>& at(size_t i) { return m_impl[i]; }
81 const OwnPtr<T>& at(size_t i) const { return m_impl.at(i); } 76 const OwnPtr<T>& at(size_t i) const { return m_impl.at(i); }
82 OwnPtr<T>& last() { return m_impl[m_impl.size() - 1]; } 77 OwnPtr<T>& last() { return m_impl[m_impl.size() - 1]; }
83 const OwnPtr<T>& last() const { return m_impl[m_impl.size() - 1]; } 78 const OwnPtr<T>& last() const { return m_impl[m_impl.size() - 1]; }
84 void append(const PassOwnPtr<T>& t) { m_impl.push_back(t); } 79 void append(const PassOwnPtr<T>& t) { m_impl.push_back(t); }
85 void prepend(const PassOwnPtr<T>& t) { m_impl.insert(m_impl.begin(), t); } 80 void prepend(const PassOwnPtr<T>& t) { m_impl.insert(m_impl.begin(), t); }
86 void remove(size_t i) { m_impl.erase(m_impl.begin() + i); } 81 void remove(size_t i) { m_impl.erase(m_impl.begin() + i); }
87 void clear() { m_impl.clear(); } 82 void clear() { m_impl.clear(); }
88 void swap(Vector& other) { m_impl.swap(other.m_impl); } 83 void swap(Vector& other) { m_impl.swap(other.m_impl); }
84 void swap(Vector&& other) { m_impl.swap(other.m_impl); }
89 void removeLast() { m_impl.pop_back(); } 85 void removeLast() { m_impl.pop_back(); }
90 86
91 private: 87 private:
92 std::vector<OwnPtr<T>> m_impl; 88 std::vector<OwnPtr<T>> m_impl;
93 }; 89 };
94 90
95 template <typename K, typename V, typename I> 91 template <typename K, typename V, typename I>
96 class HashMapIterator { 92 class HashMapIterator {
97 STACK_ALLOCATED(); 93 STACK_ALLOCATED();
98 public: 94 public:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 template <typename K> 209 template <typename K>
214 class HashSet : public protocol::HashMap<K, K> { 210 class HashSet : public protocol::HashMap<K, K> {
215 public: 211 public:
216 void add(const K& k) { this->set(k, k); } 212 void add(const K& k) { this->set(k, k); }
217 }; 213 };
218 214
219 } // namespace platform 215 } // namespace platform
220 } // namespace blink 216 } // namespace blink
221 217
222 #endif // !defined(CollectionsSTL_h) 218 #endif // !defined(CollectionsSTL_h)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/inspector_protocol/CollectionsWTF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698