| 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 <algorithm> // std::swap (pre-C++11) | 14 #include <algorithm> // std::swap (pre-C++11) |
| 15 #include <cassert> | 15 #include <cassert> |
| 16 #include <cstring> | 16 #include <cstring> |
| 17 #include <utility> // std::swap (C++11 and later) | 17 #include <utility> // std::swap (C++11 and later) |
| 18 |
| 19 #include "webrtc/base/deprecation.h" |
| 18 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
| 19 | 21 |
| 20 namespace rtc { | 22 namespace rtc { |
| 21 | 23 |
| 22 namespace internal { | 24 namespace internal { |
| 23 | 25 |
| 24 // (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 |
| 25 // 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 |
| 26 // this: | 28 // this: |
| 27 // | 29 // |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (capacity <= capacity_) | 165 if (capacity <= capacity_) |
| 164 return; | 166 return; |
| 165 scoped_ptr<uint8_t[]> new_data(new uint8_t[capacity]); | 167 scoped_ptr<uint8_t[]> new_data(new uint8_t[capacity]); |
| 166 std::memcpy(new_data.get(), data_.get(), size_); | 168 std::memcpy(new_data.get(), data_.get(), size_); |
| 167 data_ = std::move(new_data); | 169 data_ = std::move(new_data); |
| 168 capacity_ = capacity; | 170 capacity_ = capacity; |
| 169 assert(IsConsistent()); | 171 assert(IsConsistent()); |
| 170 } | 172 } |
| 171 | 173 |
| 172 // b.Pass() does the same thing as std::move(b). | 174 // b.Pass() does the same thing as std::move(b). |
| 173 Buffer&& Pass() { | 175 // Deprecated; remove in March 2016 (bug 5373). |
| 176 RTC_DEPRECATED Buffer&& Pass() { return DEPRECATED_Pass(); } |
| 177 Buffer&& DEPRECATED_Pass() { |
| 174 assert(IsConsistent()); | 178 assert(IsConsistent()); |
| 175 return std::move(*this); | 179 return std::move(*this); |
| 176 } | 180 } |
| 177 | 181 |
| 178 // Resets the buffer to zero size and capacity. Works even if the buffer has | 182 // Resets the buffer to zero size and capacity. Works even if the buffer has |
| 179 // been moved from. | 183 // been moved from. |
| 180 void Clear() { | 184 void Clear() { |
| 181 data_.reset(); | 185 data_.reset(); |
| 182 size_ = 0; | 186 size_ = 0; |
| 183 capacity_ = 0; | 187 capacity_ = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 221 } |
| 218 | 222 |
| 219 size_t size_; | 223 size_t size_; |
| 220 size_t capacity_; | 224 size_t capacity_; |
| 221 scoped_ptr<uint8_t[]> data_; | 225 scoped_ptr<uint8_t[]> data_; |
| 222 }; | 226 }; |
| 223 | 227 |
| 224 } // namespace rtc | 228 } // namespace rtc |
| 225 | 229 |
| 226 #endif // WEBRTC_BASE_BUFFER_H_ | 230 #endif // WEBRTC_BASE_BUFFER_H_ |
| OLD | NEW |