Porytiles
Loading...
Searching...
No Matches
unwrap_config.hpp File Reference
Include dependency graph for unwrap_config.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  porytiles
 

Macros

#define PT_UNWRAP_TILESET_CONFIG_PTR_AS(var, ptr, config, tileset_name, return_type)
 Unwraps a tileset-scoped config value via pointer access into an explicitly named local variable, returning early if the value is not available.
 
#define PT_UNWRAP_TILESET_CONFIG_PTR(ptr, config, tileset_name, return_type)    PT_UNWRAP_TILESET_CONFIG_PTR_AS(config, ptr, config, tileset_name, return_type)
 Unwraps a tileset-scoped config value via pointer access, returning early if the value is not available.
 
#define PT_UNWRAP_TILESET_CONFIG_REF_AS(var, ref, config, tileset_name, return_type)
 Unwraps a tileset-scoped config value via reference access into an explicitly named local variable, returning early if the value is not available.
 
#define PT_UNWRAP_TILESET_CONFIG_REF(ref, config, tileset_name, return_type)    PT_UNWRAP_TILESET_CONFIG_REF_AS(config, ref, config, tileset_name, return_type)
 Unwraps a tileset-scoped config value via reference access, returning early if the value is not available.
 
#define PT_UNWRAP_LAYOUT_CONFIG_AS(var, ptr, config, layout_name, return_type)
 Unwraps a layout-scoped config value into an explicitly named local variable, returning early if the value is not available.
 
#define PT_UNWRAP_LAYOUT_CONFIG(ptr, config, layout_name, return_type)    PT_UNWRAP_LAYOUT_CONFIG_AS(config, ptr, config, layout_name, return_type)
 Unwraps a layout-scoped config value from a DomainConfig, AppConfig, or InfraConfig object, returning early if the value is not available.
 

Macro Definition Documentation

◆ PT_UNWRAP_LAYOUT_CONFIG

#define PT_UNWRAP_LAYOUT_CONFIG (   ptr,
  config,
  layout_name,
  return_type 
)     PT_UNWRAP_LAYOUT_CONFIG_AS(config, ptr, config, layout_name, return_type)

Unwraps a layout-scoped config value from a DomainConfig, AppConfig, or InfraConfig object, returning early if the value is not available.

Convenience form of PT_UNWRAP_LAYOUT_CONFIG_AS that names the resulting local variable after the config method itself. Because the locals are derived from the config name, this form cannot unwrap the same config value twice in one scope; use PT_UNWRAP_LAYOUT_CONFIG_AS for that.

Parameters
ptrA pointer to a config object
configThe name of the config method to call and the resulting variable name
layout_nameThe layout name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_LAYOUT_CONFIG_AS for the explicitly named form

Definition at line 155 of file unwrap_config.hpp.

◆ PT_UNWRAP_LAYOUT_CONFIG_AS

#define PT_UNWRAP_LAYOUT_CONFIG_AS (   var,
  ptr,
  config,
  layout_name,
  return_type 
)
Value:
auto var##_result = ptr->config(ConfigScopeType::layout, layout_name); \
if (!var##_result.has_value()) { \
return ChainableResult<return_type>{ \
FormattableError{ \
"Failed to get config value '{}:{}:{}'.", \
FormatParam{"layout", Style::bold}, \
FormatParam{layout_name, Style::bold}, \
FormatParam{#config, Style::bold}}, \
var##_result}; \
} \
auto var = std::move(var##_result).value();

Unwraps a layout-scoped config value into an explicitly named local variable, returning early if the value is not available.

This macro retrieves a config value for a given layout and automatically handles the error case. If the config value is not available, it returns a ChainableResult error with a formatted message. Otherwise, it unwraps the value into a local variable named by the var parameter (with an internal var##_result temporary).

Prefer PT_UNWRAP_LAYOUT_CONFIG when the config name works as the variable name. This form exists for call sites that unwrap the same config value more than once in a single scope (e.g. for two different layouts), where the config-named form would redeclare its locals.

Parameters
varThe variable name to assign the unwrapped value to
ptrA pointer to a config object
configThe name of the config method to call
layout_nameThe layout name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_LAYOUT_CONFIG for the config-named convenience form

Definition at line 128 of file unwrap_config.hpp.

◆ PT_UNWRAP_TILESET_CONFIG_PTR

#define PT_UNWRAP_TILESET_CONFIG_PTR (   ptr,
  config,
  tileset_name,
  return_type 
)     PT_UNWRAP_TILESET_CONFIG_PTR_AS(config, ptr, config, tileset_name, return_type)

Unwraps a tileset-scoped config value via pointer access, returning early if the value is not available.

Convenience form of PT_UNWRAP_TILESET_CONFIG_PTR_AS that names the resulting local variable after the config method itself. Because the locals are derived from the config name, this form cannot unwrap the same config value twice in one scope; use PT_UNWRAP_TILESET_CONFIG_PTR_AS for that.

Parameters
ptrA pointer to a DomainConfig, AppConfig, or InfraConfig object
configThe name of the config method to call and the resulting variable name
tileset_nameThe tileset name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_TILESET_CONFIG_PTR_AS for the explicitly named form
PT_UNWRAP_TILESET_CONFIG_REF for reference-based access

Definition at line 55 of file unwrap_config.hpp.

◆ PT_UNWRAP_TILESET_CONFIG_PTR_AS

#define PT_UNWRAP_TILESET_CONFIG_PTR_AS (   var,
  ptr,
  config,
  tileset_name,
  return_type 
)
Value:
auto var##_result = ptr->config(ConfigScopeType::tileset, tileset_name); \
if (!var##_result.has_value()) { \
return ChainableResult<return_type>{ \
FormattableError{ \
"Failed to get config value '{}:{}:{}'.", \
FormatParam{"tileset", Style::bold}, \
FormatParam{tileset_name, Style::bold}, \
FormatParam{#config, Style::bold}}, \
var##_result}; \
} \
auto var = std::move(var##_result).value();

Unwraps a tileset-scoped config value via pointer access into an explicitly named local variable, returning early if the value is not available.

This macro retrieves a config value for a given tileset using pointer syntax (ptr->config) and automatically handles the error case. If the config value is not available, it returns a ChainableResult error with a formatted message. Otherwise, it unwraps the value into a local variable named by the var parameter (with an internal var##_result temporary).

Prefer PT_UNWRAP_TILESET_CONFIG_PTR when the config name works as the variable name. This form exists for call sites that unwrap the same config value more than once in a single scope (e.g. for two different tilesets), where the config-named form would redeclare its locals.

Parameters
varThe variable name to assign the unwrapped value to
ptrA pointer to a DomainConfig, AppConfig, or InfraConfig object
configThe name of the config method to call
tileset_nameThe tileset name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_TILESET_CONFIG_PTR for the config-named convenience form
PT_UNWRAP_TILESET_CONFIG_REF_AS for reference-based access

Definition at line 28 of file unwrap_config.hpp.

◆ PT_UNWRAP_TILESET_CONFIG_REF

#define PT_UNWRAP_TILESET_CONFIG_REF (   ref,
  config,
  tileset_name,
  return_type 
)     PT_UNWRAP_TILESET_CONFIG_REF_AS(config, ref, config, tileset_name, return_type)

Unwraps a tileset-scoped config value via reference access, returning early if the value is not available.

Convenience form of PT_UNWRAP_TILESET_CONFIG_REF_AS that names the resulting local variable after the config method itself. Because the locals are derived from the config name, this form cannot unwrap the same config value twice in one scope; use PT_UNWRAP_TILESET_CONFIG_REF_AS for that.

Parameters
refA reference to a DomainConfig, AppConfig, or InfraConfig object
configThe name of the config method to call and the resulting variable name
tileset_nameThe tileset name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_TILESET_CONFIG_REF_AS for the explicitly named form
PT_UNWRAP_TILESET_CONFIG_PTR for pointer-based access

Definition at line 106 of file unwrap_config.hpp.

◆ PT_UNWRAP_TILESET_CONFIG_REF_AS

#define PT_UNWRAP_TILESET_CONFIG_REF_AS (   var,
  ref,
  config,
  tileset_name,
  return_type 
)
Value:
auto var##_result = ref.config(ConfigScopeType::tileset, tileset_name); \
if (!var##_result.has_value()) { \
return ChainableResult<return_type>{ \
FormattableError{ \
"Failed to get config value '{}:{}:{}'.", \
FormatParam{"tileset", Style::bold}, \
FormatParam{tileset_name, Style::bold}, \
FormatParam{#config, Style::bold}}, \
var##_result}; \
} \
auto var = std::move(var##_result).value();

Unwraps a tileset-scoped config value via reference access into an explicitly named local variable, returning early if the value is not available.

This macro retrieves a config value for a given tileset using reference syntax (ref.config) and automatically handles the error case. If the config value is not available, it returns a ChainableResult error with a formatted message. Otherwise, it unwraps the value into a local variable named by the var parameter (with an internal var##_result temporary).

Prefer PT_UNWRAP_TILESET_CONFIG_REF when the config name works as the variable name. This form exists for call sites that unwrap the same config value more than once in a single scope (e.g. for two different tilesets), where the config-named form would redeclare its locals.

Parameters
varThe variable name to assign the unwrapped value to
refA reference to a DomainConfig, AppConfig, or InfraConfig object
configThe name of the config method to call
tileset_nameThe tileset name to pass to the config method
return_typeThe template parameter for ChainableResult in case of error
See also
PT_UNWRAP_TILESET_CONFIG_REF for the config-named convenience form
PT_UNWRAP_TILESET_CONFIG_PTR_AS for pointer-based access

Definition at line 79 of file unwrap_config.hpp.