microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
microfmt::address_space_ref Class Reference

Type-erased, two-word handle to a remote address space. More...

#include <address_space.hpp>

Classes

struct  vtable
 Virtual table of address-space operations. More...
 

Public Member Functions

constexpr address_space_ref () noexcept=default
 Constructs an empty (invalid) handle.
 
template<typename Tag , typename Traits = address_space_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
constexpr address_space_ref (Tag) noexcept
 Constructs a handle for a stateless address-space tag.
 
template<typename Tag , typename Context , typename Traits = address_space_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type > &&std::is_convertible_v< const Context *, const typename Traits::context_type * >, int > = 0>
constexpr address_space_ref (Tag, const Context &ctx RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS) noexcept
 Constructs a handle for a stateful address-space tag.
 
template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
constexpr address_space_ref (Tag, Context &&)=delete
 
expected< void, address_space_error > read_bytes (uintptr_t addr, void *dest, size_t size) const noexcept
 Reads raw bytes from the remote address space.
 
template<typename T >
expected< void, address_space_error > read (uintptr_t addr, T &out_obj) const noexcept
 Reads a trivially-copyable object from the remote address space.
 
template<typename T >
expected< T, address_space_error > read (uintptr_t addr) const noexcept
 Reads and returns a trivially-copyable object.
 
expected< void, address_space_error > write_bytes (uintptr_t addr, const void *src, size_t size) const noexcept
 Writes raw bytes into the remote address space.
 
template<typename T >
expected< void, address_space_error > write (uintptr_t addr, const T &object) const noexcept
 Writes a trivially-copyable object into the remote address space.
 
expected< string_chunk, address_space_error > read_string_chunk (uintptr_t addr, span< char > buffer) const noexcept
 Reads a bounded chunk of a remote NUL-terminated string.
 
constexpr operator bool () const noexcept
 Reports whether the handle is bound to an address space.
 
constexpr bool can_write () const noexcept
 Reports whether the bound backend provides write access.
 

Static Public Member Functions

template<typename Tag , typename Traits = address_space_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
static constexpr address_space_ref make () noexcept
 Creates a handle for a stateless address-space tag.
 
template<typename Tag , typename Context , typename Traits = address_space_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type >, int > = 0>
static constexpr address_space_ref make (const Context &ctx RELOCO_LIFETIMEBOUND) noexcept
 Creates a handle for a stateful address-space tag.
 
template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
static address_space_ref make (Context &&)=delete
 

Detailed Description

Type-erased, two-word handle to a remote address space.

Packs a context pointer and a virtual table into two words, avoiding allocations, RTTI, and virtual dispatch.

Constructor & Destructor Documentation

◆ address_space_ref() [1/4]

constexpr microfmt::address_space_ref::address_space_ref ( )
constexprdefaultnoexcept

Constructs an empty (invalid) handle.

◆ address_space_ref() [2/4]

template<typename Tag , typename Traits = address_space_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
constexpr microfmt::address_space_ref::address_space_ref ( Tag  )
inlineexplicitconstexprnoexcept

Constructs a handle for a stateless address-space tag.

Template Parameters
TagAddress-space tag type.
TraitsSpecialized traits, enabled when context_type is void.

◆ address_space_ref() [3/4]

template<typename Tag , typename Context , typename Traits = address_space_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type > &&std::is_convertible_v< const Context *, const typename Traits::context_type * >, int > = 0>
constexpr microfmt::address_space_ref::address_space_ref ( Tag  ,
const Context &ctx RELOCO_LIFETIMEBOUND  RELOCO_LIFETIME_CAPTURE_BY_THIS 
)
inlineconstexprnoexcept

Constructs a handle for a stateful address-space tag.

Template Parameters
TagAddress-space tag type.
ContextConcrete context type.
TraitsSpecialized traits, enabled when context_type is non-void and Context converts to it.
Parameters
ctxContext object providing the reads.

◆ address_space_ref() [4/4]

template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
constexpr microfmt::address_space_ref::address_space_ref ( Tag  ,
Context &&   
)
constexprdelete

Member Function Documentation

◆ can_write()

constexpr bool microfmt::address_space_ref::can_write ( ) const
inlineconstexprnoexcept

Reports whether the bound backend provides write access.

◆ make() [1/3]

template<typename Tag , typename Traits = address_space_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
static constexpr address_space_ref microfmt::address_space_ref::make ( )
inlinestaticconstexprnoexcept

Creates a handle for a stateless address-space tag.

Template Parameters
TagAddress-space tag type.
TraitsSpecialized traits, enabled when context_type is void.
Returns
An address_space_ref for the tag.

◆ make() [2/3]

template<typename Tag , typename Context , typename Traits = address_space_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type >, int > = 0>
static constexpr address_space_ref microfmt::address_space_ref::make ( const Context &ctx  RELOCO_LIFETIMEBOUND)
inlinestaticconstexprnoexcept

Creates a handle for a stateful address-space tag.

Template Parameters
TagAddress-space tag type.
ContextConcrete context type.
TraitsSpecialized traits, enabled when context_type is non-void.
Parameters
ctxContext object providing the reads.
Returns
An address_space_ref bound to ctx.

◆ make() [3/3]

template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
static address_space_ref microfmt::address_space_ref::make ( Context &&  )
staticdelete

◆ operator bool()

constexpr microfmt::address_space_ref::operator bool ( ) const
inlineexplicitconstexprnoexcept

Reports whether the handle is bound to an address space.

Returns
true when the handle is valid.

◆ read() [1/2]

template<typename T >
expected< T, address_space_error > microfmt::address_space_ref::read ( uintptr_t  addr) const
inlinenoexcept

Reads and returns a trivially-copyable object.

Template Parameters
TObject type (must be trivially copyable, nothrow default constructible, and nothrow move constructible).
Parameters
addrAbsolute address of the object.
Returns
The loaded object or the address-space error.

◆ read() [2/2]

template<typename T >
expected< void, address_space_error > microfmt::address_space_ref::read ( uintptr_t  addr,
T &  out_obj 
) const
inlinenoexcept

Reads a trivially-copyable object from the remote address space.

Template Parameters
TObject type (must be trivially copyable).
Parameters
addrAbsolute address of the object.
out_objReceives the loaded object.
Returns
Success or the address-space error.

◆ read_bytes()

expected< void, address_space_error > microfmt::address_space_ref::read_bytes ( uintptr_t  addr,
void *  dest,
size_t  size 
) const
inlinenoexcept

Reads raw bytes from the remote address space.

Parameters
addrAbsolute source address.
destDestination buffer.
sizeNumber of bytes to read.
Returns
Success, or an error identifying an invalid handle/address or a backend read failure.

◆ read_string_chunk()

expected< string_chunk, address_space_error > microfmt::address_space_ref::read_string_chunk ( uintptr_t  addr,
span< char >  buffer 
) const
inlinenoexcept

Reads a bounded chunk of a remote NUL-terminated string.

Parameters
addrAbsolute source address.
bufferScratch buffer receiving the chunk.
Returns
Chunk metadata or an error identifying an invalid handle/address, empty buffer, or backend read failure.

◆ write()

template<typename T >
expected< void, address_space_error > microfmt::address_space_ref::write ( uintptr_t  addr,
const T &  object 
) const
inlinenoexcept

Writes a trivially-copyable object into the remote address space.

Template Parameters
TObject type (must be trivially copyable).
Parameters
addrAbsolute destination address.
objectObject whose representation is written.
Returns
Success or the address-space error.

◆ write_bytes()

expected< void, address_space_error > microfmt::address_space_ref::write_bytes ( uintptr_t  addr,
const void *  src,
size_t  size 
) const
inlinenoexcept

Writes raw bytes into the remote address space.

Parameters
addrAbsolute destination address.
srcSource buffer.
sizeNumber of bytes to write.
Returns
Success, or an error identifying invalid input, an unsupported write operation, or a backend write failure.

The documentation for this class was generated from the following file: