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

Side by Side Diff: net/base/address_list.h

Issue 2003973002: net::AddressList no longer privately inherits from std::vector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | net/base/address_list.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 NET_BASE_ADDRESS_LIST_H_ 5 #ifndef NET_BASE_ADDRESS_LIST_H_
6 #define NET_BASE_ADDRESS_LIST_H_ 6 #define NET_BASE_ADDRESS_LIST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "net/base/ip_endpoint.h" 14 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
16 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
17 17
18 struct addrinfo; 18 struct addrinfo;
19 19
20 namespace net { 20 namespace net {
21 21
22 class IPAddress; 22 class IPAddress;
23 23
24 class NET_EXPORT AddressList 24 class NET_EXPORT AddressList {
25 : NON_EXPORTED_BASE(private std::vector<IPEndPoint>) {
26 public: 25 public:
27 AddressList(); 26 AddressList();
27 AddressList(const AddressList&);
28 ~AddressList(); 28 ~AddressList();
29 29
30 // Creates an address list for a single IP literal. 30 // Creates an address list for a single IP literal.
31 explicit AddressList(const IPEndPoint& endpoint); 31 explicit AddressList(const IPEndPoint& endpoint);
32 32
33 static AddressList CreateFromIPAddress(const IPAddress& address, 33 static AddressList CreateFromIPAddress(const IPAddress& address,
34 uint16_t port); 34 uint16_t port);
35 35
36 static AddressList CreateFromIPAddressList( 36 static AddressList CreateFromIPAddressList(const IPAddressList& addresses,
37 const IPAddressList& addresses, 37 const std::string& canonical_name);
38 const std::string& canonical_name);
39 38
40 // Copies the data from |head| and the chained list into an AddressList. 39 // Copies the data from |head| and the chained list into an AddressList.
41 static AddressList CreateFromAddrinfo(const struct addrinfo* head); 40 static AddressList CreateFromAddrinfo(const struct addrinfo* head);
42 41
43 // Returns a copy of |list| with port on each element set to |port|. 42 // Returns a copy of |list| with port on each element set to |port|.
44 static AddressList CopyWithPort(const AddressList& list, uint16_t port); 43 static AddressList CopyWithPort(const AddressList& list, uint16_t port);
45 44
46 // TODO(szym): Remove all three. http://crbug.com/126134 45 // TODO(szym): Remove all three. http://crbug.com/126134
47 const std::string& canonical_name() const { 46 const std::string& canonical_name() const { return canonical_name_; }
48 return canonical_name_;
49 }
50 47
51 void set_canonical_name(const std::string& canonical_name) { 48 void set_canonical_name(const std::string& canonical_name) {
52 canonical_name_ = canonical_name; 49 canonical_name_ = canonical_name;
53 } 50 }
54 51
55 // Sets canonical name to the literal of the first IP address on the list. 52 // Sets canonical name to the literal of the first IP address on the list.
56 void SetDefaultCanonicalName(); 53 void SetDefaultCanonicalName();
57 54
58 // Creates a callback for use with the NetLog that returns a Value 55 // Creates a callback for use with the NetLog that returns a Value
59 // representation of the address list. The callback must be destroyed before 56 // representation of the address list. The callback must be destroyed before
60 // |this| is. 57 // |this| is.
61 NetLog::ParametersCallback CreateNetLogCallback() const; 58 NetLog::ParametersCallback CreateNetLogCallback() const;
62 59
63 // Exposed methods from std::vector. 60 using iterator = std::vector<IPEndPoint>::iterator;
64 using std::vector<IPEndPoint>::size; 61 using const_iterator = std::vector<IPEndPoint>::const_iterator;
65 using std::vector<IPEndPoint>::empty; 62
66 using std::vector<IPEndPoint>::clear; 63 size_t size() const { return endpoints_.size(); }
67 using std::vector<IPEndPoint>::reserve; 64 bool empty() const { return endpoints_.empty(); }
68 using std::vector<IPEndPoint>::capacity; 65 void clear() { endpoints_.clear(); }
69 using std::vector<IPEndPoint>::operator[]; 66 void reserve(size_t count) { endpoints_.reserve(count); }
70 using std::vector<IPEndPoint>::front; 67 size_t capacity() const { return endpoints_.capacity(); }
71 using std::vector<IPEndPoint>::back; 68 IPEndPoint& operator[](size_t index) { return endpoints_[index]; }
72 using std::vector<IPEndPoint>::push_back; 69 const IPEndPoint& operator[](size_t index) const { return endpoints_[index]; }
73 using std::vector<IPEndPoint>::insert; 70 IPEndPoint& front() { return endpoints_.front(); }
74 using std::vector<IPEndPoint>::erase; 71 const IPEndPoint& front() const { return endpoints_.front(); }
75 using std::vector<IPEndPoint>::iterator; 72 IPEndPoint& back() { return endpoints_.back(); }
76 using std::vector<IPEndPoint>::const_iterator; 73 const IPEndPoint& back() const { return endpoints_.back(); }
77 using std::vector<IPEndPoint>::begin; 74 void push_back(const IPEndPoint& val) { endpoints_.push_back(val); }
78 using std::vector<IPEndPoint>::end; 75
79 using std::vector<IPEndPoint>::rbegin; 76 template <typename InputIt>
80 using std::vector<IPEndPoint>::rend; 77 void insert(iterator pos, InputIt first, InputIt last) {
78 endpoints_.insert(pos, first, last);
79 }
80 iterator begin() { return endpoints_.begin(); }
81 const_iterator begin() const { return endpoints_.begin(); }
82 iterator end() { return endpoints_.end(); }
83 const_iterator end() const { return endpoints_.end(); }
81 84
82 private: 85 private:
86 std::vector<IPEndPoint> endpoints_;
83 // TODO(szym): Remove. http://crbug.com/126134 87 // TODO(szym): Remove. http://crbug.com/126134
84 std::string canonical_name_; 88 std::string canonical_name_;
85 }; 89 };
86 90
87 } // namespace net 91 } // namespace net
88 92
89 #endif // NET_BASE_ADDRESS_LIST_H_ 93 #endif // NET_BASE_ADDRESS_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/address_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698