Porytiles
Loading...
Searching...
No Matches
porytiles2::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 (T value, std::string name, std::string source, const std::vector< std::string > &source_details)
 Constructs a ConfigValue with a value, name, 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 &
 Gets a const reference to the underlying value.
 
T && value () &&
 Gets an rvalue reference to the underlying value.
 
const std::string & name () const
 Gets the name of this configuration value.
 
const std::string & source () const
 Gets the source information for this configuration value.
 
const std::vector< std::string > & source_details () const
 Gets the source details for this configuration value.
 
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > format_data () const
 Generates formatted text data for displaying this configuration value.
 

Detailed Description

template<typename T>
class porytiles2::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 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 22 of file config_value.hpp.

Constructor & Destructor Documentation

◆ ConfigValue()

template<typename T >
porytiles2::ConfigValue< T >::ConfigValue ( value,
std::string  name,
std::string  source,
const std::vector< std::string > &  source_details 
)
inline

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

Parameters
valueThe configuration value
nameThe name of the configuration value (e.g., "num_tiles_primary")
sourceA string describing where this value came from
source_detailsA vector of strings with the optional source details

Definition at line 32 of file config_value.hpp.

Member Function Documentation

◆ format_data()

template<typename T >
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > porytiles2::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 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 T & value() const &
Gets a const reference to the underlying value.
const std::string & name() const
Gets the name of this configuration value.
const std::string & source() const
Gets the source information for this configuration value.

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 155 of file config_value.hpp.

◆ name()

template<typename T >
const std::string & porytiles2::ConfigValue< T >::name ( ) const
inline

Gets the name of this configuration value.

The name identifies the configuration value, such as:

  • "num_tiles_primary"
  • "num_tiles_secondary"
  • "incremental_build_mode"
Returns
A const reference to the name string

Definition at line 94 of file config_value.hpp.

◆ operator const T &()

template<typename T >
porytiles2::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 45 of file config_value.hpp.

◆ operator T&&()

template<typename T >
porytiles2::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 58 of file config_value.hpp.

◆ source()

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

Gets the source information for this configuration value.

The source string describes where this value originated, such as:

  • "default value"
  • "./porytiles.yaml:12"
  • "$PORYTILES_FIELDMAP_NUM_TILES_PRIMARY"
Returns
A const reference to the source string

Definition at line 110 of file config_value.hpp.

◆ source_details()

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

Gets the source details for this configuration value.

The source details supplement the source string with additional context. For example, the YAML file provider may use the details string to supplement the file name and line number with a contextual view of the YAML file.

Returns
A const reference to the source details vector

Definition at line 124 of file config_value.hpp.

◆ value() [1/2]

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

Gets an rvalue reference to the underlying value.

Returns
An rvalue reference to the stored value

Definition at line 78 of file config_value.hpp.

◆ value() [2/2]

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

Gets a const reference to the underlying value.

Returns
A const reference to the stored value

Definition at line 68 of file config_value.hpp.


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