3#include "util/Assert.hpp"
4#include "util/config/ConfigConstraints.hpp"
5#include "util/config/ConfigValue.hpp"
6#include "util/config/Types.hpp"
20namespace util::config {
42 [[nodiscard]] std::string
65 if ((
type() == ConfigType::Integer) && configVal_.get().hasValue()) {
66 auto const val = std::get<int64_t>(configVal_.get().getValue());
67 if (std::is_unsigned_v<T> && val < 0)
68 ASSERT(
false,
"Int {} cannot be converted to the specified unsigned type", val);
70 if (std::is_convertible_v<
decltype(val), T>) {
71 return static_cast<T
>(val);
74 ASSERT(
false,
"Value view is not of Int type");
101 [[nodiscard]]
constexpr ConfigType
104 return configVal_.get().type();
114 return configVal_.get().hasValue();
124 return configVal_.get().isOptional();
132 [[nodiscard]]
constexpr std::optional<std::reference_wrapper<Constraint const>>
135 return configVal_.get().getConstraint();
144 template <
typename T>
148 ASSERT(configVal_.get().hasValue(),
"ConfigValue does not have a value");
149 if constexpr (std::is_same_v<T, bool>) {
150 ASSERT(
type() == ConfigType::Boolean,
"Value type is not a bool");
152 }
else if constexpr (std::is_integral_v<T>) {
153 ASSERT(
type() == ConfigType::Integer,
"Value type is not an int");
155 }
else if constexpr (std::is_same_v<T, std::string>) {
156 ASSERT(
type() == ConfigType::String,
"Value type is not a string");
158 }
else if constexpr (std::is_floating_point_v<T>) {
160 type() == ConfigType::Double ||
type() == ConfigType::Integer,
161 "Value type is not a floating point"
175 template <
typename T>
179 ASSERT(
isOptional(),
"A Config Value is not an optional value");
196 stream << value.configVal_;
201 std::reference_wrapper<ConfigValue const> configVal_;
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
Represents the config values for Json/Yaml config.
Definition ConfigValue.hpp:28
double asDouble() const
Retrieves the value as a double.
Definition ValueView.cpp:37
bool constexpr isOptional() const
Check if config value is optional.
Definition ValueView.hpp:122
friend std::ostream & operator<<(std::ostream &stream, ValueView value)
Custom output stream for ValueView.
Definition ValueView.hpp:194
T getValueImpl() const
Retrieves the stored value as the specified type T.
Definition ValueView.hpp:146
ValueView(ConfigValue const &configVal)
Constructs a ValueView object.
Definition ValueView.cpp:14
constexpr std::optional< std::reference_wrapper< Constraint const > > getConstraint() const
Retrieves the constraint associated with the ConfigValue in this ValueView, if any.
Definition ValueView.hpp:133
bool constexpr hasValue() const
Check if Config Value exists.
Definition ValueView.hpp:112
bool asBool() const
Retrieves the value as a boolean.
Definition ValueView.cpp:28
float asFloat() const
Retrieves the value as a float.
Definition ValueView.cpp:56
T asIntType() const
Retrieves any type of "int" value (uint_32, int64_t etc).
Definition ValueView.hpp:63
constexpr ConfigType type() const
Gets the config type.
Definition ValueView.hpp:102
std::string asString() const
Retrieves the value as a string.
Definition ValueView.cpp:19
std::optional< T > asOptional() const
Returns an optional value of the specified type T if valid.
Definition ValueView.hpp:177