Porytiles
Loading...
Searching...
No Matches
xcut_config_validators.hpp File Reference

Cross-cutting configuration validators shared across all architectural layers. More...

#include <cstddef>
#include <functional>
#include <string>
#include <vector>
#include "porytiles/utilities/result/chainable_result.hpp"
#include "porytiles/xcut/config/config_scope_type.hpp"
#include "porytiles/xcut/config/config_value.hpp"
Include dependency graph for xcut_config_validators.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  porytiles
 
namespace  porytiles::details
 

Functions

ChainableResult< ConfigValue< std::size_t > > porytiles::size_t_val_greater_than_zero (const ConfigValue< std::size_t > &val)
 Validates that a size_t config value is greater than zero.
 
ChainableResult< ConfigValue< std::size_t > > porytiles::size_t_val_two_or_four (const ConfigValue< std::size_t > &val)
 Validates that a size_t config value is either 2 or 4.
 
ChainableResult< ConfigValue< std::size_t > > porytiles::size_t_val_eight_or_twelve (const ConfigValue< std::size_t > &val)
 Validates that a size_t config value is either 8 or 12.
 
template<typename T , typename ConfigInterface , typename FetchFunc , typename Comparator >
ChainableResult< ConfigValue< T > > porytiles::details::compare_values (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other, Comparator comp, std::string_view error_message)
 Generic comparison validator that compares the current value against another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_greater_than (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is greater than another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_less_than (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is less than another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_greater_equal (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is greater than or equal to another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_less_equal (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is less than or equal to another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_equal (const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is equal to another config value.
 
template<typename T , typename ConfigInterface , typename FetchFunc >
ChainableResult< ConfigValue< T > > porytiles::compare_not_equal (const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
 Validates that the current value is not equal to another config value.
 

Detailed Description

Cross-cutting configuration validators shared across all architectural layers.

This file provides layer-agnostic configuration validators that can be used by DomainConfig, AppConfig, and InfraConfig without introducing circular dependencies. The validators are organized into two categories:

Validator Categories

  1. Single-Value Validators: Validate a single config value in isolation (e.g., size_t_val_greater_than_zero)
  2. Cross-Field Validators: Validate a config value by comparing it against other config values within the same layer (e.g., compare_greater_than, compare_less_than). These validators accept a ConfigInterface and can fetch other values for comparison.

Design Rationale: Why xcut Layer for Common Validators?

The xcut (cross-cutting) layer sits above the domain, app, and infra layers in the architectural hierarchy. By placing common validators here, we achieve several benefits:

  1. Dependency Inversion: Lower layers (domain, app, infra) can depend on xcut without creating cycles
  2. Code Reuse: Validators that don't depend on layer-specific types can be shared across all layers
  3. Separation of Concerns: Generic validation logic is separated from domain/app/infra-specific logic

Layer-Specific Validators: When and Why?

When a validator needs to reference layer-specific types (e.g., TilesPalMode from the infra layer), it cannot be defined here in xcut because that would require xcut to depend on a lower-level layer, creating a circular dependency. In these cases, the validator should be defined in a layer-specific header such as app_config_validators.hpp, domain_config_validators.hpp, or infra_config_validators.hpp.

The config generation system supports this pattern seamlessly because validators are referenced by name as strings in the YAML schema. During code generation, these validator function names are copy-pasted into the generated layer config files. The generation process is agnostic to where the validators are defined - it only cares that the function name matches. This allows each layer's config header to include both the common xcut validators and its own layer-specific validators without any dependency issues.

Note
All validators return ChainableResult<ConfigValue<T>> to support composable validation chains
See also
config_value.hpp for the ConfigValue type
chainable_result.hpp for the ChainableResult monadic error handling type

Definition in file xcut_config_validators.hpp.