22#include "util/Assert.hpp"
23#include "util/newconfig/ConfigConstraints.hpp"
24#include "util/newconfig/ConfigValue.hpp"
25#include "util/newconfig/Types.hpp"
39namespace util::config {
41class ClioConfigDefinition;
61 [[nodiscard]] std::string
84 if ((
type() == ConfigType::Integer) && configVal_.get().hasValue()) {
85 auto const val = std::get<int64_t>(configVal_.get().getValue());
86 if (std::is_unsigned_v<T> && val < 0)
87 ASSERT(
false,
"Int {} cannot be converted to the specified unsigned type", val);
89 if (std::is_convertible_v<
decltype(val), T>) {
90 return static_cast<T
>(val);
93 ASSERT(
false,
"Value view is not of Int type");
120 [[nodiscard]]
constexpr ConfigType
123 return configVal_.get().type();
133 return configVal_.get().hasValue();
143 return configVal_.get().isOptional();
151 [[nodiscard]]
constexpr std::optional<std::reference_wrapper<Constraint const>>
154 return configVal_.get().getConstraint();
163 template <
typename T>
167 ASSERT(configVal_.get().hasValue(),
"ConfigValue does not have a value");
168 if constexpr (std::is_same_v<T, bool>) {
169 ASSERT(
type() == ConfigType::Boolean,
"Value type is not a bool");
171 }
else if constexpr (std::is_integral_v<T>) {
172 ASSERT(
type() == ConfigType::Integer,
"Value type is not an int");
174 }
else if constexpr (std::is_same_v<T, std::string>) {
175 ASSERT(
type() == ConfigType::String,
"Value type is not a string");
177 }
else if constexpr (std::is_floating_point_v<T>) {
178 ASSERT(
type() == ConfigType::Double ||
type() == ConfigType::Integer,
"Value type is not a floating point");
191 template <
typename T>
195 ASSERT(
isOptional(),
"A Config Value is not an optional value");
212 stream << value.configVal_;
217 std::reference_wrapper<ConfigValue const> configVal_;
Represents the config values for Json/Yaml config.
Definition ConfigValue.hpp:48
Provides view into ConfigValues that represents values in Clio Config.
Definition ValueView.hpp:46
double asDouble() const
Retrieves the value as a double.
Definition ValueView.cpp:56
bool constexpr isOptional() const
Check if config value is optional.
Definition ValueView.hpp:141
friend std::ostream & operator<<(std::ostream &stream, ValueView value)
Custom output stream for ValueView.
Definition ValueView.hpp:210
T getValueImpl() const
Retrieves the stored value as the specified type T.
Definition ValueView.hpp:165
ValueView(ConfigValue const &configVal)
Constructs a ValueView object.
Definition ValueView.cpp:33
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:152
bool constexpr hasValue() const
Check if Config Value exists.
Definition ValueView.hpp:131
bool asBool() const
Retrieves the value as a boolean.
Definition ValueView.cpp:47
float asFloat() const
Retrieves the value as a float.
Definition ValueView.cpp:75
T asIntType() const
Retrieves any type of "int" value (uint_32, int64_t etc)
Definition ValueView.hpp:82
constexpr ConfigType type() const
Gets the config type.
Definition ValueView.hpp:121
std::string asString() const
Retrieves the value as a string.
Definition ValueView.cpp:38
std::optional< T > asOptional() const
Returns an optional value of the specified type T if valid.
Definition ValueView.hpp:193