Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Value.inl
1// INFINITY_API_PUBLIC
2
3#pragma once
4
6{
7 template<typename T>
9 : _val()
10 { }
11
12 template<typename T>
14 : _val(value)
15 { }
16
17 template<typename T>
18 template<typename... Args>
19 Value<T>::Value(Args&&... args)
20 : _val(std::forward<Args>(args)...)
21 { }
22
23 template<typename T>
26
27 template<typename T>
28 std::unique_ptr<Base> Value<T>::clone() const
29 {
30 return std::make_unique<Value<T>>(*this);
31 }
32
33 template<typename T>
35 {
36 return _val;
37 }
38
39 template <typename T>
40 Value<T>::operator const T&() const
41 {
42 return _val;
43 }
44
45 template<typename T>
47 {
48 _val = rhs._val;
49 return *this;
50 }
51
52 template<typename T>
54 {
55 _val = rhs;
56 return *this;
57 }
58
59 template<typename T>
61 {
62 return _val;
63 }
64
65 template<typename T>
66 const T& Value<T>::get() const
67 {
68 return _val;
69 }
70
71 template<typename T>
72 void Value<T>::set(const T& value)
73 {
74 _val = value;
75 }
76
77 template<typename T>
78 size_t Value<T>::size() const
79 {
80 if constexpr (std::is_same_v<T, std::string>)
81 {
82 return sizeof(size_t) + _val.size();
83 } else {
84 return sizeof(T);
85 }
86 }
87
88 template<typename T>
89 std::istream& Value<T>::legibleDataRead(std::istream& in)
90 {
91 if constexpr (std::is_same_v<T, std::string>)
92 {
93 std::getline(in, _val, '\0');
94 } else if constexpr (std::is_same_v<T, bool>) {
95 std::string s;
96 in >> s;
97 std::transform(s.begin(), s.end(), s.begin(), ::tolower);
98
99 if (s == "true" || s == "1" || s == "yes" || s == "on")
100 {
101 _val = true;
102 } else if (s == "false" || s == "0" || s == "no" || s == "off") {
103 _val = false;
104 } else {
105 in.setstate(std::ios::failbit);
106 }
107 } else {
108 in >> _val;
109 }
110 return in;
111 }
112
113 template<typename T>
114 std::ostream& Value<T>::legibleDataWrite(std::ostream& out) const
115 {
116 out << _val;
117 return out;
118 }
119
120 template<typename T>
122 {
123 return Infinity::Types::getTypeID<Value<T>>();
124 }
125
126}
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
size_t size() const
Gets the size of the underlying value in bytes.
Definition Value.inl:78
virtual const Infinity::Types::TypeID & typeId() const override
Gets the runtime type identifier for this Value<T> specialization.
Definition Value.inl:121
void set(const T &value)
Sets the underlying value.
Definition Value.inl:72
T & get()
Gets a mutable reference to the underlying value.
Definition Value.inl:60
virtual ~Value()
Virtual destructor.
Definition Value.inl:24
virtual std::istream & legibleDataRead(std::istream &in) override
Reads the Value from a single-line text representation.
Definition Value.inl:89
std::unique_ptr< Base > clone() const override
Definition Value.inl:28
virtual std::ostream & legibleDataWrite(std::ostream &out) const override
Writes the Value to a single-line text representation.
Definition Value.inl:114
Value & operator=(const Value &rhs)
Copy assignment from another Value.
Definition Value.inl:46
Value()
Default constructor.
Definition Value.inl:8
Definition Base.hpp:12
Definition Span.hpp:599
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71