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) { |
| 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 Loading... |
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_ |
OLD | NEW |