Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: webrtc/base/copyonwritebuffer.h

Issue 1929903002: Define rtc::BufferT, like rtc::Buffer but for any trivial type (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/copyonwritebuffer.h
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h
index 87f24bf51d6db78aecc44442c810d0d0887d8dec..a7e52beea53c3ce442ac3b97a1db013590e08861 100644
--- a/webrtc/base/copyonwritebuffer.h
+++ b/webrtc/base/copyonwritebuffer.h
@@ -36,10 +36,14 @@ class CopyOnWriteBuffer {
// Construct a buffer and copy the specified number of bytes into it. The
// source array may be (const) uint8_t*, int8_t*, or char*.
- template <typename T, typename internal::ByteType<T>::t = 0>
+ template <typename T,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
CopyOnWriteBuffer(const T* data, size_t size)
: CopyOnWriteBuffer(data, size, size) {}
- template <typename T, typename internal::ByteType<T>::t = 0>
+ template <typename T,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
CopyOnWriteBuffer(const T* data, size_t size, size_t capacity)
: CopyOnWriteBuffer(size, capacity) {
if (buffer_) {
@@ -48,22 +52,29 @@ class CopyOnWriteBuffer {
}
// Construct a buffer from the contents of an array.
- template <typename T, size_t N, typename internal::ByteType<T>::t = 0>
- CopyOnWriteBuffer(const T(&array)[N]) // NOLINT: runtime/explicit
+ template <typename T,
+ size_t N,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
+ CopyOnWriteBuffer(const T (&array)[N]) // NOLINT: runtime/explicit
: CopyOnWriteBuffer(array, N) {}
~CopyOnWriteBuffer();
// Get a pointer to the data. Just .data() will give you a (const) uint8_t*,
// but you may also use .data<int8_t>() and .data<char>().
- template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
+ template <typename T = uint8_t,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
const T* data() const {
return cdata<T>();
}
// Get writable pointer to the data. This will create a copy of the underlying
// data if it is shared with other buffers.
- template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
+ template <typename T = uint8_t,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
T* data() {
RTC_DCHECK(IsConsistent());
if (!buffer_) {
@@ -75,7 +86,9 @@ class CopyOnWriteBuffer {
// Get const pointer to the data. This will not create a copy of the
// underlying data if it is shared with other buffers.
- template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
+ template <typename T = uint8_t,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
T* cdata() const {
RTC_DCHECK(IsConsistent());
if (!buffer_) {
@@ -137,7 +150,9 @@ class CopyOnWriteBuffer {
// Replace the contents of the buffer. Accepts the same types as the
// constructors.
- template <typename T, typename internal::ByteType<T>::t = 0>
+ template <typename T,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
void SetData(const T* data, size_t size) {
RTC_DCHECK(IsConsistent());
if (!buffer_ || !buffer_->HasOneRef()) {
@@ -149,8 +164,11 @@ class CopyOnWriteBuffer {
RTC_DCHECK(IsConsistent());
}
- template <typename T, size_t N, typename internal::ByteType<T>::t = 0>
- void SetData(const T(&array)[N]) {
+ template <typename T,
+ size_t N,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
+ void SetData(const T (&array)[N]) {
SetData(array, N);
}
@@ -163,7 +181,9 @@ class CopyOnWriteBuffer {
}
// Append data to the buffer. Accepts the same types as the constructors.
- template <typename T, typename internal::ByteType<T>::t = 0>
+ template <typename T,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
void AppendData(const T* data, size_t size) {
RTC_DCHECK(IsConsistent());
if (!buffer_) {
@@ -178,8 +198,11 @@ class CopyOnWriteBuffer {
RTC_DCHECK(IsConsistent());
}
- template <typename T, size_t N, typename internal::ByteType<T>::t = 0>
- void AppendData(const T(&array)[N]) {
+ template <typename T,
+ size_t N,
+ typename std::enable_if<
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
+ void AppendData(const T (&array)[N]) {
AppendData(array, N);
}

Powered by Google App Engine
This is Rietveld 408576698