2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-25 18:08:40 -07:00
|
|
|
// This entire file is deprecated, and will be removed in XXXX 2016. Use
|
|
|
|
|
// std::unique_ptr instead!
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
#ifndef WEBRTC_BASE_SCOPED_PTR_H__
|
|
|
|
|
#define WEBRTC_BASE_SCOPED_PTR_H__
|
|
|
|
|
|
2016-04-25 18:08:40 -07:00
|
|
|
// All these #includes are left to maximize backwards compatibility.
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2015-01-29 09:12:47 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdlib.h>
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2016-04-25 18:08:40 -07:00
|
|
|
#include <algorithm>
|
2015-12-17 06:20:27 -08:00
|
|
|
#include <cstddef>
|
2016-02-17 10:04:18 -08:00
|
|
|
#include <memory>
|
2015-01-26 13:03:32 +00:00
|
|
|
|
2015-01-29 09:12:47 +00:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
|
|
|
|
#include "webrtc/base/template_util.h"
|
|
|
|
|
#include "webrtc/typedefs.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
2016-04-25 18:08:40 -07:00
|
|
|
template <typename T, typename Deleter = std::default_delete<T>>
|
|
|
|
|
using scoped_ptr = std::unique_ptr<T, Deleter>;
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2016-04-25 18:08:40 -07:00
|
|
|
// These used to convert between rtc::scoped_ptr and std::unique_ptr. Now they
|
|
|
|
|
// are no-ops.
|
2016-02-17 10:04:18 -08:00
|
|
|
template <typename T>
|
2016-04-25 18:08:40 -07:00
|
|
|
std::unique_ptr<T> ScopedToUnique(std::unique_ptr<T> up) {
|
|
|
|
|
return up;
|
2016-02-17 10:04:18 -08:00
|
|
|
}
|
|
|
|
|
template <typename T>
|
2016-04-25 18:08:40 -07:00
|
|
|
std::unique_ptr<T> UniqueToScoped(std::unique_ptr<T> up) {
|
|
|
|
|
return up;
|
2016-02-17 10:04:18 -08:00
|
|
|
}
|
|
|
|
|
|
rtc::Buffer improvements
1. Constructors, SetData(), and AppendData() now accept uint8_t*,
int8_t*, and char*. Previously, they accepted void*, meaning that
any kind of pointer was accepted. I think requiring an explicit
cast in cases where the input array isn't already of a byte-sized
type is a better compromise between convenience and safety.
2. data() can now return a uint8_t* instead of a char*, which seems
more appropriate for a byte array, and is harder to mix up with
zero-terminated C strings. data<int8_t>() is also available so
that callers that want that type instead won't have to cast, as
is data<char>() (which remains the default until all existing
callers have been fixed).
3. Constructors, SetData(), and AppendData() now accept arrays
natively, not just decayed to pointers. The advantage of this is
that callers don't have to pass the size separately.
4. There are new constructors that allow setting size and capacity
without initializing the array. Previously, this had to be done
separately after construction.
5. Instead of TransferTo(), Buffer now supports swap(), and move
construction and assignment, and has a Pass() method that works
just like std::move(). (The Pass method is modeled after
scoped_ptr::Pass().)
R=jmarusic@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/42989004
Cr-Commit-Position: refs/heads/master@{#9033}
2015-04-20 14:03:07 +02:00
|
|
|
} // namespace rtc
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
#endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__
|