summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/GetPtr.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/GetPtr.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WTF/wtf/GetPtr.h')
-rw-r--r--Source/WTF/wtf/GetPtr.h59
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