11#ifndef FRAMEWORK_VARIANT_H
12#define FRAMEWORK_VARIANT_H
21#include <initializer_list>
58template <VariantType V>
68template <VariantType V>
76template <VariantType V>
82template <VariantType V>
91template <VariantType V>
108struct variant_trait : std::integral_constant<VariantType, VariantType::Unknown> {
111#define DECLARE_VARIANT_TRAIT(_Type1_, _Type2_) \
113 struct variant_trait<_Type1_> : std::integral_constant<VariantType, VariantType::_Type2_> { \
192template <VariantType type>
196#define DECLARE_VARIANT_TYPE(_Type1_, _Type2_) \
198 struct variant_type<VariantType::_Type2_> { \
199 using type = _Type1_; \
230template <VariantType type>
234#define DECLARE_VARIANT_ARRAY_ELEMENT_TYPE(_Type1_, _Type2_) \
236 struct variant_array_element_type<VariantType::_Type2_> { \
237 using type = _Type1_; \
254template <VariantType V>
261 new (
reinterpret_cast<T*
>(store)) T{};
262 *(
reinterpret_cast<T*
>(store)) =
value;
266 *
reinterpret_cast<T*
>(store) =
reinterpret_cast<T
>(std::memcpy(std::malloc(
size *
sizeof(std::remove_pointer_t<T>)),
reinterpret_cast<void*
>(
values),
size *
sizeof(std::remove_pointer_t<T>)));
269 static T
get(
const void* store) {
return *(
reinterpret_cast<const T*
>(store)); }
275 static void set(
void* store, std::vector<std::string>
value)
277 new (
reinterpret_cast<std::vector<std::string>*
>(store)) std::vector<std::string>{};
278 *(
reinterpret_cast<std::vector<std::string>*
>(store)) =
value;
281 static std::vector<std::string>
const&
get(
const void* store) {
return *(
reinterpret_cast<std::vector<std::string> const*
>(store)); }
286 static const char*
get(
const void* store) {
return *
reinterpret_cast<const char* const*
>(store); }
288 static void set(
void* store,
const char*
value) { *
reinterpret_cast<char**
>(store) = strdup(
value); }
293 static std::string_view
get(
const void* store) {
return std::string_view(*
reinterpret_cast<const char* const*
>(store)); }
295 static void set(
void* store, std::string_view
value) { *
reinterpret_cast<char**
>(store) = strdup(
value.data()); }
300 static std::string
get(
const void* store) {
return std::string(*
reinterpret_cast<const char* const*
>(store)); }
302 static void set(
void* store, std::string
value) { *
reinterpret_cast<char**
>(store) = strdup(
value.data()); }
311 template <
typename T>
317 template <
typename T>
323 template <
typename T>
334 template <
typename T>
337 static_assert(
sizeof(T) == 0,
338 "brace-enclosed initializer list forbidden for Variant"
339 "\n did you accidentally put braces around the default value?");
347 template <
typename T>
354 template <
typename T>
357 if (mType != variant_trait_v<T>) {
358 throw runtime_error_f(
"Variant::get: Mismatch between types %d %d.", mType, variant_trait_v<T>);
363 template <
typename T>
369 template <
typename T>
376 template <
typename T>
378 requires(std::is_pod_v<T>)
383 template <
typename T>
385 requires(std::is_same_v<T, std::string>)
391 [[nodiscard]]
size_t size()
const {
return mSize; }
392 [[nodiscard]] std::string
asString()
const;
396 using storage_t = std::aligned_union<8,
int, int8_t, int16_t, int64_t,
397 uint8_t, uint16_t, uint32_t, uint64_t,
398 const char*, float, double, bool,
399 int*,
float*,
double*,
bool*, std::string*,
#define DECLARE_VARIANT_TYPE(_Type1_, _Type2_)
#define DECLARE_VARIANT_TRAIT(_Type1_, _Type2_)
#define DECLARE_VARIANT_ARRAY_ELEMENT_TYPE(_Type1_, _Type2_)
Variant for configuration parameter storage. Owns stored data.
Variant(std::vector< std::string > &values)
Variant(std::vector< T > &values)
Variant(T values, size_t size)
std::string asString() const
Variant & operator=(std::vector< T > &&other) noexcept
Variant & operator=(const Variant &other)
friend std::ostream & operator<<(std::ostream &oss, Variant const &val)
void set(std::vector< T > &values)
void set(T value, size_t size)
Variant(std::initializer_list< T >)
void set(std::vector< T > &values)
Variant(VariantType type=VariantType::Unknown)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
GLenum GLsizei GLsizei GLint * values
Defining PrimaryVertex explicitly as messageable.
constexpr auto isSimpleVariant()
constexpr auto isLabeledArrayString()
constexpr auto isLabeledArray()
constexpr auto isArray2D()
typename variant_array_element_type< V >::type variant_array_element_type_t
constexpr VariantType variant_trait_v
RuntimeErrorRef runtime_error_f(const char *,...)
Defining DataPointCompositeObject explicitly as copiable.
static constexpr char symbol
static const char * get(const void *store)
static void set(void *store, const char *value)
static void set(void *store, std::string value)
static std::string get(const void *store)
static void set(void *store, std::string_view value)
static std::string_view get(const void *store)
static std::vector< std::string > const & get(const void *store)
static void set(void *store, std::vector< std::string > value)
static T get(const void *store)
static void set(void *store, T values, size_t size)
static void set(void *store, T value)
VectorOfTObjectPtrs other