kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/base/buffer.h" |
| 12 | |
ossu | b01c781 | 2016-02-24 01:05:56 -0800 | [diff] [blame] | 13 | #include <algorithm> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 14 | #include <utility> |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 15 | |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 16 | namespace rtc { |
| 17 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 18 | Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) { |
kwiberg | e3d9922 | 2016-03-01 01:57:38 -0800 | [diff] [blame^] | 19 | RTC_DCHECK(IsConsistent()); |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 22 | Buffer::Buffer(const Buffer& buf) : Buffer(buf.data(), buf.size()) { |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 25 | Buffer::Buffer(Buffer&& buf) |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 26 | : size_(buf.size()), |
| 27 | capacity_(buf.capacity()), |
| 28 | data_(std::move(buf.data_)) { |
kwiberg | e3d9922 | 2016-03-01 01:57:38 -0800 | [diff] [blame^] | 29 | RTC_DCHECK(IsConsistent()); |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 30 | buf.OnMovedFrom(); |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 33 | Buffer::Buffer(size_t size) : Buffer(size, size) { |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 36 | Buffer::Buffer(size_t size, size_t capacity) |
| 37 | : size_(size), |
| 38 | capacity_(std::max(size, capacity)), |
| 39 | data_(new uint8_t[capacity_]) { |
kwiberg | e3d9922 | 2016-03-01 01:57:38 -0800 | [diff] [blame^] | 40 | RTC_DCHECK(IsConsistent()); |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 43 | // Note: The destructor works even if the buffer has been moved from. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 44 | Buffer::~Buffer() = default; |
| 45 | |
| 46 | }; // namespace rtc |