ActiveLib
Loading...
Searching...
No Matches
TimeValue.h
1
6#ifndef ACTIVE_SETTING_TIME_VALUE
7#define ACTIVE_SETTING_TIME_VALUE
8
9#include "Active/Setting/Values/ValueBase.h"
10#include "Active/Serialise/XML/Item/XMLDateTime.h"
11
12namespace active::setting {
13
16
17 // MARK: - Operators
18
24 template<> inline
25 Value& TimeValue::operator=(int32_t val) {
26 data.setSecondsSince1970(val);
27 return *this;
28 }
34 template<> inline
35 Value& TimeValue::operator=(uint32_t val) {
36 data.setSecondsSince1970(val);
37 return *this;
38 }
44 template<> inline
45 Value& TimeValue::operator=(int64_t val) {
46 data.setSecondsSince1970(static_cast<int32_t>(val));
47 return *this;
48 }
54 template<> inline
55 Value& TimeValue::operator=(double val) {
56 data.setSecondsSince1970(static_cast<int32_t>(val));
57 data.setMicrosecond(static_cast<uint32_t>(1e6 * fmod(val, 1.0)));
58 return *this;
59 }
65 template<> inline
66 Value& TimeValue::operator=(const utility::String& val) {
67 utility::Time time;
68 serialise::xml::XMLDateTime xmlParser{time};
69 if (xmlParser.read(val))
70 data = time;
71 else
72 status = bad;
73 return *this;
74 }
80 template<> inline
81 Value& TimeValue::operator=(const utility::Time& val) {
82 data = val;
83 return *this;
84 }
85
86 // MARK: - Conversion operators
87
92 template<> inline
93 TimeValue::operator bool() const { return false; }
98 template<> inline
99 TimeValue::operator int32_t() const { return static_cast<int32_t>(data.secondsSince1970()); }
104 template<> inline
105 TimeValue::operator uint32_t() const { return static_cast<uint32_t>(data.secondsSince1970()); }
110 template<> inline
111 TimeValue::operator int64_t() const { return static_cast<int64_t>(data.secondsSince1970()); }
116 template<> inline
117 TimeValue::operator double() const { return static_cast<double>(data.secondsSince1970()) + (static_cast<double>(data.microsecond()) / 1e6); }
122 template<> inline
123 TimeValue::operator utility::String() const {
124 utility::String string;
125 utility::Time temp{data};
126 serialise::xml::XMLDateTime{temp}.write(string);
127 return string;
128
129 }
134 template<> inline
135 TimeValue::operator utility::Time() const {
136 return data;
137 }
138
139 // MARK: - Functions (const)
140
145 template<> inline
146 bool TimeValue::isNull() const { return false; }
151 template<> inline
152 Value::Type TimeValue::getType() const { return timeType; };
153
154}
155
156#endif //ACTIVE_SETTING_TIME_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