Porytiles
Loading...
Searching...
No Matches
porytiles2::FormatParam Class Reference

A text parameter with associated styling for formatted output. More...

#include <text_formatter.hpp>

Public Member Functions

 FormatParam (std::string text)
 Constructs a FormatParam with unstyled text.
 
 FormatParam (std::string text, Style styles)
 Constructs a FormatParam with styled text.
 
template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && requires(std::ostringstream os, T val) { os << val; })
 FormatParam (T &&value)
 Constructs a FormatParam by converting a value to string.
 
template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && requires(std::ostringstream os, T val) { os << val; })
 FormatParam (T &&value, Style styles)
 Constructs a FormatParam by converting a value to styled string.
 
const std::string & text () const
 
Style styles () const
 

Detailed Description

A text parameter with associated styling for formatted output.

FormatParam pairs a text string with Style flags to enable styled parameter substitution in formatted strings. When used with TextFormatter::format(), the text is styled according to the formatter implementation (ANSI codes for TTY, plain text for non-TTY) before being substituted into the format string.

Example usage:

++
FormattableError{"tileset '{}' not found", FormatParam{name, Style::bold}}
A text parameter with associated styling for formatted output.
General-purpose error implementation with formatted message support.
Definition error.hpp:117
@ bold
Bold text formatting.

This struct is typically constructed inline when creating error messages or formatted diagnostic output.

Definition at line 132 of file text_formatter.hpp.

Constructor & Destructor Documentation

◆ FormatParam() [1/4]

porytiles2::FormatParam::FormatParam ( std::string  text)
inline

Constructs a FormatParam with unstyled text.

Creates a FormatParam with the given text and no styling applied (Style::none).

Parameters
textThe text content to be formatted

Definition at line 142 of file text_formatter.hpp.

◆ FormatParam() [2/4]

porytiles2::FormatParam::FormatParam ( std::string  text,
Style  styles 
)
inlineexplicit

Constructs a FormatParam with styled text.

Creates a FormatParam with the given text and specified styling attributes.

Parameters
textThe text content to be formatted
stylesThe styling attributes to apply to the text

Definition at line 153 of file text_formatter.hpp.

◆ FormatParam() [3/4]

template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && requires(std::ostringstream os, T val) { os << val; })
porytiles2::FormatParam::FormatParam ( T &&  value)
inline

Constructs a FormatParam by converting a value to string.

Creates a FormatParam by converting the given value to a string using stream insertion. This constructor is constrained to accept only types that support operator<<, excluding std::string to avoid ambiguity with the existing string constructor.

Template Parameters
TThe type of the value (must support stream insertion)
Parameters
valueThe value to convert to string

Definition at line 170 of file text_formatter.hpp.

◆ FormatParam() [4/4]

template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && requires(std::ostringstream os, T val) { os << val; })
porytiles2::FormatParam::FormatParam ( T &&  value,
Style  styles 
)
inlineexplicit

Constructs a FormatParam by converting a value to styled string.

Creates a FormatParam by converting the given value to a string using stream insertion, with the specified styling attributes applied.

Template Parameters
TThe type of the value (must support stream insertion)
Parameters
valueThe value to convert to string
stylesThe styling attributes to apply to the text

Definition at line 189 of file text_formatter.hpp.

Member Function Documentation

◆ styles()

Style porytiles2::FormatParam::styles ( ) const
inline

Definition at line 198 of file text_formatter.hpp.

◆ text()

const std::string & porytiles2::FormatParam::text ( ) const
inline

Definition at line 193 of file text_formatter.hpp.


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