Porytiles
Loading...
Searching...
No Matches
porytiles::ConfigValue< T > Class Template Reference

A container that wraps a configuration value with its name and source information. More...

#include <config_value.hpp>

Public Member Functions

 ConfigValue ()=default
 
 ConfigValue (T value, std::string canonical_name, std::string source_key, std::string source, const std::vector< std::string > &source_details)
 Constructs a ConfigValue with a value, names, and source information.
 
 operator const T & () const &
 Implicit conversion to const reference of the underlying value.
 
 operator T&& () &&
 Implicit conversion to rvalue reference of the underlying value.
 
const T & value () const &
 
T && value () &&
 
const std::string & canonical_name () const
 
const std::string & source_key () const
 
const std::string & source () const
 
const std::vector< std::string > & source_details () const
 
template<typename U >
ConfigValue< U > derive (const ConfigPODField< U > &override) const
 Creates a child ConfigValue from a ConfigPODField, inheriting this value's source provenance.
 
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > format_data () const
 Generates formatted text data for displaying this configuration value.
 
std::vector< std::string > prettify (const TextFormatter &formatter) const
 Generates a prettified, styled readout of this configuration value.
 

Detailed Description

template<typename T>
class porytiles::ConfigValue< T >

A container that wraps a configuration value with its name and source information.

ConfigValue provides transparent access to configuration values while also tracking the config value's canonical name, provider-specific name, and where each value originated (e.g., which ConfigProvider supplied it). It supports implicit conversion to the underlying type for ergonomic usage.

Template Parameters
TThe type of the configuration value

Definition at line 24 of file config_value.hpp.

Constructor & Destructor Documentation

◆ ConfigValue() [1/2]

template<typename T >
porytiles::ConfigValue< T >::ConfigValue ( )
default

◆ ConfigValue() [2/2]

template<typename T >
porytiles::ConfigValue< T >::ConfigValue ( value,
std::string  canonical_name,
std::string  source_key,
std::string  source,
const std::vector< std::string > &  source_details 
)
inline

Constructs a ConfigValue with a value, names, and source information.

Parameters
valueThe configuration value
canonical_nameThe human-readable name from the schema (e.g., "Number Of Tiles In Primary")
source_keyThe provider-specific identifier (e.g., "--num-tiles-per-metatile" for CLI, "fieldmap.num_tiles_in_primary" for YAML)
sourceA string describing where this value came from (e.g., "CliOptionProvider", "./porytiles.yaml:12")
source_detailsA vector of strings with the optional source details

Definition at line 38 of file config_value.hpp.

Member Function Documentation

◆ canonical_name()

template<typename T >
const std::string & porytiles::ConfigValue< T >::canonical_name ( ) const
inline

Definition at line 87 of file config_value.hpp.

◆ derive()

template<typename T >
template<typename U >
ConfigValue< U > porytiles::ConfigValue< T >::derive ( const ConfigPODField< U > &  override) const
inline

Creates a child ConfigValue from a ConfigPODField, inheriting this value's source provenance.

Used to resolve per-field overrides within aggregate config values. The derived ConfigValue inherits source() and source_details() from this (parent) ConfigValue, while taking the value, canonical_name, and source_key from the override. This allows provider-specific source metadata set at parse time to flow through to the consumer without hardcoding provider formats.

Template Parameters
UThe type of the override value (may differ from T)
Parameters
overrideThe config override containing the value and per-field source metadata
Precondition
override must have a value (override.has_value() is true).
Returns
A new ConfigValue wrapping the override's value with combined provenance

Definition at line 122 of file config_value.hpp.

◆ format_data()

template<typename T >
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > porytiles::ConfigValue< T >::format_data ( ) const
inline

Generates formatted text data for displaying this configuration value.

Creates a structured representation of the configuration value suitable for formatted output or error messages. The output includes the value's canonical name, its actual value, the source information, and any additional source details if available. The format follows the pattern:

Source: source_string
[optional source details lines]
const std::string & source() const
const std::string & canonical_name() const
const T & value() const &

Each format string in the returned pair contains placeholders ({}) that correspond to the FormatParam objects in the parallel vector, which provide both the text to insert and styling information.

Returns
A pair containing:
  • first: Vector of format strings with placeholders
  • second: Vector of FormatParam vectors, where each inner vector contains the parameters for the corresponding format string at the same index
Postcondition
The returned vectors in the pair have matching sizes (excluding source_details entries which have no parameters)
The first format string is always "{} = {}" for name and value
The second format string is always "Source: {}" for source information

Definition at line 158 of file config_value.hpp.

◆ operator const T &()

template<typename T >
porytiles::ConfigValue< T >::operator const T & ( ) const &
inline

Implicit conversion to const reference of the underlying value.

Allows ConfigValue to be used transparently where the underlying type is expected.

Returns
A const reference to the stored value

Definition at line 58 of file config_value.hpp.

◆ operator T&&()

template<typename T >
porytiles::ConfigValue< T >::operator T&& ( ) &&
inline

Implicit conversion to rvalue reference of the underlying value.

Enables move semantics when the ConfigValue is an rvalue.

Returns
An rvalue reference to the stored value

Definition at line 72 of file config_value.hpp.

◆ prettify()

template<typename T >
std::vector< std::string > porytiles::ConfigValue< T >::prettify ( const TextFormatter formatter) const
inline

Generates a prettified, styled readout of this configuration value.

Convenience method that combines format_data() with a TextFormatter to produce styled text output ready for display. This method internally calls format_data() and applies the formatter to each format string with its corresponding parameters, returning a vector of fully formatted lines.

The output includes the value name, its actual value, the source information, and any additional source details if available, all with appropriate styling applied (or not, depending on the formatter implementation).

Example output (when displayed):

num_tiles_primary = 512
Source: ./porytiles.yaml:12
1: foo:
2: bar: baz
3: fieldmap:
-> 4: num_tiles_primary: 512
Parameters
formatterThe TextFormatter to use for applying styles to the text
Returns
A vector of formatted strings, each representing a line of the prettified output
Postcondition
The returned vector has at least 2 elements (name/value line and source line)
Additional lines may be present if source details are available

Definition at line 215 of file config_value.hpp.

◆ source()

template<typename T >
const std::string & porytiles::ConfigValue< T >::source ( ) const
inline

Definition at line 97 of file config_value.hpp.

◆ source_details()

template<typename T >
const std::vector< std::string > & porytiles::ConfigValue< T >::source_details ( ) const
inline

Definition at line 102 of file config_value.hpp.

◆ source_key()

template<typename T >
const std::string & porytiles::ConfigValue< T >::source_key ( ) const
inline

Definition at line 92 of file config_value.hpp.

◆ value() [1/2]

template<typename T >
T && porytiles::ConfigValue< T >::value ( ) &&
inline

Definition at line 82 of file config_value.hpp.

◆ value() [2/2]

template<typename T >
const T & porytiles::ConfigValue< T >::value ( ) const &
inline

Definition at line 77 of file config_value.hpp.


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