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: webrtc/base/buffer.h

Issue 1745033002: Added an operator[] to Buffer, to make reading data easier. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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 | webrtc/base/buffer_unittest.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return *this; 117 return *this;
118 } 118 }
119 119
120 bool operator==(const Buffer& buf) const { 120 bool operator==(const Buffer& buf) const {
121 assert(IsConsistent()); 121 assert(IsConsistent());
122 return size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0; 122 return size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0;
123 } 123 }
124 124
125 bool operator!=(const Buffer& buf) const { return !(*this == buf); } 125 bool operator!=(const Buffer& buf) const { return !(*this == buf); }
126 126
127 uint8_t& operator[](size_t index) { return data()[index]; }
128 uint8_t operator[](size_t index) const { return data()[index]; }
kwiberg-webrtc 2016/02/29 12:40:46 It's probably a good idea to DCHECK that the index
ossu 2016/02/29 12:48:53 Acknowledged.
129
127 // The SetData functions replace the contents of the buffer. They accept the 130 // The SetData functions replace the contents of the buffer. They accept the
128 // same input types as the constructors. 131 // same input types as the constructors.
129 template <typename T, typename internal::ByteType<T>::t = 0> 132 template <typename T, typename internal::ByteType<T>::t = 0>
130 void SetData(const T* data, size_t size) { 133 void SetData(const T* data, size_t size) {
131 assert(IsConsistent()); 134 assert(IsConsistent());
132 size_ = 0; 135 size_ = 0;
133 AppendData(data, size); 136 AppendData(data, size);
134 } 137 }
135 138
136 template <typename T, size_t N, typename internal::ByteType<T>::t = 0> 139 template <typename T, size_t N, typename internal::ByteType<T>::t = 0>
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 272 }
270 273
271 size_t size_; 274 size_t size_;
272 size_t capacity_; 275 size_t capacity_;
273 std::unique_ptr<uint8_t[]> data_; 276 std::unique_ptr<uint8_t[]> data_;
274 }; 277 };
275 278
276 } // namespace rtc 279 } // namespace rtc
277 280
278 #endif // WEBRTC_BASE_BUFFER_H_ 281 #endif // WEBRTC_BASE_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698