diff --git a/xo-refcnt/CMakeLists.txt b/xo-refcnt/CMakeLists.txt index 4ef7c6c4..d5e487ed 100644 --- a/xo-refcnt/CMakeLists.txt +++ b/xo-refcnt/CMakeLists.txt @@ -13,7 +13,7 @@ xo_cxx_toplevel_options3() # c++ settings 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! add_definitions(${PROJECT_CXX_FLAGS}) diff --git a/xo-refcnt/include/xo/refcnt/Refcounted.hpp b/xo-refcnt/include/xo/refcnt/Refcounted.hpp index 13feed3d..732acb0b 100644 --- a/xo-refcnt/include/xo/refcnt/Refcounted.hpp +++ b/xo-refcnt/include/xo/refcnt/Refcounted.hpp @@ -230,7 +230,7 @@ namespace xo { template inline std::ostream & operator<<(std::ostream & os, intrusive_ptr const & x) { - if(x.get()) { + if (x.get()) { os << *(x.get()); } else { os << "() << ">"; diff --git a/xo-refcnt/include/xo/refcnt/pretty_refcnt.hpp b/xo-refcnt/include/xo/refcnt/pretty_refcnt.hpp new file mode 100644 index 00000000..ecf53aba --- /dev/null +++ b/xo-refcnt/include/xo/refcnt/pretty_refcnt.hpp @@ -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 { + static bool print_upto(ppstate * pps, const xo::ref::Refcount * x) { + return ppdetail_atomic::print_upto(pps, x); + } + static void print_pretty(ppstate * pps, const xo::ref::Refcount * x) { + ppdetail_atomic::print_pretty(pps, x); + } + }; + + template + struct ppdetail> { + static bool print_upto(ppstate * pps, const rp & x) { + if (auto p = x.get()) { + return ppdetail::print_upto(pps, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + pps->write("write(reflect::type_name()); + pps->write(">"); + + return pps->has_margin(); + } + } + + static void print_pretty(ppstate * pps, const rp & x) { + if (auto p = x.get()) { + ppdetail::print_pretty(pps, *p); + } else { + pps->write("write(reflect::type_name()); + pps->write(">"); + } + } + }; + + template + struct ppdetail> { + static bool print_upto(ppstate * pps, const bp & x) { + if (auto p = x.get()) { + return ppdetail::print_upto(pps, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + pps->write("write(reflect::type_name()); + pps->write(">"); + + return pps->has_margin(); + } + } + + static void print_pretty(ppstate * pps, const bp & x) { + if (auto p = x.get()) { + ppdetail::print_pretty(pps, *p); + } else { + pps->write("write(reflect::type_name()); + pps->write(">"); + } + } + }; + } +} diff --git a/xo-refcnt/src/Refcounted.cpp b/xo-refcnt/src/Refcounted.cpp index 38accc85..f08d9c62 100644 --- a/xo-refcnt/src/Refcounted.cpp +++ b/xo-refcnt/src/Refcounted.cpp @@ -1,6 +1,7 @@ /* @file Refcounted.cpp */ #include "Refcounted.hpp" +#include "pretty_refcnt.hpp" namespace xo { namespace ref {