From 7cf3938efb2788f23e396c9a7d137c75a117ae04 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 4 Apr 2019 12:32:42 -0700 Subject: [PATCH] Fabric: `getDebugDescription` implementation for `shared_ptr`, `weak_ptr` and `unique_ptr` Summary: Trivial. Reviewed By: mdvacca Differential Revision: D14715083 fbshipit-source-id: 92031cbbf166ea00569a6076d41575a9fd741043 --- .../fabric/debug/DebugStringConvertible.cpp | 3 +++ .../fabric/debug/DebugStringConvertible.h | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.cpp b/ReactCommon/fabric/debug/DebugStringConvertible.cpp index 951d5c27fe9..b8a2e30eea3 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.cpp +++ b/ReactCommon/fabric/debug/DebugStringConvertible.cpp @@ -142,6 +142,9 @@ std::string toString(double const &value) { return folly::to(value); } std::string toString(void const *value) { + if (value == nullptr) { + return "null"; + } return folly::sformat("0x{0:016x}", reinterpret_cast(value)); } diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.h b/ReactCommon/fabric/debug/DebugStringConvertible.h index 0337896116a..2767f92d2e9 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.h +++ b/ReactCommon/fabric/debug/DebugStringConvertible.h @@ -272,7 +272,7 @@ inline std::string getDebugDescription( // `void *` inline std::string getDebugDescription( - void const *pointer, + void *pointer, DebugStringConvertibleOptions options = {}) { return toString(pointer); } @@ -295,6 +295,30 @@ std::vector getDebugChildren(std::vector const &vector) { return vector; } +// `std::shared_ptr` +template +inline std::string getDebugDescription( + std::shared_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.get()) + "(shared)"; +} + +// `std::weak_ptr` +template +inline std::string getDebugDescription( + std::weak_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.lock().get()) + "(weak)"; +} + +// `std::unique_ptr` +template +inline std::string getDebugDescription( + std::unique_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.get()) + "(unique)"; +} + /* * Trivial container for `name` and `value` pair that supports * static `DebugStringConvertible` informal interface.