| Index: Source/wtf/Ptr.h
|
| diff --git a/public/platform/WebData.h b/Source/wtf/Ptr.h
|
| similarity index 52%
|
| copy from public/platform/WebData.h
|
| copy to Source/wtf/Ptr.h
|
| index 0fc8ef18a0a2a9e0bdfaea5a59f0bb5272b0937c..1602421f45dd4eb76ca6b572f32ea3f22b3e796e 100644
|
| --- a/public/platform/WebData.h
|
| +++ b/Source/wtf/Ptr.h
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * Copyright (C) 2009 Google Inc. All rights reserved.
|
| + * Copyright (C) 2014 Google Inc. All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| * modification, are permitted provided that the following conditions are
|
| @@ -28,80 +28,71 @@
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| */
|
|
|
| -#ifndef WebData_h
|
| -#define WebData_h
|
| +#ifndef WTF_Ptr_h
|
| +#define WTF_Ptr_h
|
|
|
| -#include "WebCommon.h"
|
| -#include "WebPrivatePtr.h"
|
| +// Ptr is a simple wrapper for a raw pointer that provides the
|
| +// interface (get, clear) of other pointer types such as RefPtr,
|
| +// Persistent and Member. This is used for the Blink garbage
|
| +// collection work in order to be able to write shared code that will
|
| +// use reference counting or garbage collection based on a
|
| +// compile-time flag.
|
|
|
| -namespace WebCore { class SharedBuffer; }
|
| +namespace WTF {
|
|
|
| -namespace blink {
|
| -
|
| -class WebDataPrivate;
|
| -
|
| -// A container for raw bytes. It is inexpensive to copy a WebData object.
|
| -//
|
| -// WARNING: It is not safe to pass a WebData across threads!!!
|
| -//
|
| -class BLINK_PLATFORM_EXPORT WebData {
|
| +template<typename T>
|
| +class Ptr {
|
| public:
|
| - ~WebData() { reset(); }
|
| +#if ENABLE(OILPAN)
|
| + typedef Ptr<T> FromPassRefPtr;
|
| + typedef Ptr<T> FromRefPtr;
|
| + typedef Ptr<T> FromPassOwnPtr;
|
| +#else
|
| + typedef PassRefPtr<T> FromPassRefPtr;
|
| + typedef RefPtr<T> FromRefPtr;
|
| + typedef PassOwnPtr<T> FromPassOwnPtr;
|
| +#endif
|
|
|
| - WebData() { }
|
| + Ptr(T* ptr) : m_ptr(ptr) { }
|
| + Ptr(std::nullptr_t) : m_ptr(0) { }
|
|
|
| - WebData(const char* data, size_t size)
|
| + template<typename U>
|
| + Ptr(const Ptr<U>& other)
|
| + : m_ptr(other.get())
|
| {
|
| - assign(data, size);
|
| }
|
|
|
| - template <int N>
|
| - WebData(const char (&data)[N])
|
| - {
|
| - assign(data, N - 1);
|
| - }
|
| -
|
| - WebData(const WebData& d) { assign(d); }
|
| + T* get() const { return m_ptr; }
|
| + void clear() { m_ptr = 0; }
|
|
|
| - WebData& operator=(const WebData& d)
|
| + Ptr& operator=(T* ptr)
|
| {
|
| - assign(d);
|
| + m_ptr = ptr;
|
| return *this;
|
| }
|
|
|
| - void reset();
|
| - void assign(const WebData&);
|
| - void assign(const char* data, size_t size);
|
| -
|
| - size_t size() const;
|
| - const char* data() const;
|
| -
|
| - bool isEmpty() const { return !size(); }
|
| - bool isNull() const { return m_private.isNull(); }
|
| -
|
| -#if INSIDE_BLINK
|
| - WebData(const PassRefPtr<WebCore::SharedBuffer>&);
|
| - WebData& operator=(const PassRefPtr<WebCore::SharedBuffer>&);
|
| - operator PassRefPtr<WebCore::SharedBuffer>() const;
|
| -#else
|
| - template <class C>
|
| - WebData(const C& c)
|
| - {
|
| - assign(c.data(), c.size());
|
| - }
|
| -
|
| - template <class C>
|
| - WebData& operator=(const C& c)
|
| + Ptr& operator=(std::nullptr_t)
|
| {
|
| - assign(c.data(), c.size());
|
| + m_ptr = 0;
|
| return *this;
|
| }
|
| -#endif
|
| +
|
| + operator T*() const { return m_ptr; }
|
| + T& operator*() const { return *m_ptr; }
|
| + T* operator->() const { return m_ptr; }
|
| + bool operator!() const { return !m_ptr; }
|
| +
|
| + // This conversion operator allows implicit conversion to bool but
|
| + // not to other integer types.
|
| + typedef T* Ptr::*UnspecifiedBoolType;
|
| + operator UnspecifiedBoolType() const { return m_ptr ? &m_ptr : 0; }
|
|
|
| private:
|
| - WebPrivatePtr<WebCore::SharedBuffer> m_private;
|
| + T* m_ptr;
|
| };
|
|
|
| -} // namespace blink
|
| +} // namespace WTF
|
| +
|
| +using WTF::Ptr;
|
|
|
| #endif
|
|
|