ActiveLib
Loading...
Searching...
No Matches
UInt32Value.h
1
6#ifndef ACTIVE_SETTING_UINT32_VALUE
7#define ACTIVE_SETTING_UINT32_VALUE
8
9#include "Active/Setting/Values/ValueBase.h"
10
11namespace active::setting {
12
15
16 // MARK: - Operators
17
23 template<> inline
24 Value& UInt32Value::operator=(bool val) {
25 data = val ? 1 : 0;
26 return *this;
27 }
33 template<> inline
34 Value& UInt32Value::operator=(int32_t val) {
35 data = static_cast<uint32_t>(val);
36 return *this;
37 }
43 template<> inline
44 Value& UInt32Value::operator=(uint32_t val) {
45 data = val;
46 return *this;
47 }
53 template<> inline
54 Value& UInt32Value::operator=(int64_t val) {
55 data = static_cast<uint32_t>(val);
56 return *this;
57 }
63 template<> inline
64 Value& UInt32Value::operator=(double val) {
65 data = static_cast<uint32_t>(math::round(val, 1.0));
66 return *this;
67 }
73 template<> inline
74 Value& UInt32Value::operator=(const utility::String& val) {
75 if (auto intValue = val.toInt32(); intValue)
76 data = *intValue;
77 else
78 status = bad;
79 return *this;
80 }
86 template<> inline
87 Value& UInt32Value::operator=(const utility::Time& val) {
88 data = static_cast<uint32_t>(val.secondsSince1970());
89 return *this;
90 }
91
92 // MARK: - Conversion operators
93
98 template<> inline
99 UInt32Value::operator bool() const { return (data != 0); }
104 template<> inline
105 UInt32Value::operator int32_t() const { return static_cast<uint32_t>(data); }
110 template<> inline
111 UInt32Value::operator uint32_t() const { return data; }
116 template<> inline
117 UInt32Value::operator int64_t() const { return data; }
122 template<> inline
123 UInt32Value::operator double() const { return data; }
128 template<> inline
129 UInt32Value::operator utility::String() const { return utility::String{data}; }
134 template<> inline
135 UInt32Value::operator utility::Time() const { return utility::Time{static_cast<int64_t>(data)}; }
136
137 // MARK: - Functions (const)
138
143 template<> inline
144 bool UInt32Value::isNull() const { return (data != 0); }
149 template<> inline
150 Value::Type UInt32Value::getType() const { return intType; };
151
152}
153
154#endif //ACTIVE_SETTING_UINT32_VALUE
Definition ValueBase.h:21
virtual bool isNull() const override
Definition ValueBase.h:193
virtual Value & operator=(const Value &val) override
Definition ValueBase.h:85
T data
The value data.
Definition ValueBase.h:58
virtual Type getType() const override
Definition ValueBase.h:198
Definition Value.h:31
Type
Supported value types (broad groups, e.g. int32_t and int64_t are both intType)
Definition Value.h:51
Status status
The value status.
Definition Value.h:100
double round(const double &val, double module=eps)
Rounding functions.
Definition MathFunctions.h:160
Definition Transportable.h:13