xo-reflect: + pretty printing for xo::reflect::TypeDescr
This commit is contained in:
parent
afc4c58cf7
commit
1b185a3680
3 changed files with 48 additions and 9 deletions
|
|
@ -1,16 +1,16 @@
|
|||
/* GcStatistics.hpp
|
||||
/** @file GcStatistics.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
* @author Roland Conybeare, Aug 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "generation.hpp"
|
||||
#include "CircularBuffer.hpp"
|
||||
#include "xo/reflect/TypeDescr.hpp"
|
||||
#include "xo/unit/quantity.hpp"
|
||||
#include "xo/unit/quantity_iostream.hpp"
|
||||
#include "xo/indentlog/print/pretty.hpp"
|
||||
#include <xo/reflect/TypeDescr.hpp>
|
||||
#include <xo/unit/quantity.hpp>
|
||||
#include <xo/unit/quantity_iostream.hpp>
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
#include <ostream>
|
||||
#include <array>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "TypeDescrExtra.hpp"
|
||||
#include "xo/cxxutil/demangle.hpp"
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
#include <xo/cxxutil/demangle.hpp>
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include <unordered_map>
|
||||
|
|
@ -15,6 +16,8 @@
|
|||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace print { class ppindentinfo; }
|
||||
|
||||
namespace reflect {
|
||||
class TaggedPtr; /* see [reflect/TaggedPtr.hpp] */
|
||||
|
||||
|
|
@ -202,6 +205,9 @@ namespace xo {
|
|||
|
||||
/* run-time description for a native c++ type */
|
||||
class TypeDescrBase {
|
||||
public:
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
/* type-description objects for a type T is unique,
|
||||
* --> can always use its address
|
||||
|
|
@ -391,6 +397,9 @@ namespace xo {
|
|||
TypeDescr fn_arg(uint32_t i) const { return this->tdextra_->fn_arg(i); }
|
||||
bool fn_is_noexcept() const { return this->tdextra_->fn_is_noexcept(); }
|
||||
|
||||
/** pretty-printer support, using @p ppii **/
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
void display(std::ostream & os) const;
|
||||
std::string display_string() const;
|
||||
|
||||
|
|
@ -543,7 +552,6 @@ namespace xo {
|
|||
return os;
|
||||
}
|
||||
|
||||
|
||||
/* tag to drive overload resolution */
|
||||
struct reflected_types_printer {};
|
||||
|
||||
|
|
@ -567,6 +575,24 @@ namespace xo {
|
|||
static TypeDescrTable s_instance;
|
||||
};
|
||||
} /*namespace reflect*/
|
||||
|
||||
namespace print {
|
||||
template <>
|
||||
struct ppdetail<xo::reflect::TypeDescrBase> {
|
||||
static bool print_pretty(const ppindentinfo & ppii,
|
||||
const xo::reflect::TypeDescrBase & td) {
|
||||
return td.pretty(ppii);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ppdetail<xo::reflect::TypeDescr> {
|
||||
static bool print_pretty(const ppindentinfo & ppii,
|
||||
xo::reflect::TypeDescr td) {
|
||||
return td ? td->pretty(ppii) : true;
|
||||
}
|
||||
};
|
||||
} /*namespace print*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace std {
|
||||
|
|
|
|||
|
|
@ -301,6 +301,19 @@ namespace xo {
|
|||
return this->tdextra_->child_tp(i, object);
|
||||
} /*child_tp*/
|
||||
|
||||
bool
|
||||
TypeDescrBase::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"TypeDescr",
|
||||
refrtag("id", id_),
|
||||
refrtag("canonical_name", canonical_name_),
|
||||
refrtag("complete", complete_flag_),
|
||||
refrtag("metatype", this->metatype()));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
TypeDescrBase::display(std::ostream & os) const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue