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 |
11 #ifndef WEBRTC_BASE_BUFFER_H_ | 11 #ifndef WEBRTC_BASE_BUFFER_H_ |
12 #define WEBRTC_BASE_BUFFER_H_ | 12 #define WEBRTC_BASE_BUFFER_H_ |
13 | 13 |
14 #include <cstring> | 14 #include <cstring> |
15 #include <memory> | 15 #include <memory> |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "webrtc/base/array_view.h" | 18 #include "webrtc/base/array_view.h" |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/deprecation.h" | |
22 | 21 |
23 namespace rtc { | 22 namespace rtc { |
24 | 23 |
25 namespace internal { | 24 namespace internal { |
26 | 25 |
27 // (Internal; please don't use outside this file.) ByteType<T>::t is int if T | 26 // (Internal; please don't use outside this file.) ByteType<T>::t is int if T |
28 // is uint8_t, int8_t, or char; otherwise, it's a compilation error. Use like | 27 // is uint8_t, int8_t, or char; otherwise, it's a compilation error. Use like |
29 // this: | 28 // this: |
30 // | 29 // |
31 // template <typename T, typename ByteType<T>::t = 0> | 30 // template <typename T, typename ByteType<T>::t = 0> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 RTC_DCHECK(IsConsistent()); | 221 RTC_DCHECK(IsConsistent()); |
223 if (capacity <= capacity_) | 222 if (capacity <= capacity_) |
224 return; | 223 return; |
225 std::unique_ptr<uint8_t[]> new_data(new uint8_t[capacity]); | 224 std::unique_ptr<uint8_t[]> new_data(new uint8_t[capacity]); |
226 std::memcpy(new_data.get(), data_.get(), size_); | 225 std::memcpy(new_data.get(), data_.get(), size_); |
227 data_ = std::move(new_data); | 226 data_ = std::move(new_data); |
228 capacity_ = capacity; | 227 capacity_ = capacity; |
229 RTC_DCHECK(IsConsistent()); | 228 RTC_DCHECK(IsConsistent()); |
230 } | 229 } |
231 | 230 |
232 // b.Pass() does the same thing as std::move(b). | |
233 // Deprecated; remove in March 2016 (bug 5373). | |
234 RTC_DEPRECATED Buffer&& Pass() { return DEPRECATED_Pass(); } | |
235 | |
236 Buffer&& DEPRECATED_Pass() { | |
237 RTC_DCHECK(IsConsistent()); | |
238 return std::move(*this); | |
239 } | |
240 | |
241 // Resets the buffer to zero size without altering capacity. Works even if the | 231 // Resets the buffer to zero size without altering capacity. Works even if the |
242 // buffer has been moved from. | 232 // buffer has been moved from. |
243 void Clear() { | 233 void Clear() { |
244 size_ = 0; | 234 size_ = 0; |
245 RTC_DCHECK(IsConsistent()); | 235 RTC_DCHECK(IsConsistent()); |
246 } | 236 } |
247 | 237 |
248 // Swaps two buffers. Also works for buffers that have been moved from. | 238 // Swaps two buffers. Also works for buffers that have been moved from. |
249 friend void swap(Buffer& a, Buffer& b) { | 239 friend void swap(Buffer& a, Buffer& b) { |
250 using std::swap; | 240 using std::swap; |
(...skipping 27 matching lines...) Expand all Loading... |
278 } | 268 } |
279 | 269 |
280 size_t size_; | 270 size_t size_; |
281 size_t capacity_; | 271 size_t capacity_; |
282 std::unique_ptr<uint8_t[]> data_; | 272 std::unique_ptr<uint8_t[]> data_; |
283 }; | 273 }; |
284 | 274 |
285 } // namespace rtc | 275 } // namespace rtc |
286 | 276 |
287 #endif // WEBRTC_BASE_BUFFER_H_ | 277 #endif // WEBRTC_BASE_BUFFER_H_ |
OLD | NEW |