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:
Родитель
0fb27a7633
Коммит
7cf3938efb
|
@ -142,6 +142,9 @@ std::string toString(double const &value) {
|
||||||
return folly::to<std::string>(value);
|
return folly::to<std::string>(value);
|
||||||
}
|
}
|
||||||
std::string toString(void const *value) {
|
std::string toString(void const *value) {
|
||||||
|
if (value == nullptr) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
return folly::sformat("0x{0:016x}", reinterpret_cast<size_t>(value));
|
return folly::sformat("0x{0:016x}", reinterpret_cast<size_t>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ inline std::string getDebugDescription(
|
||||||
|
|
||||||
// `void *`
|
// `void *`
|
||||||
inline std::string getDebugDescription(
|
inline std::string getDebugDescription(
|
||||||
void const *pointer,
|
void *pointer,
|
||||||
DebugStringConvertibleOptions options = {}) {
|
DebugStringConvertibleOptions options = {}) {
|
||||||
return toString(pointer);
|
return toString(pointer);
|
||||||
}
|
}
|
||||||
|
@ -295,6 +295,30 @@ std::vector<T> getDebugChildren(std::vector<T> const &vector) {
|
||||||
return 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
|
* Trivial container for `name` and `value` pair that supports
|
||||||
* static `DebugStringConvertible` informal interface.
|
* static `DebugStringConvertible` informal interface.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче