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

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: Added DCHECKs for index against size_ 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) {
128 RTC_DCHECK_LT(index, size_);
129 return data()[index];
130 }
131
132 uint8_t operator[](size_t index) const {
133 RTC_DCHECK_LT(index, size_);
134 return data()[index];
135 }
136
127 // The SetData functions replace the contents of the buffer. They accept the 137 // The SetData functions replace the contents of the buffer. They accept the
128 // same input types as the constructors. 138 // same input types as the constructors.
129 template <typename T, typename internal::ByteType<T>::t = 0> 139 template <typename T, typename internal::ByteType<T>::t = 0>
130 void SetData(const T* data, size_t size) { 140 void SetData(const T* data, size_t size) {
131 assert(IsConsistent()); 141 assert(IsConsistent());
132 size_ = 0; 142 size_ = 0;
133 AppendData(data, size); 143 AppendData(data, size);
134 } 144 }
135 145
136 template <typename T, size_t N, typename internal::ByteType<T>::t = 0> 146 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 } 279 }
270 280
271 size_t size_; 281 size_t size_;
272 size_t capacity_; 282 size_t capacity_;
273 std::unique_ptr<uint8_t[]> data_; 283 std::unique_ptr<uint8_t[]> data_;
274 }; 284 };
275 285
276 } // namespace rtc 286 } // namespace rtc
277 287
278 #endif // WEBRTC_BASE_BUFFER_H_ 288 #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