diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/GetPtr.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WTF/wtf/GetPtr.h')
-rw-r--r-- | Source/WTF/wtf/GetPtr.h | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/Source/WTF/wtf/GetPtr.h b/Source/WTF/wtf/GetPtr.h index 25a0e6d9b..78107cbe5 100644 --- a/Source/WTF/wtf/GetPtr.h +++ b/Source/WTF/wtf/GetPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Apple Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,12 +21,61 @@ #ifndef WTF_GetPtr_h #define WTF_GetPtr_h +#include <memory> + namespace WTF { - template <typename T> inline T* getPtr(T* p) - { - return p; - } +enum HashTableDeletedValueType { HashTableDeletedValue }; +enum HashTableEmptyValueType { HashTableEmptyValue }; + +template <typename T> inline T* getPtr(T* p) { return p; } + +template <typename T> struct IsSmartPtr { + static const bool value = false; +}; + +template <typename T, bool isSmartPtr> +struct GetPtrHelperBase; + +template <typename T> +struct GetPtrHelperBase<T, false /* isSmartPtr */> { + typedef T* PtrType; + static T* getPtr(T& p) { return std::addressof(p); } +}; + +template <typename T> +struct GetPtrHelperBase<T, true /* isSmartPtr */> { + typedef typename T::PtrType PtrType; + static PtrType getPtr(const T& p) { return p.get(); } +}; + +template <typename T> +struct GetPtrHelper : GetPtrHelperBase<T, IsSmartPtr<T>::value> { +}; + +template <typename T> +inline typename GetPtrHelper<T>::PtrType getPtr(T& p) +{ + return GetPtrHelper<T>::getPtr(p); +} + +template <typename T> +inline typename GetPtrHelper<T>::PtrType getPtr(const T& p) +{ + return GetPtrHelper<T>::getPtr(p); +} + +// Explicit specialization for C++ standard library types. + +template <typename T, typename Deleter> struct IsSmartPtr<std::unique_ptr<T, Deleter>> { + static const bool value = true; +}; + +template <typename T, typename Deleter> +struct GetPtrHelper<std::unique_ptr<T, Deleter>> { + typedef T* PtrType; + static T* getPtr(const std::unique_ptr<T, Deleter>& p) { return p.get(); } +}; } // namespace WTF |