Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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_ |
| OLD | NEW |