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 porytiles2 {
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 // TODO: add _ to end of these field names
39 std::optional<T> value;
40 std::string source_info;
41 std::vector<std::string> source_details;
43 std::string error_message;
44
52 static LayerValue valid(T val, std::string source_info)
53 {
54 return LayerValue{std::move(val), std::move(source_info), {}, ValidationState::valid, ""};
55 }
56
65 static LayerValue valid(T val, std::string source_info, std::vector<std::string> source_details)
66 {
67 return LayerValue{
68 std::move(val), std::move(source_info), std::move(source_details), ValidationState::valid, ""};
69 }
70
78 static LayerValue invalid(std::string error, std::string source_info)
79 {
80 return LayerValue{std::nullopt, std::move(source_info), {}, ValidationState::invalid, std::move(error)};
81 }
82
91 static LayerValue invalid(std::string error, std::string source_info, std::vector<std::string> source_details)
92 {
93 return LayerValue{
94 std::nullopt,
95 std::move(source_info),
96 std::move(source_details),
98 std::move(error)};
99 }
100
107 {
108 return LayerValue{std::nullopt, "", {}, ValidationState::not_provided, ""};
109 }
110};
111
112} // namespace porytiles2
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_info)
Creates a LayerValue representing a valid configuration value.
static LayerValue not_provided()
Creates a LayerValue representing that the provider does not supply this configuration.
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 invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.
std::vector< std::string > source_details
std::optional< T > value
static LayerValue valid(T val, std::string source_info, std::vector< std::string > source_details)
Creates a LayerValue representing a valid configuration value with detailed source context.
ValidationState state