mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-12-22 13:23:06 +00:00
TreeBuilder v2: Extend Element with a data member
This commit is contained in:
parent
c657a41d79
commit
7361d8fa29
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace oi::result {
|
namespace oi::result {
|
||||||
@ -31,6 +33,12 @@ struct Element {
|
|||||||
struct IsSetStats {
|
struct IsSetStats {
|
||||||
bool is_set;
|
bool is_set;
|
||||||
};
|
};
|
||||||
|
struct Pointer {
|
||||||
|
uintptr_t p;
|
||||||
|
};
|
||||||
|
struct Scalar {
|
||||||
|
uint64_t n;
|
||||||
|
};
|
||||||
|
|
||||||
std::string_view name;
|
std::string_view name;
|
||||||
std::vector<std::string_view>
|
std::vector<std::string_view>
|
||||||
@ -40,6 +48,8 @@ struct Element {
|
|||||||
size_t exclusive_size;
|
size_t exclusive_size;
|
||||||
|
|
||||||
std::optional<uintptr_t> pointer;
|
std::optional<uintptr_t> pointer;
|
||||||
|
std::variant<std::nullopt_t, Pointer, Scalar, std::string> data = {
|
||||||
|
std::nullopt};
|
||||||
std::optional<ContainerStats> container_stats;
|
std::optional<ContainerStats> container_stats;
|
||||||
std::optional<IsSetStats> is_set_stats;
|
std::optional<IsSetStats> is_set_stats;
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
template <class>
|
template <class>
|
||||||
inline constexpr bool always_false_v = false;
|
inline constexpr bool always_false_v = false;
|
||||||
@ -99,6 +100,18 @@ void Json::print(IntrospectionResult::const_iterator& it,
|
|||||||
out_ << tab << "\"pointer\":" << space << *(it->pointer) << ',' << endl
|
out_ << tab << "\"pointer\":" << space << *(it->pointer) << ',' << endl
|
||||||
<< indent;
|
<< indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto* s = std::get_if<result::Element::Scalar>(&it->data)) {
|
||||||
|
out_ << tab << "\"data\":" << space << s->n << ',' << endl << indent;
|
||||||
|
} else if (auto* p = std::get_if<result::Element::Pointer>(&it->data)) {
|
||||||
|
out_ << tab << "\"data\":" << space << "\"0x" << std::hex << p->p
|
||||||
|
<< std::dec << "\"," << endl
|
||||||
|
<< indent;
|
||||||
|
} else if (auto* str = std::get_if<std::string>(&it->data)) {
|
||||||
|
out_ << tab << "\"data\":" << space << "\"" << *str << "\"," << endl
|
||||||
|
<< indent;
|
||||||
|
}
|
||||||
|
|
||||||
if (it->container_stats.has_value()) {
|
if (it->container_stats.has_value()) {
|
||||||
out_ << tab << "\"length\":" << space << it->container_stats->length
|
out_ << tab << "\"length\":" << space << it->container_stats->length
|
||||||
<< ',' << endl
|
<< ',' << endl
|
||||||
|
Loading…
Reference in New Issue
Block a user