20class remote_container_view;
29 bool print_value{
true};
31 microfmt::string_view kv_separator{
": "};
33 microfmt::string_view entry_separator{
", "};
35 microfmt::string_view open_bracket{
"{"};
37 microfmt::string_view close_bracket{
"}"};
52template <
typename IteratorState,
typename FormatterFn>
class RELOCO_OWNER
container_context {
60 : state_(initial_state), formatter_fn_(
formatter) {}
74 return self->formatter_fn_(self->state_, opts, space, scratch, out);
81 [[nodiscard]]
constexpr IteratorState &
state() &
noexcept RELOCO_LIFETIMEBOUND {
return state_; }
86 [[nodiscard]]
constexpr const IteratorState &
state() const & noexcept RELOCO_LIFETIMEBOUND {
return state_; }
88 [[nodiscard]]
constexpr const IteratorState &
state() const && = delete;
92 FormatterFn formatter_fn_;
108 : container_addr_(container_addr), context_(std::move(context)) {}
110 [[nodiscard]]
constexpr uintptr_t
container_address() const noexcept {
return container_addr_; }
112 [[nodiscard]]
constexpr value_ref<context_type>
context() &
noexcept RELOCO_LIFETIMEBOUND {
113 return value_ref<context_type>(context_);
116 [[nodiscard]]
constexpr value_ref<const context_type>
context() const & noexcept RELOCO_LIFETIMEBOUND {
117 return value_ref<const context_type>(context_);
120 value_ref<context_type>
context() && =
delete;
121 value_ref<const context_type>
context() const && = delete;
124 span<std::
byte> scratch RELOCO_LIFETIMEBOUND,
132 return Dispatcher::format(value_ref<const context_type>(self.context_), self.container_addr_, opts, space, scratch,
137 uintptr_t container_addr_;
138 context_type context_;
150template <
typename IteratorState,
typename FormatterFn>
181 template <typename Context>
183 span<std::
byte> scratch RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS,
184 value_ref<Context> ctx RELOCO_LIFETIME_CAPTURE_BY_THIS,
186 : container_addr_(container_addr), space_(space), scratch_(scratch), ctx_(ctx.pointer()),
187 format_fn_(&Context::format_thunk), options_(options) {}
193 [[nodiscard]]
constexpr uintptr_t
container_address() const noexcept {
return container_addr_; }
203 [[nodiscard]]
constexpr span<std::byte>
scratch() const noexcept RELOCO_LIFETIMEBOUND {
return scratch_; }
214 [[nodiscard]] constexpr
bool is_null() const noexcept {
return container_addr_ == 0 || !ctx_; }
223 if (format_fn_ ==
nullptr || !ctx_)
225 return format_fn_(ctx_.get(), space_, scratch_, out, options_);
232 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return !is_null(); }
235 uintptr_t container_addr_{0};
236 address_space_ref space_{};
237 span<std::byte> scratch_{};
238 value_ptr<void> ctx_{};
240 container_options options_;
243template <
typename Tag,
typename Dispatcher>
244[[nodiscard]]
constexpr remote_container_view
247 return remote_container_view(container_addr_, space, scratch, value_ref<basic_remote_container>(*
this), options);
260 if (view.is_null()) {
264 if (!view.format(out)) {
265 out.write(
"<fault>");
Type-erased remote address-space access and remote string/object views.
Type-erased, two-word handle to a remote address space.
Definition address_space.hpp:204
Owning typed container bound to a compile-time traits dispatcher.
Definition remote_container.hpp:102
typename traits_type::context_type context_type
Definition remote_container.hpp:105
value_ref< context_type > context() &&=delete
remote_container_view view(address_space_ref, span< std::byte >, container_options={}) &&=delete
constexpr basic_remote_container(uintptr_t container_addr, context_type context) noexcept
Definition remote_container.hpp:107
constexpr value_ref< const context_type > context() const &noexcept RELOCO_LIFETIMEBOUND
Definition remote_container.hpp:116
constexpr uintptr_t container_address() const noexcept
Definition remote_container.hpp:110
constexpr value_ref< context_type > context() &noexcept RELOCO_LIFETIMEBOUND
Definition remote_container.hpp:112
value_ref< const context_type > context() const &&=delete
static bool format_thunk(void *raw_ctx, address_space_ref space, span< std::byte > scratch, const sink &out, const container_options &opts) noexcept
Definition remote_container.hpp:129
typename Dispatcher::traits_type traits_type
Definition remote_container.hpp:104
External context holder capturing container state and traversal/formatting logic.
Definition remote_container.hpp:52
static bool format_thunk(void *raw_ctx, address_space_ref space, span< std::byte > scratch, const sink &out, const container_options &opts) noexcept
Invokes the stored formatter through the type-erased view API.
Definition remote_container.hpp:71
constexpr container_context(IteratorState initial_state, FormatterFn formatter) noexcept
Stores container traversal state and its formatting callback.
Definition remote_container.hpp:59
constexpr const IteratorState & state() const &noexcept RELOCO_LIFETIMEBOUND
Returns the traversal state.
Definition remote_container.hpp:86
constexpr const IteratorState & state() const &&=delete
constexpr IteratorState & state() &noexcept RELOCO_LIFETIMEBOUND
Returns the mutable traversal state.
Definition remote_container.hpp:81
Definition microfmt.hpp:881
General type-erased view over any remote container or data structure. Manages its own formatting opti...
Definition remote_container.hpp:159
constexpr span< std::byte > scratch() const noexcept RELOCO_LIFETIMEBOUND
Returns the reusable scratch storage.
Definition remote_container.hpp:203
constexpr address_space_ref space() const noexcept
Returns the address space.
Definition remote_container.hpp:198
constexpr uintptr_t container_address() const noexcept
Returns the remote container address.
Definition remote_container.hpp:193
constexpr remote_container_view() noexcept=default
Constructs an empty, invalid view.
bool(*)(void *ctx, address_space_ref space, span< std::byte > scratch, const sink &out, const container_options &opts) noexcept format_fn_t
Type-erased function signature used to format a container.
Definition remote_container.hpp:165
bool format(const sink &out) const noexcept
Formats the remote container through its bound context.
Definition remote_container.hpp:222
constexpr const container_options & options() const &noexcept RELOCO_LIFETIMEBOUND
Returns the rendering configuration.
Definition remote_container.hpp:208
const container_options & options() const &&=delete
#define MICROFMT_API_CLASS
Definition compat.hpp:181
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
void(*)(const void *val_ptr, microfmt::string_view spec, const sink &out) noexcept format_fn_t
Definition microfmt.hpp:1348
constexpr auto make_container_context(IteratorState initial_state, FormatterFn formatter) noexcept
Creates an external context for a remote container view.
Definition remote_container.hpp:151
Configuration options for formatting container views.
Definition remote_container.hpp:25