ActiveLib
Loading...
Searching...
No Matches
BoolValue.h
1
6#ifndef ACTIVE_SETTING_BOOL_VALUE
7#define ACTIVE_SETTING_BOOL_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& BoolValue::operator=(bool val) {
26 data = val;
27 return *this;
28 }
34 template<> inline
35 Value& BoolValue::operator=(int32_t val) {
36 data = (val != 0);
37 return *this;
38 }
44 template<> inline
45 Value& BoolValue::operator=(uint32_t val) {
46 data = (val != 0);
47 return *this;
48 }
54 template<> inline
55 Value& BoolValue::operator=(int64_t val) {
56 data = (val != 0);
57 return *this;
58 }
64 template<> inline
65 Value& BoolValue::operator=(double val) {
66 data = !math::isZero(val);
67 return *this;
68 }
74 template<> inline
75 Value& BoolValue::operator=(const utility::String& val) {
76 if ((val.lowercase() == "true") || (val.lowercase() == "1"))
77 data = true;
78 else if ((val.lowercase() == "false") || (val.lowercase() == "0"))
79 data = false;
80 else {
81 status = bad;
82 }
83 return *this;
84 }
90 template<> inline
91 Value& BoolValue::operator=(const utility::Guid& val) {
92 data = val;
93 return *this;
94 }
95
96 // MARK: - Conversion operators
97
102 template<> inline
103 BoolValue::operator bool() const { return data; }
108 template<> inline
109 BoolValue::operator int32_t() const { return data ? 1 : 0; }
114 template<> inline
115 BoolValue::operator uint32_t() const { return data ? 1 : 0; }
120 template<> inline
121 BoolValue::operator int64_t() const { return data ? 1 : 0; }
126 template<> inline
127 BoolValue::operator double() const { return data ? 1.0 : 0.0; }
132 template<> inline
133 BoolValue::operator utility::String() const { return data ? "true" : "false"; }
134
135 // MARK: - Functions (const)
136
141 template<> inline
142 bool BoolValue::isNull() const { return !data; }
147 template<> inline
148 Value::Type BoolValue::getType() const { return boolType; };
149
150}
151
152#endif //ACTIVE_SETTING_BOOL_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