-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.cpp
93 lines (75 loc) · 1.54 KB
/
object.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
namespace tokox::json
{
object::object(): actual_object()
{}
object::object(const object& o): actual_object(o.get_any())
{}
object::object(const std::any& v): actual_object(v)
{}
template<object_type T>
object::object(const T& v) : actual_object(v)
{
if constexpr (std::is_same_v<T, std::nullptr_t>)
this->actual_object.reset();
}
object& object::operator=(const object& o)
{
this->actual_object = o.get_any();
return (*this);
}
object& object::operator=(const std::any& v)
{
this->actual_object = v;
return (*this);
}
template<object_type T>
object& object::operator=(const T& v)
{
if constexpr (std::is_same_v<T, std::nullptr_t>)
this->actual_object.reset();
else
this->actual_object = v;
return (*this);
}
const std::any& object::get_any() const
{
return actual_object;
}
object::operator std::any() const
{
return this->get_any();
}
value_type object::get_value_type() const
{
return any_to_value_type(this->actual_object);
}
object::operator value_type() const
{
return this->get_value_type();
}
template<object_type T>
T& object::get_value()
{
return *std::any_cast<T>(&this->actual_object);
}
template<object_type T>
const T& object::object::get_value() const
{
return *std::any_cast<T>(&this->actual_object);
}
template<object_type T>
object::operator T() const
{
return this->get_value<T>();
}
template<value_type V>
auto& object::get_value()
{
return this->get_value<object_type_from_value_type<V>>();
}
template<value_type V>
const auto& object::get_value() const
{
return this->get_value<object_type_from_value_type<V>>();
}
}