Fabric: getDebugDescription implementation for shared_ptr, weak_ptr and unique_ptr

Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D14715083

fbshipit-source-id: 92031cbbf166ea00569a6076d41575a9fd741043
This commit is contained in:
Valentin Shergin
2019-04-04 12:32:42 -07:00
committed by Facebook Github Bot
parent 0fb27a7633
commit 7cf3938efb
2 changed files with 28 additions and 1 deletions

View File

@@ -142,6 +142,9 @@ std::string toString(double const &value) {
return folly::to<std::string>(value);
}
std::string toString(void const *value) {
if (value == nullptr) {
return "null";
}
return folly::sformat("0x{0:016x}", reinterpret_cast<size_t>(value));
}

View File

@@ -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<T> getDebugChildren(std::vector<T> const &vector) {
return vector;
}
// `std::shared_ptr<T>`
template <typename T>
inline std::string getDebugDescription(
std::shared_ptr<T> const &pointer,
DebugStringConvertibleOptions options = {}) {
return getDebugDescription((void *)pointer.get()) + "(shared)";
}
// `std::weak_ptr<T>`
template <typename T>
inline std::string getDebugDescription(
std::weak_ptr<T> const &pointer,
DebugStringConvertibleOptions options = {}) {
return getDebugDescription((void *)pointer.lock().get()) + "(weak)";
}
// `std::unique_ptr<T>`
template <typename T>
inline std::string getDebugDescription(
std::unique_ptr<T const> const &pointer,
DebugStringConvertibleOptions options = {}) {
return getDebugDescription((void *)pointer.get()) + "(unique)";
}
/*
* Trivial container for `name` and `value` pair that supports
* static `DebugStringConvertible` informal interface.