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
21template <typename T>
23 std::optional<T> value{std::nullopt};
24 std::string source_key;
25 std::string canonical_name;
26 std::string source_info;
27 std::vector<std::string> source_details;
28
29 ConfigPODField() = default;
30
37 // NOLINTNEXTLINE
38 ConfigPODField(T val) : value{std::move(val)} {}
39
44 // NOLINTNEXTLINE
45 ConfigPODField(std::nullopt_t) {}
46
55 ConfigPODField(T val, std::string source_key, std::string canonical_name)
56 : value{std::move(val)}, source_key{std::move(source_key)}, canonical_name{std::move(canonical_name)}
57 {
58 }
59
74 T val,
75 std::string source_key,
76 std::string canonical_name,
77 std::string source_info,
78 std::vector<std::string> source_details)
79 : value{std::move(val)}, source_key{std::move(source_key)}, canonical_name{std::move(canonical_name)},
81 {
82 }
83
87 [[nodiscard]] bool has_value() const
88 {
89 return value.has_value();
90 }
91
96 [[nodiscard]] const T &operator*() const
97 {
98 return *value;
99 }
100};
101
102} // 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.