ActiveLib
Loading...
Searching...
No Matches
StringValue.h
1
6#ifndef ACTIVE_SETTING_STRING_VALUE
7#define ACTIVE_SETTING_STRING_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& StringValue::operator=(bool val) {
26 data = val ? "true" : "false";
27 return *this;
28 }
34 template<> inline
35 Value& StringValue::operator=(int32_t val) {
36 data = utility::String{val};
37 return *this;
38 }
44 template<> inline
45 Value& StringValue::operator=(uint32_t val) {
46 data = utility::String{val};
47 return *this;
48 }
54 template<> inline
55 Value& StringValue::operator=(int64_t val) {
56 data = utility::String{val};
57 return *this;
58 }
64 template<> inline
65 Value& StringValue::operator=(double val) {
66 data = utility::String{val};
67 return *this;
68 }
74 template<> inline
75 Value& StringValue::operator=(const utility::String& val) {
76 data = val;
77 return *this;
78 }
84 template<> inline
85 Value& StringValue::operator=(const utility::Guid& val) {
86 data = val;
87 return *this;
88 }
94 template<> inline
95 Value& StringValue::operator=(const utility::Time& val) {
96 data.clear();
97 utility::Time temp{val};
98 serialise::xml::XMLDateTime{temp}.write(data);
99 return *this;
100 }
101
102 // MARK: - Conversion operators
103
108 template<> inline
109 StringValue::operator bool() const { return ((data == "true") || (data == "1")); }
114 template<> inline
115 StringValue::operator int32_t() const { return data.operator int32_t(); }
120 template<> inline
121 StringValue::operator uint32_t() const { return data.operator uint32_t(); }
126 template<> inline
127 StringValue::operator int64_t() const { return data.operator int64_t(); }
132 template<> inline
133 StringValue::operator double() const { return data.operator double(); }
138 template<> inline
139 StringValue::operator utility::String() const { return data; }
144 template<> inline
145 StringValue::operator utility::Guid() const { return utility::Guid{data}; }
150 template<> inline
151 StringValue::operator utility::Time() const {
152 //First attempt to read the time as xs:dateTime format
153 utility::Time time;
154 serialise::xml::XMLDateTime xmlParser{time};
155 if (xmlParser.read(data))
156 return time;
157 //Otherwise attempt to convert as seconds from 1970
158 if (auto seconds = data.toInt64(); seconds)
159 return utility::Time{*seconds};
160 return utility::Time{};
161 }
162
163 // MARK: - Functions (const)
164
169 template<> inline
170 bool StringValue::isNull() const { return !data.empty(); }
175 template<> inline
176 Value::Type StringValue::getType() const { return stringType; };
177
178}
179
180#endif //ACTIVE_SETTING_STRING_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
A Unicode-aware string class.
Definition String.h:51
Definition Transportable.h:13