jbauch | 13041cf | 2016-02-25 06:16:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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/copyonwritebuffer.h" |
| 12 | |
| 13 | namespace rtc { |
| 14 | |
| 15 | CopyOnWriteBuffer::CopyOnWriteBuffer() { |
| 16 | RTC_DCHECK(IsConsistent()); |
| 17 | } |
| 18 | |
| 19 | CopyOnWriteBuffer::CopyOnWriteBuffer(const CopyOnWriteBuffer& buf) |
| 20 | : buffer_(buf.buffer_) { |
| 21 | } |
| 22 | |
danilchap | d8a9c53 | 2016-07-30 12:39:26 -0700 | [diff] [blame^] | 23 | CopyOnWriteBuffer::CopyOnWriteBuffer(CopyOnWriteBuffer&& buf) |
| 24 | : buffer_(std::move(buf.buffer_)) { |
jbauch | 13041cf | 2016-02-25 06:16:52 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | CopyOnWriteBuffer::CopyOnWriteBuffer(size_t size) |
| 28 | : buffer_(size > 0 ? new RefCountedObject<Buffer>(size) : nullptr) { |
| 29 | RTC_DCHECK(IsConsistent()); |
| 30 | } |
| 31 | |
| 32 | CopyOnWriteBuffer::CopyOnWriteBuffer(size_t size, size_t capacity) |
| 33 | : buffer_(size > 0 || capacity > 0 |
| 34 | ? new RefCountedObject<Buffer>(size, capacity) |
| 35 | : nullptr) { |
| 36 | RTC_DCHECK(IsConsistent()); |
| 37 | } |
| 38 | |
| 39 | CopyOnWriteBuffer::~CopyOnWriteBuffer() = default; |
| 40 | |
| 41 | } // namespace rtc |