Porytiles
Loading...
Searching...
No Matches
config_pod_field.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <utility>
6#include <vector>
7
8namespace porytiles {
9
23template <typename T>
25 std::optional<T> value{std::nullopt};
26 std::string source_key;
27 std::string canonical_name;
28 std::string source_info;
29 std::vector<std::string> source_details;
30
31 ConfigPODField() = default;
32
41 // NOLINTNEXTLINE
42 ConfigPODField(T val) : value{std::move(val)} {}
43
50 // NOLINTNEXTLINE
51 ConfigPODField(std::nullopt_t) {}
52
63 ConfigPODField(T val, std::string source_key, std::string canonical_name)
64 : value{std::move(val)}, source_key{std::move(source_key)}, canonical_name{std::move(canonical_name)}
65 {
66 }
67
84 T val,
85 std::string source_key,
86 std::string canonical_name,
87 std::string source_info,
88 std::vector<std::string> source_details)
89 : value{std::move(val)}, source_key{std::move(source_key)}, canonical_name{std::move(canonical_name)},
91 {
92 }
93
99 [[nodiscard]] bool has_value() const
100 {
101 return value.has_value();
102 }
103
110 [[nodiscard]] const T &operator*() const
111 {
112 return *value;
113 }
114};
115
116} // namespace porytiles
A lightweight wrapper for per-field configuration values with source metadata.
std::vector< std::string > source_details
bool has_value() const
Checks whether this field has a value set.
ConfigPODField(std::nullopt_t)
Constructs an empty ConfigPODField from std::nullopt.
const T & operator*() const
Accesses the stored value.
ConfigPODField(T val, std::string source_key, std::string canonical_name, std::string source_info, std::vector< std::string > source_details)
Constructs a ConfigPODField with a value, full source metadata, and per-entry source location.
ConfigPODField(T val)
Constructs a ConfigPODField with a value and no source metadata.
ConfigPODField(T val, std::string source_key, std::string canonical_name)
Constructs a ConfigPODField with a value and full source metadata.