Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
PropertyValue.inl
1// INFINITY_API_PUBLIC
2
3#pragma once
4
6{
7 template<typename T>
8 class Value;
9
10 template<typename T, typename>
12 {
13 using DecayT = std::decay_t<T>;
14
15 if constexpr (std::is_base_of_v<Data, DecayT>)
16 {
17 _type = DATA;
18 as_object = new DecayT(std::forward<T>(v));
19 } else {
20 _type = DATA;
21 as_object = new Value<DecayT>(std::forward<T>(v));
22 }
23 }
24
25 template<typename T>
27 {
28 using DecayT = std::decay_t<T>;
29
30 if constexpr (std::is_same_v<DecayT, bool>) {
31 return _type == BOOL ? &as_bool : nullptr;
32 } else if constexpr (std::is_same_v<DecayT, int>) {
33 return _type == INT ? &as_int : nullptr;
34 } else if constexpr (std::is_same_v<DecayT, float>) {
35 return _type == FLOAT ? &as_float : nullptr;
36 } else if constexpr (std::is_same_v<DecayT, double>) {
37 return _type == DOUBLE ? &as_double : nullptr;
38 } else if constexpr (std::is_base_of_v<Data, DecayT>) {
39 return _type == DATA ? dynamic_cast<DecayT*>(as_object) : nullptr;
40 } else {
41 if (_type != DATA) return nullptr;
42 if (auto* value_wrapper = dynamic_cast<Value<DecayT>*>(as_object))
43 {
44 return &value_wrapper->get();
45 }
46 return nullptr;
47 }
48 }
49
50 template<typename T>
51 const T* PropertyValue::as() const
52 {
53 using DecayT = std::decay_t<T>;
54
55 if constexpr (std::is_same_v<DecayT, bool>) {
56 return _type == BOOL ? &as_bool : nullptr;
57 } else if constexpr (std::is_same_v<DecayT, int>) {
58 return _type == INT ? &as_int : nullptr;
59 } else if constexpr (std::is_same_v<DecayT, float>) {
60 return _type == FLOAT ? &as_float : nullptr;
61 } else if constexpr (std::is_same_v<DecayT, double>) {
62 return _type == DOUBLE ? &as_double : nullptr;
63 } else if constexpr (std::is_base_of_v<Data, DecayT>) {
64 return _type == DATA ? dynamic_cast<const DecayT*>(as_object) : nullptr;
65 } else {
66 if (_type != DATA) return nullptr;
67 if (const auto* value_wrapper = dynamic_cast<const Value<DecayT>*>(as_object))
68 {
69 return &value_wrapper->get();
70 }
71 return nullptr;
72 }
73 }
74}
int as_int
Definition PropertyValue.hpp:30
@ DOUBLE
Definition PropertyValue.hpp:21
@ BOOL
Definition PropertyValue.hpp:18
@ FLOAT
Definition PropertyValue.hpp:20
@ DATA
Definition PropertyValue.hpp:22
@ INT
Definition PropertyValue.hpp:19
bool as_bool
Definition PropertyValue.hpp:29
float as_float
Definition PropertyValue.hpp:31
double as_double
Definition PropertyValue.hpp:32
Data * as_object
Definition PropertyValue.hpp:33
T * as()
Definition PropertyValue.inl:26
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
Definition Base.hpp:12