aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkVptr.h
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-12-06 12:27:44 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-06 19:37:27 +0000
commit0554d497f80997658b5d0417897af4b818aae958 (patch)
tree3c183bffed5ab5e7df4775a40e961d2daabf0f0a /src/core/SkVptr.h
parentd34c4a37276c240733a6d17812653636dc3656b5 (diff)
add SkVptr()
I was wondering how feasible using this to make downcasts safe would be. These tests would need to build and pass on all our bots, at least. Change-Id: I1753ba58841bf6c17d6ac3af7374518356e1bb05 Reviewed-on: https://skia-review.googlesource.com/81180 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkVptr.h')
-rw-r--r--src/core/SkVptr.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/core/SkVptr.h b/src/core/SkVptr.h
new file mode 100644
index 0000000000..2a33ad06c7
--- /dev/null
+++ b/src/core/SkVptr.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkVptr_DEFINED
+#define SkVptr_DEFINED
+
+#include <string.h>
+#include <type_traits>
+
+// Experimentally, see if we can get at the vptr of objects with one.
+
+template <typename T>
+static inline void* SkVptr(const T& object) {
+ static_assert(std::has_virtual_destructor<T>::value, "");
+ void* vptr;
+ memcpy(&vptr, (const void*)&object, sizeof(vptr));
+ return vptr;
+}
+
+#endif//SkVptr_DEFINED