Porytiles
Loading...
Searching...
No Matches
layer_value.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <vector>
6
7namespace porytiles {
8
19enum class ValidationState {
20 not_provided, // Provider doesn't supply this config
21 valid, // Provider supplies valid config
22 invalid // Provider found invalid config
23};
24
36template <typename T>
37struct LayerValue {
38 std::optional<T> value;
39 std::string source_key;
40 std::string source_info;
41 std::vector<std::string> source_details;
43 std::string error_message;
44
53 static LayerValue valid(T val, std::string source_key, std::string source_info)
54 {
55 return LayerValue{
56 std::move(val), std::move(source_key), std::move(source_info), {}, ValidationState::valid, ""};
57 }
58
69 static LayerValue
70 valid(T val, std::string source_key, std::string source_info, std::vector<std::string> source_details)
71 {
72 return LayerValue{
73 std::move(val),
74 std::move(source_key),
75 std::move(source_info),
76 std::move(source_details),
78 ""};
79 }
80
88 static LayerValue invalid(std::string error, std::string source_info)
89 {
90 return LayerValue{std::nullopt, "", std::move(source_info), {}, ValidationState::invalid, std::move(error)};
91 }
92
101 static LayerValue invalid(std::string error, std::string source_info, std::vector<std::string> source_details)
102 {
103 return LayerValue{
104 std::nullopt,
105 "",
106 std::move(source_info),
107 std::move(source_details),
109 std::move(error)};
110 }
111
118 {
119 return LayerValue{std::nullopt, "", "", {}, ValidationState::not_provided, ""};
120 }
121};
122
133template <typename T>
135 std::string provider_name;
137};
138
139} // namespace porytiles
@ error
Emit a formatted error and fail decompilation.
ValidationState
Represents the validation state of a configuration value from a ConfigProvider.
A small container that holds an optional-wrapped value, validation state, and metadata about the valu...
static LayerValue valid(T val, std::string source_key, std::string source_info)
Creates a LayerValue representing a valid configuration value.
std::optional< T > value
std::vector< std::string > source_details
static LayerValue invalid(std::string error, std::string source_info, std::vector< std::string > source_details)
Creates a LayerValue representing an invalid configuration value with detailed source context.
static LayerValue valid(T val, std::string source_key, std::string source_info, std::vector< std::string > source_details)
Creates a LayerValue representing a valid configuration value with detailed source context.
std::string error_message
static LayerValue not_provided()
Creates a LayerValue representing that the provider does not supply this configuration.
ValidationState state
static LayerValue invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.