From 011c00f708f1bdcbecf6c941343e090f378f09a6 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Mon, 20 Apr 2015 22:55:33 +0200 Subject: [PATCH] rtc::Buffer: Accept void* in addition to the byte-sized types We used to accept void* (until 9478437f), and we'll have to continue to do so for a little while longer, until Chromium doesn't need it anymore. TBR=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48179004 Cr-Commit-Position: refs/heads/master@{#9035} --- webrtc/base/buffer.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/webrtc/base/buffer.h b/webrtc/base/buffer.h index 5880f50c94..8959b40d88 100644 --- a/webrtc/base/buffer.h +++ b/webrtc/base/buffer.h @@ -40,6 +40,20 @@ struct ByteType { using t = decltype(F(static_cast(nullptr))); }; +// Deprecated: Accept void* in addition to the byte-sized types. +// TODO(kwiberg): Remove once Chromium doesn't need this anymore. +template +struct ByteTypeOrVoid { + private: + static int F(uint8_t*); + static int F(int8_t*); + static int F(char*); + static int F(void*); + + public: + using t = decltype(F(static_cast(nullptr))); +}; + } // namespace internal // Basic buffer class, can be grown and shrunk dynamically. @@ -56,10 +70,10 @@ class Buffer final { // 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 ::t = 0> + template ::t = 0> Buffer(const T* data, size_t size) : Buffer(data, size, size) {} - template ::t = 0> + template ::t = 0> Buffer(const T* data, size_t size, size_t capacity) : Buffer(size, capacity) { std::memcpy(data_.get(), data, size); @@ -119,7 +133,7 @@ class Buffer final { // Replace the contents of the buffer. Accepts the same types as the // constructors. - template ::t = 0> + template ::t = 0> void SetData(const T* data, size_t size) { assert(IsConsistent()); size_ = 0; @@ -132,7 +146,7 @@ class Buffer final { void SetData(const Buffer& buf) { SetData(buf.data(), buf.size()); } // Append data to the buffer. Accepts the same types as the constructors. - template ::t = 0> + template ::t = 0> void AppendData(const T* data, size_t size) { assert(IsConsistent()); const size_t new_size = size_ + size;