20template<
class T,
typename>
21Property::Property(T&& val) :
24 using TT = remove_cvref_t<T>;
26 if constexpr (std::is_integral_v<TT> || std::is_enum_v<TT>)
28 this->g_type = Types::PTYPE_INTEGERS;
30 if constexpr (std::is_signed_v<TT>)
32 this->g_data._i =
static_cast<fge::PintType
>(val);
33 this->g_isSigned =
true;
37 this->g_data._u =
static_cast<fge::PuintType
>(val);
38 this->g_isSigned =
false;
41 else if constexpr (std::is_floating_point_v<TT>)
43 if constexpr (std::is_same_v<TT, float>)
45 this->g_type = Types::PTYPE_FLOAT;
46 this->g_data._f = val;
50 this->g_type = Types::PTYPE_DOUBLE;
51 this->g_data._d =
static_cast<double>(val);
54 else if constexpr (std::is_same_v<TT, std::string>)
56 this->g_type = Types::PTYPE_STRING;
57 this->g_data._ptr =
new std::string(std::forward<T>(val));
59 else if constexpr (std::is_pointer_v<TT>)
61 this->g_type = Types::PTYPE_POINTER;
62 this->g_data._ptr = val;
66 this->g_type = Types::PTYPE_CLASS;
71template<
class T,
typename>
74 this->set(std::forward<T>(val));
81 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
83 if (this->g_type != Types::PTYPE_INTEGERS)
86 this->g_type = Types::PTYPE_INTEGERS;
89 if constexpr (std::is_signed_v<T>)
91 this->g_isSigned =
true;
92 return this->g_data._i;
96 this->g_isSigned =
true;
97 return this->g_data._u;
100 else if constexpr (std::is_floating_point_v<T>)
102 if constexpr (std::is_same_v<T, float>)
104 if (this->g_type != Types::PTYPE_FLOAT)
107 this->g_type = Types::PTYPE_FLOAT;
110 return this->g_data._f;
114 if (this->g_type != Types::PTYPE_DOUBLE)
117 this->g_type = Types::PTYPE_DOUBLE;
120 return this->g_data._d;
123 else if constexpr (std::is_same_v<T, std::string>)
125 if (this->g_type != Types::PTYPE_STRING)
128 this->g_type = Types::PTYPE_STRING;
129 this->g_data._ptr =
new std::string();
132 return *this->g_data.getString();
134 else if constexpr (std::is_pointer_v<T>)
136 if (this->g_type != Types::PTYPE_POINTER)
139 this->g_type = Types::PTYPE_POINTER;
142 return reinterpret_cast<std::add_lvalue_reference_t<T>
>(this->g_data._ptr);
146 using TT = remove_cvref_t<T>;
148 if (this->g_type != Types::PTYPE_CLASS)
151 this->g_type = Types::PTYPE_CLASS;
153 return this->g_data.getClassWrapper<TT>()->_data;
156 if (this->g_data.getClassWrapper()->getType() ==
typeid(T))
158 return this->g_data.getClassWrapper<TT>()->_data;
162 this->g_type = Types::PTYPE_CLASS;
164 return this->g_data.getClassWrapper<TT>()->_data;
169bool Property::isType()
const
171 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
173 return this->g_type == Types::PTYPE_INTEGERS;
175 else if constexpr (std::is_floating_point_v<T>)
177 if constexpr (std::is_same_v<T, float>)
179 return this->g_type == Types::PTYPE_FLOAT;
183 return this->g_type == Types::PTYPE_DOUBLE;
186 else if constexpr (std::is_same_v<T, std::string>)
188 return this->g_type == Types::PTYPE_STRING;
190 else if constexpr (std::is_pointer_v<T>)
192 return this->g_type == Types::PTYPE_POINTER;
196 if (this->g_type == Types::PTYPE_CLASS)
198 return this->g_data.getClassWrapper()->getType() ==
typeid(T);
204template<
class T,
typename>
205bool Property::set(T&& val)
207 using TT = remove_cvref_t<T>;
209 if constexpr (std::is_integral_v<TT> || std::is_enum_v<TT>)
211 if (this->g_type != Types::PTYPE_INTEGERS)
213 if (this->g_type == Types::PTYPE_NULL)
215 this->g_type = Types::PTYPE_INTEGERS;
223 if constexpr (std::is_signed_v<TT>)
225 this->g_data._i =
static_cast<fge::PintType
>(val);
226 this->g_isSigned =
true;
231 this->g_data._u =
static_cast<fge::PuintType
>(val);
232 this->g_isSigned =
false;
236 else if constexpr (std::is_floating_point_v<TT>)
238 if constexpr (std::is_same_v<TT, float>)
240 if (this->g_type != Types::PTYPE_FLOAT)
242 if (this->g_type == Types::PTYPE_NULL)
244 this->g_type = Types::PTYPE_FLOAT;
252 this->g_data._f = val;
257 if (this->g_type != Types::PTYPE_DOUBLE)
259 if (this->g_type == Types::PTYPE_NULL)
261 this->g_type = Types::PTYPE_DOUBLE;
269 this->g_data._d =
static_cast<double>(val);
273 else if constexpr (std::is_same_v<TT, std::string>)
275 if (this->g_type != Types::PTYPE_STRING)
277 if (this->g_type == Types::PTYPE_NULL)
279 this->g_type = Types::PTYPE_STRING;
280 this->g_data._ptr =
new std::string(std::forward<T>(val));
286 *this->g_data.getString() = std::forward<T>(val);
289 else if constexpr (std::is_pointer_v<TT>)
291 if (this->g_type != Types::PTYPE_POINTER)
293 if (this->g_type == Types::PTYPE_NULL)
295 this->g_type = Types::PTYPE_POINTER;
303 this->g_data._ptr = val;
308 if (this->g_type != Types::PTYPE_CLASS)
310 if (this->g_type == Types::PTYPE_NULL)
312 this->g_type = Types::PTYPE_CLASS;
319 if (this->g_data.getClassWrapper()->getType() ==
typeid(TT))
321 this->g_data.getClassWrapper<TT>()->_data = std::forward<T>(val);
329bool Property::get(T& val)
const
331 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
333 if (this->g_type != Types::PTYPE_INTEGERS)
335 if (this->g_type == Types::PTYPE_FLOAT)
337 val =
static_cast<T
>(this->g_data._f);
340 if (this->g_type == Types::PTYPE_DOUBLE)
342 val =
static_cast<T
>(this->g_data._d);
348 if constexpr (std::is_signed_v<T>)
350 val =
static_cast<T
>(this->g_data._i);
355 val =
static_cast<T
>(this->g_data._u);
359 else if constexpr (std::is_floating_point_v<T>)
361 if constexpr (std::is_same_v<T, float>)
363 if (this->g_type != Types::PTYPE_FLOAT)
365 if (this->g_type == Types::PTYPE_INTEGERS)
367 if (this->g_isSigned)
369 val =
static_cast<T
>(this->g_data._i);
372 val =
static_cast<T
>(this->g_data._u);
375 if (this->g_type == Types::PTYPE_DOUBLE)
377 val =
static_cast<T
>(this->g_data._d);
383 val =
static_cast<T
>(this->g_data._f);
388 if (this->g_type != Types::PTYPE_DOUBLE)
390 if (this->g_type == Types::PTYPE_INTEGERS)
392 if (this->g_isSigned)
394 val =
static_cast<T
>(this->g_data._i);
397 val =
static_cast<T
>(this->g_data._u);
400 if (this->g_type == Types::PTYPE_FLOAT)
402 val =
static_cast<T
>(this->g_data._f);
408 val =
static_cast<T
>(this->g_data._d);
412 else if constexpr (std::is_same_v<T, std::string>)
414 if (this->g_type != Types::PTYPE_STRING)
419 val = *this->g_data.getString();
422 else if constexpr (std::is_same_v<T, char const*>)
424 if (this->g_type != Types::PTYPE_STRING)
429 val = this->g_data.getString()->data();
432 else if constexpr (std::is_pointer_v<T>)
434 if (this->g_type != Types::PTYPE_POINTER)
439 val =
reinterpret_cast<T
>(this->g_data._ptr);
444 if (this->g_type == Types::PTYPE_CLASS)
446 if (this->g_data.getClassWrapper()->getType() ==
typeid(T))
448 using TT = remove_cvref_t<T>;
449 val = this->g_data.getClassWrapper<TT>()->_data;
458std::optional<T> Property::get()
const
460 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
462 if (this->g_type != Types::PTYPE_INTEGERS)
464 if (this->g_type == Types::PTYPE_FLOAT)
466 return static_cast<T
>(this->g_data._f);
468 if (this->g_type == Types::PTYPE_DOUBLE)
470 return static_cast<T
>(this->g_data._d);
475 if constexpr (std::is_signed_v<T>)
477 return static_cast<T
>(this->g_data._i);
481 return static_cast<T
>(this->g_data._u);
484 else if constexpr (std::is_floating_point_v<T>)
486 if constexpr (std::is_same_v<T, float>)
488 if (this->g_type != Types::PTYPE_FLOAT)
490 if (this->g_type == Types::PTYPE_INTEGERS)
492 if (this->g_isSigned)
494 return static_cast<T
>(this->g_data._i);
496 return static_cast<T
>(this->g_data._u);
498 if (this->g_type == Types::PTYPE_DOUBLE)
500 return static_cast<T
>(this->g_data._d);
505 return static_cast<T
>(this->g_data._f);
509 if (this->g_type != Types::PTYPE_DOUBLE)
511 if (this->g_type == Types::PTYPE_INTEGERS)
513 if (this->g_isSigned)
515 return static_cast<T
>(this->g_data._i);
517 return static_cast<T
>(this->g_data._u);
519 if (this->g_type == Types::PTYPE_FLOAT)
521 return static_cast<T
>(this->g_data._f);
526 return static_cast<T
>(this->g_data._d);
529 else if constexpr (std::is_same_v<T, std::string>)
531 if (this->g_type != Types::PTYPE_STRING)
536 return *this->g_data.getString();
538 else if constexpr (std::is_same_v<T, char const*>)
540 if (this->g_type != Types::PTYPE_STRING)
545 return this->g_data.getString()->data();
547 else if constexpr (std::is_pointer_v<T>)
549 if (this->g_type != Types::PTYPE_POINTER)
554 return reinterpret_cast<T
>(this->g_data._ptr);
558 if (this->g_type == Types::PTYPE_CLASS)
560 if (this->g_data.getClassWrapper()->getType() ==
typeid(T))
562 using TT = remove_cvref_t<T>;
563 return this->g_data.getClassWrapper<TT>()->_data;
574 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
576 if constexpr (
sizeof(T) !=
sizeof(fge::PintType))
581 if (this->g_type != Types::PTYPE_INTEGERS)
586 if constexpr (std::is_signed_v<T>)
588 return static_cast<T*
>(&this->g_data._i);
592 return static_cast<T*
>(&this->g_data._u);
595 else if constexpr (std::is_floating_point_v<T>)
597 if constexpr (std::is_same_v<T, float>)
599 if (this->g_type != Types::PTYPE_FLOAT)
604 return &this->g_data._f;
608 if (this->g_type != Types::PTYPE_DOUBLE)
613 return &this->g_data._d;
616 else if constexpr (std::is_same_v<T, std::string>)
618 if (this->g_type != Types::PTYPE_STRING)
623 return this->g_data.getString();
625 else if constexpr (std::is_pointer_v<T>)
627 if (this->g_type != Types::PTYPE_POINTER)
632 return &
reinterpret_cast<T&
>(this->g_data._ptr);
636 if (this->g_type == Types::PTYPE_CLASS)
638 if (this->g_data.getClassWrapper()->getType() ==
typeid(T))
640 using TT = remove_cvref_t<T>;
641 return &this->g_data.getClassWrapper<TT>()->_data;
649T
const* Property::getPtr()
const
651 if constexpr (std::is_integral_v<T> || std::is_enum_v<T>)
653 if constexpr (
sizeof(T) !=
sizeof(fge::PintType))
658 if (this->g_type != Types::PTYPE_INTEGERS)
663 if constexpr (std::is_signed_v<T>)
665 return static_cast<T*
>(&this->g_data._i);
669 return static_cast<T*
>(&this->g_data._u);
672 else if constexpr (std::is_floating_point_v<T>)
674 if constexpr (std::is_same_v<T, float>)
676 if (this->g_type != Types::PTYPE_FLOAT)
681 return &this->g_data._f;
685 if (this->g_type != Types::PTYPE_DOUBLE)
690 return &this->g_data._d;
693 else if constexpr (std::is_same_v<T, std::string>)
695 if (this->g_type != Types::PTYPE_STRING)
700 return this->g_data.getString();
702 else if constexpr (std::is_pointer_v<T>)
704 if (this->g_type != Types::PTYPE_POINTER)
709 return &
reinterpret_cast<T&
>(this->g_data._ptr);
713 if (this->g_type == Types::PTYPE_CLASS)
715 if (this->g_data.getClassWrapper()->getType() ==
typeid(T))
717 using TT = remove_cvref_t<T>;
718 return &this->g_data.getClassWrapper<TT>()->_data;
727bool Property::pushType()
729 if (this->g_type == Types::PTYPE_CLASS)
731 if (this->g_data.getClassWrapper()->getType() ==
typeid(fge::ParrayType))
733 this->g_data.getArray()->_data.emplace_back().setType<T>();
741bool Property::getData(std::size_t index, T& val)
const
743 if (this->g_type == Types::PTYPE_CLASS)
745 if (this->g_data.getClassWrapper()->getType() ==
typeid(fge::ParrayType))
747 if (this->g_data.getArray()->_data.size() > index)
749 return this->g_data.getArray()->_data[index].get<T>(val);
756T* Property::getDataPtr(std::size_t index)
758 if (this->g_type == Types::PTYPE_CLASS)
760 if (this->g_data.getClassWrapper()->getType() ==
typeid(fge::ParrayType))
762 if (this->g_data.getArray()->_data.size() > index)
764 return this->g_data.getArray()->_data[index].getPtr<T>();
771T
const* Property::getDataPtr(std::size_t index)
const
773 if (this->g_type == Types::PTYPE_CLASS)
775 if (this->g_data.getClassWrapper()->getType() ==
typeid(fge::ParrayType))
777 if (this->g_data.getArray()->_data.size() > index)
779 return this->g_data.getArray()->_data[index].getPtr<T>();
790PropertyClassWrapperType<T>::PropertyClassWrapperType(T
const& val) :
795PropertyClassWrapperType<T>::PropertyClassWrapperType(T&& val) noexcept :
800std::type_info
const& PropertyClassWrapperType<T>::getType()
const
806std::string PropertyClassWrapperType<T>::toString()
const
808 if constexpr (std::is_same_v<T, fge::ParrayType>)
814 return typeid(T).name();
827 if (val->getType() ==
typeid(T))
838 if (val->getType() ==
typeid(T))
840 if constexpr (comparisonCheck::EqualExists<T>::value)
Definition C_property.hpp:241
Definition C_property.hpp:206
A class that can store any type of data.
Definition C_property.hpp:54