Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
trace::FormattingOptions Struct Reference

Configuration and formatting options for a trace module. More...

#include <trace_impl.hpp>

Collaboration diagram for trace::FormattingOptions:
[legend]

Classes

struct  ColorOptionTraits
 Enables/disables/auto color for this module (from UNI20_COLOR or programmatic override). More...
 
struct  ThreadIdOptionTraits
 Controls thread-id prefixing (from UNI20_TRACE_THREAD_ID or module override). More...
 

Public Types

using ColorOptions = NamedEnumeration< ColorOptionTraits >
 
using Sink = std::function< void(std::string)>
 
using ThreadIdOptions = NamedEnumeration< ThreadIdOptionTraits >
 

Public Member Functions

void append_glyph (uni20::presentation::styled_text &text, uni20::presentation::semantic_glyph glyph, std::string const &kind) const
 Append a styled semantic glyph without rendering it immediately.
 
void append_style (uni20::presentation::styled_text &text, std::string_view str, std::string const &kind) const
 Append styled text without rendering it immediately.
 
std::string format_glyph (uni20::presentation::semantic_glyph glyph, std::string const &kind) const
 Format a semantic glyph using this module's style for the given kind.
 
std::string format_style (const std::string &str, const std::string &kind) const
 Get or compute the terminal style for a given kind in this module.
 
 FormattingOptions ()
 Default constructor.
 
 FormattingOptions (std::string_view module)
 Module‐specific constructor.
 
uni20::presentation::mdspan_format_options & mdspan_format_policy ()
 Return the shared mdspan/tensor presentation policy used by this trace module.
 
uni20::presentation::mdspan_format_options const & mdspan_format_policy () const
 Return the shared mdspan/tensor presentation policy used by this trace module.
 
uni20::presentation::mdspan_preview_options & mdspan_preview_policy ()
 Return the shared mdspan/tensor preview policy used by this trace module.
 
uni20::presentation::mdspan_preview_options const & mdspan_preview_policy () const
 Return the shared mdspan/tensor preview policy used by this trace module.
 
uni20::presentation::numeric_format_options numeric_format_policy () const
 Build numeric formatting controls from trace precision settings.
 
uni20::presentation::output_policy & presentation_policy ()
 Return the shared presentation output policy used by this trace module.
 
uni20::presentation::output_policy const & presentation_policy () const
 Return the shared presentation output policy used by this trace module.
 
terminal::TerminalStyle presentation_style (std::string_view kind) const
 Return the terminal style associated with a trace style-map key.
 
std::string render (uni20::presentation::styled_text const &text) const
 Render a presentation document through this trace module's policy.
 
void set_color_output (ColorOptions c)
 Enable or disable color output for this module.
 
void set_color_output (uni20::presentation::color_mode c)
 Enable, disable, or auto-detect color output using the shared presentation color mode.
 
void set_output_stream (FILE *f)
 Change the output FILE* for this module.
 
void set_sink (Sink s)
 Set a custom sink function for this module.
 
bool should_show_color () const
 Query whether color should be used in this module.
 

Static Public Member Functions

static bool errors_abort ()
 Query the abort-on-error setting.
 
static void set_errors_abort (bool b)
 Enable or disable abort-on-error for this module.
 

Public Attributes

ColorOptions color
 
int fp_precision_float128 = 36
 Floating-point precision for formatting configured float128 values.
 
int fp_precision_float32 = 6
 Floating-point precision for formatting float32 values.
 
int fp_precision_float64 = 15
 Floating-point precision for formatting float64 values.
 
uni20::presentation::mdspan_format_options mdspanFormatPolicy
 Presentation tensor-art policy used for mdspan and tensor-like values.
 
uni20::presentation::mdspan_preview_options mdspanPreviewPolicy
 Presentation preview policy used for mdspan and tensor-like trace values.
 
FILE * outputStream = stderr
 File to which this module writes (stderr by default, or UNI20_TRACEFILE).
 
uni20::presentation::output_policy renderPolicy = uni20::presentation::terminal_policy(outputStream)
 Shared presentation rendering policy used by trace formatting.
 
bool showColor = terminal::is_a_terminal(stderr)
 Whether to actually emit color sequences.
 
Sink sink
 Function that actually emits strings (defaults to fputs to stderr).
 
std::map< std::string, terminal::TerminalStyle > Styles
 Holds per-kind styles (keys like "TRACE", "TRACE_LINE", etc).
 
int terminal_width = terminal::columns(stderr)
 Maximum width (in characters) before switching to multi-line.
 
ThreadIdOptions threadId = ThreadIdOptions()
 
bool timestamp = false
 Prefix each trace with a timestamp (from UNI20_TRACE_TIMESTAMP or module override).
 

Static Public Attributes

static bool errorsAbort = true
 Abort on error if true. This is static, since it only makes sense globally.
 

Friends

FormattingOptions & get_formatting_options (const std::string &module)
 get the FormattingOptions object for a given module; use "" as the module name (or default parameter) for the global format
 

Detailed Description

Configuration and formatting options for a trace module.

Member Typedef Documentation

◆ ColorOptions

◆ Sink

using trace::FormattingOptions::Sink = std::function<void(std::string)>

◆ ThreadIdOptions

Constructor & Destructor Documentation

◆ FormattingOptions() [1/2]

trace::FormattingOptions::FormattingOptions ( )
inline

Default constructor.

Seeds all built-in style keys and reads the global trace environment.

◆ FormattingOptions() [2/2]

trace::FormattingOptions::FormattingOptions ( std::string_view  module)
inline

Module‐specific constructor.

Delegates to the default ctor then applies only trace module overrides:

  • UNI20_TRACEFILE_MODULE_<MODULE>
  • UNI20_TRACE_TIMESTAMP_MODULE_<MODULE>
  • UNI20_TRACE_THREAD_ID_MODULE_<MODULE>

Member Function Documentation

◆ append_glyph()

void trace::FormattingOptions::append_glyph ( uni20::presentation::styled_text &  text,
uni20::presentation::semantic_glyph  glyph,
std::string const &  kind 
) const
inline

Append a styled semantic glyph without rendering it immediately.

Parameters
textPresentation document to append to.
glyphSemantic presentation glyph.
kindStyle-map key to apply.

◆ append_style()

void trace::FormattingOptions::append_style ( uni20::presentation::styled_text &  text,
std::string_view  str,
std::string const &  kind 
) const
inline

Append styled text without rendering it immediately.

Parameters
textPresentation document to append to.
strText payload.
kindStyle-map key to apply.

◆ errors_abort()

static bool trace::FormattingOptions::errors_abort ( )
inlinestatic

Query the abort-on-error setting.

◆ format_glyph()

std::string trace::FormattingOptions::format_glyph ( uni20::presentation::semantic_glyph  glyph,
std::string const &  kind 
) const
inline

Format a semantic glyph using this module's style for the given kind.

Parameters
glyphSemantic presentation glyph.
kindStyle-map key to apply.
Returns
Rendered glyph string.

◆ format_style()

std::string trace::FormattingOptions::format_style ( const std::string &  str,
const std::string &  kind 
) const
inline

Get or compute the terminal style for a given kind in this module.

Format text using the "global" style (no module) for the given kind.

◆ mdspan_format_policy() [1/2]

uni20::presentation::mdspan_format_options & trace::FormattingOptions::mdspan_format_policy ( )
inline

Return the shared mdspan/tensor presentation policy used by this trace module.

Returns
Mutable mdspan formatting policy.

◆ mdspan_format_policy() [2/2]

uni20::presentation::mdspan_format_options const & trace::FormattingOptions::mdspan_format_policy ( ) const
inline

Return the shared mdspan/tensor presentation policy used by this trace module.

Returns
Immutable mdspan formatting policy.

◆ mdspan_preview_policy() [1/2]

uni20::presentation::mdspan_preview_options & trace::FormattingOptions::mdspan_preview_policy ( )
inline

Return the shared mdspan/tensor preview policy used by this trace module.

Returns
Mutable mdspan preview policy.

◆ mdspan_preview_policy() [2/2]

uni20::presentation::mdspan_preview_options const & trace::FormattingOptions::mdspan_preview_policy ( ) const
inline

Return the shared mdspan/tensor preview policy used by this trace module.

Returns
Immutable mdspan preview policy.

◆ numeric_format_policy()

uni20::presentation::numeric_format_options trace::FormattingOptions::numeric_format_policy ( ) const
inline

Build numeric formatting controls from trace precision settings.

Returns
Numeric presentation options preserving trace fixed-point behavior.

◆ presentation_policy() [1/2]

uni20::presentation::output_policy & trace::FormattingOptions::presentation_policy ( )
inline

Return the shared presentation output policy used by this trace module.

Returns
Mutable presentation policy.

◆ presentation_policy() [2/2]

uni20::presentation::output_policy const & trace::FormattingOptions::presentation_policy ( ) const
inline

Return the shared presentation output policy used by this trace module.

Returns
Immutable presentation policy.

◆ presentation_style()

terminal::TerminalStyle trace::FormattingOptions::presentation_style ( std::string_view  kind) const
inline

Return the terminal style associated with a trace style-map key.

Parameters
kindStyle-map key such as TRACE or TRACE_LINE.
Returns
Configured style, or an empty style when the key is unknown.

◆ render()

std::string trace::FormattingOptions::render ( uni20::presentation::styled_text const &  text) const
inline

Render a presentation document through this trace module's policy.

Parameters
textPresentation document to render.
Returns
Rendered string.

◆ set_color_output() [1/2]

void trace::FormattingOptions::set_color_output ( ColorOptions  c)
inline

Enable or disable color output for this module.

◆ set_color_output() [2/2]

void trace::FormattingOptions::set_color_output ( uni20::presentation::color_mode  c)
inline

Enable, disable, or auto-detect color output using the shared presentation color mode.

◆ set_errors_abort()

static void trace::FormattingOptions::set_errors_abort ( bool  b)
inlinestatic

Enable or disable abort-on-error for this module.

◆ set_output_stream()

void trace::FormattingOptions::set_output_stream ( FILE *  f)
inline

Change the output FILE* for this module.

◆ set_sink()

void trace::FormattingOptions::set_sink ( Sink  s)
inline

Set a custom sink function for this module.

◆ should_show_color()

bool trace::FormattingOptions::should_show_color ( ) const
inline

Query whether color should be used in this module.

Friends And Related Symbol Documentation

◆ get_formatting_options

FormattingOptions & get_formatting_options ( const std::string &  module)
friend

get the FormattingOptions object for a given module; use "" as the module name (or default parameter) for the global format

Returns the FormattingOptions for a module, or the “default” when called with no args.

Empty module name ⇒ use the no-arg ctor (global defaults only).

Member Data Documentation

◆ color

ColorOptions trace::FormattingOptions::color

◆ errorsAbort

bool trace::FormattingOptions::errorsAbort = true
inlinestatic

Abort on error if true. This is static, since it only makes sense globally.

◆ fp_precision_float128

int trace::FormattingOptions::fp_precision_float128 = 36

Floating-point precision for formatting configured float128 values.

◆ fp_precision_float32

int trace::FormattingOptions::fp_precision_float32 = 6

Floating-point precision for formatting float32 values.

◆ fp_precision_float64

int trace::FormattingOptions::fp_precision_float64 = 15

Floating-point precision for formatting float64 values.

◆ mdspanFormatPolicy

uni20::presentation::mdspan_format_options trace::FormattingOptions::mdspanFormatPolicy

Presentation tensor-art policy used for mdspan and tensor-like values.

◆ mdspanPreviewPolicy

uni20::presentation::mdspan_preview_options trace::FormattingOptions::mdspanPreviewPolicy

Presentation preview policy used for mdspan and tensor-like trace values.

◆ outputStream

FILE* trace::FormattingOptions::outputStream = stderr

File to which this module writes (stderr by default, or UNI20_TRACEFILE).

◆ renderPolicy

Shared presentation rendering policy used by trace formatting.

◆ showColor

bool trace::FormattingOptions::showColor = terminal::is_a_terminal(stderr)

Whether to actually emit color sequences.

◆ sink

Sink trace::FormattingOptions::sink
Initial value:
= [](std::string s) {
std::fputs(s.c_str(), stderr);
std::fflush(stderr);
}

Function that actually emits strings (defaults to fputs to stderr).

◆ Styles

std::map<std::string, terminal::TerminalStyle> trace::FormattingOptions::Styles
mutable

Holds per-kind styles (keys like "TRACE", "TRACE_LINE", etc).

◆ terminal_width

int trace::FormattingOptions::terminal_width = terminal::columns(stderr)

Maximum width (in characters) before switching to multi-line.

◆ threadId

ThreadIdOptions trace::FormattingOptions::threadId = ThreadIdOptions()

◆ timestamp

bool trace::FormattingOptions::timestamp = false

Prefix each trace with a timestamp (from UNI20_TRACE_TIMESTAMP or module override).


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