xo-refcnt: + pretty_refcnt.hpp

This commit is contained in:
Roland Conybeare 2025-07-13 21:19:13 -05:00
commit 232c6d7b22
4 changed files with 80 additions and 2 deletions

View file

@ -13,7 +13,7 @@ xo_cxx_toplevel_options3()
# c++ settings # c++ settings
set(XO_PROJECT_NAME refcnt) # is this used? set(XO_PROJECT_NAME refcnt) # is this used?
set(PROJECT_CXX_FLAGS "") set(PROJECT_CXX_FLAGS "-ftemplate-backtrace-limit=0")
#set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") # gcc-only! #set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") # gcc-only!
add_definitions(${PROJECT_CXX_FLAGS}) add_definitions(${PROJECT_CXX_FLAGS})

View file

@ -230,7 +230,7 @@ namespace xo {
template<typename T> template<typename T>
inline std::ostream & inline std::ostream &
operator<<(std::ostream & os, intrusive_ptr<T> const & x) { operator<<(std::ostream & os, intrusive_ptr<T> const & x) {
if(x.get()) { if (x.get()) {
os << *(x.get()); os << *(x.get());
} else { } else {
os << "<nullptr " << reflect::type_name<T>() << ">"; os << "<nullptr " << reflect::type_name<T>() << ">";

View file

@ -0,0 +1,77 @@
/* @file pretty_refcnt.hpp
*
* author: Roland Conybeare, Jul 2025
*/
#pragma once
#include "Refcounted.hpp"
#include "xo/indentlog/print/pretty.hpp"
namespace xo {
namespace print {
template <>
struct ppdetail<xo::ref::Refcount *> {
static bool print_upto(ppstate * pps, const xo::ref::Refcount * x) {
return ppdetail_atomic<const xo::ref::Refcount *>::print_upto(pps, x);
}
static void print_pretty(ppstate * pps, const xo::ref::Refcount * x) {
ppdetail_atomic<const xo::ref::Refcount *>::print_pretty(pps, x);
}
};
template <typename T>
struct ppdetail<rp<T>> {
static bool print_upto(ppstate * pps, const rp<T> & x) {
if (auto p = x.get()) {
return ppdetail<T>::print_upto(pps, *p);
} else {
/* note: degenerate case here, since never write newline for nullptr */
pps->write("<nullptr ");
pps->write(reflect::type_name<T>());
pps->write(">");
return pps->has_margin();
}
}
static void print_pretty(ppstate * pps, const rp<T> & x) {
if (auto p = x.get()) {
ppdetail<T>::print_pretty(pps, *p);
} else {
pps->write("<nullptr ");
pps->write(reflect::type_name<T>());
pps->write(">");
}
}
};
template <typename T>
struct ppdetail<bp<T>> {
static bool print_upto(ppstate * pps, const bp<T> & x) {
if (auto p = x.get()) {
return ppdetail<T>::print_upto(pps, *p);
} else {
/* note: degenerate case here, since never write newline for nullptr */
pps->write("<nullptr ");
pps->write(reflect::type_name<T>());
pps->write(">");
return pps->has_margin();
}
}
static void print_pretty(ppstate * pps, const bp<T> & x) {
if (auto p = x.get()) {
ppdetail<T>::print_pretty(pps, *p);
} else {
pps->write("<nullptr ");
pps->write(reflect::type_name<T>());
pps->write(">");
}
}
};
}
}

View file

@ -1,6 +1,7 @@
/* @file Refcounted.cpp */ /* @file Refcounted.cpp */
#include "Refcounted.hpp" #include "Refcounted.hpp"
#include "pretty_refcnt.hpp"
namespace xo { namespace xo {
namespace ref { namespace ref {