ActiveLib
Loading...
Searching...
No Matches
DoubleValue.h
1
6#ifndef ACTIVE_SETTING_DOUBLE_VALUE
7#define ACTIVE_SETTING_DOUBLE_VALUE
8
9#include "Active/Setting/Values/ValueBase.h"
10#include "Active/Utility/MathFunctions.h"
11
12namespace active::setting {
13
16
17 // MARK: - Operators
18
24 template<> inline
25 Value& DoubleValue::operator=(bool val) {
26 data = val ? 1.0 : 0.0;
27 status = good;
28 return *this;
29 }
35 template<> inline
36 Value& DoubleValue::operator=(int32_t val) {
37 data = static_cast<double>(val);
38 status = good;
39 return *this;
40 }
46 template<> inline
47 Value& DoubleValue::operator=(uint32_t val) {
48 data = static_cast<double>(val);
49 status = good;
50 return *this;
51 }
57 template<> inline
58 Value& DoubleValue::operator=(int64_t val) {
59 data = static_cast<double>(val);
60 status = good;
61 return *this;
62 }
68 template<> inline
69 Value& DoubleValue::operator=(double val) {
70 data = val;
71 status = good;
72 return *this;
73 }
79 template<> inline
80 Value& DoubleValue::operator=(const utility::String& val) {
81 if (auto doubleValue = val.toDouble(); doubleValue) {
82 data = *doubleValue;
83 status = good;
84 } else
85 status = bad;
86 return *this;
87 }
93 template<> inline
94 Value& DoubleValue::operator=(const char* val) {
95 return operator=(utility::String{val});
96 }
102 template<> inline
103 Value& DoubleValue::operator=(const utility::Time& val) {
104 data = static_cast<double>(val.secondsSince1970()) + (static_cast<double>(val.microsecond()) / 1e6);
105 status = good;
106 return *this;
107 }
108
109 // MARK: - Conversion operators
110
115 template<> inline
116 DoubleValue::operator bool() const { return !math::isZero(data); }
121 template<> inline
122 DoubleValue::operator int32_t() const { return static_cast<int32_t>(data); }
127 template<> inline
128 DoubleValue::operator uint32_t() const { return static_cast<uint32_t>(data); }
133 template<> inline
134 DoubleValue::operator int64_t() const { return static_cast<int64_t>(data); }
139 template<> inline
140 DoubleValue::operator double() const { return data; }
145 template<> inline
146 DoubleValue::operator utility::String() const { return utility::String{data}; }
151 template<> inline
152 DoubleValue::operator utility::Time() const { return utility::Time{data}; }
153
154 // MARK: - Functions (const)
155
160 template<> inline
161 bool DoubleValue::isNull() const { return !math::isZero(data); }
166 template<> inline
167 Value::Type DoubleValue::getType() const { return floatType; };
168
169}
170
171#endif //ACTIVE_SETTING_DOUBLE_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
Definition Transportable.h:13