ActiveLib
Loading...
Searching...
No Matches
ValueBase.h
1
6#ifndef ACTIVE_SETTING_VALUE_BASE
7#define ACTIVE_SETTING_VALUE_BASE
8
9#include "Active/Setting/Values/Value.h"
10
11#include <type_traits>
12
13namespace active::setting {
14
20 template<class T>
21 class ValueBase : public Value {
22 public:
23
24 // MARK: - Constructors
25
29 ValueBase() : Value(undefined) {}
35 ValueBase(const T& val, Status stat = good) : Value(stat) { data = val; }
40 ValueBase(const Value& value) { data = value; }
45 ValueBase(const utility::String& stringVal) requires (!std::is_same<T, utility::String>::value) : Value(bad) { *this = stringVal; }
46
47 ValueBase(const ValueBase& source) = default;
48
53 virtual Value* clonePtr() const override { return new ValueBase<T>{*this}; };
54
55 // MARK: - Public variables
56
58 T data = T();
59
60 // MARK: - Operators
61
67 virtual bool operator==(const Value& ref) const override { return data == ref.operator T(); }
73 bool operator!=(const Value& ref) const { return !((*this) == ref); }
79 virtual bool operator<(const Value& ref) const override { return data < ref.operator T(); }
85 virtual Value& operator=(const Value& val) override {
86 data = val;
87 return *this;
88 }
94 virtual Value& operator=(bool val) override { status = bad; return *this; }
100 virtual Value& operator=(int32_t val) override { status = bad; return *this; }
106 virtual Value& operator=(uint32_t val) override { status = bad; return *this; }
112 virtual Value& operator=(int64_t val) override { status = bad; return *this; }
118 virtual Value& operator=(double val) override { status = bad; return *this; }
124 virtual Value& operator=(const active::utility::String& val) override { status = bad; return *this; }
130 virtual Value& operator=(const char* val) override { return Value::operator=(val); }
136 virtual Value& operator=(const active::utility::Guid& val) override { status = bad; return *this; }
142 virtual Value& operator=(const active::utility::Time& val) override { status = bad; return *this; }
143
144 // MARK: - Conversion operators
145
150 virtual operator bool() const override { return false; }
155 virtual operator int32_t() const override { return 0; }
160 virtual operator uint32_t() const override { return 0; }
165 virtual operator int64_t() const override { return 0; }
170 virtual operator double() const override { return 0.0; }
175 virtual operator active::utility::String() const override { return active::utility::String{}; }
180 virtual operator active::utility::Guid() const override { return active::utility::Guid{}; }
185 virtual operator active::utility::Time() const override { return active::utility::Time{}; }
186
187 // MARK: - Functions (const)
188
193 virtual bool isNull() const override { return data == T{}; }
198 virtual Type getType() const override { return null; }
199
200 // MARK: - Functions (mutating)
201
203 virtual void setDefault() override { data = T{}; }
204 };
205
206 //template<> inline
207 //Item::Type ValueWrap<utility::String>::type() const { return Item::Type::text; }
208
209 template<> inline
211 data = val.operator utility::Guid();
212 return *this;
213 }
214
215
216}
217
218#endif //ACTIVE_SETTING_VALUE_BASE
Definition ValueBase.h:21
virtual bool isNull() const override
Definition ValueBase.h:193
virtual Value & operator=(const char *val) override
Definition ValueBase.h:130
virtual Value & operator=(uint32_t val) override
Definition ValueBase.h:106
virtual Value * clonePtr() const override
Definition ValueBase.h:53
virtual Value & operator=(const Value &val) override
Definition ValueBase.h:85
virtual bool operator<(const Value &ref) const override
Definition ValueBase.h:79
ValueBase(const T &val, Status stat=good)
Definition ValueBase.h:35
virtual Value & operator=(const active::utility::Time &val) override
Definition ValueBase.h:142
T data
The value data.
Definition ValueBase.h:58
virtual void setDefault() override
Definition ValueBase.h:203
virtual Value & operator=(int32_t val) override
Definition ValueBase.h:100
virtual Type getType() const override
Definition ValueBase.h:198
ValueBase()
Definition ValueBase.h:29
virtual Value & operator=(const active::utility::Guid &val) override
Definition ValueBase.h:136
bool operator!=(const Value &ref) const
Definition ValueBase.h:73
ValueBase(const Value &value)
Definition ValueBase.h:40
virtual Value & operator=(const active::utility::String &val) override
Definition ValueBase.h:124
virtual Value & operator=(int64_t val) override
Definition ValueBase.h:112
virtual Value & operator=(double val) override
Definition ValueBase.h:118
virtual Value & operator=(bool val) override
Definition ValueBase.h:94
ValueBase(const utility::String &stringVal)
Definition ValueBase.h:45
virtual bool operator==(const Value &ref) const override
Definition ValueBase.h:67
Definition Value.h:31
Status
The value status (defines whether a value has been explicitly set and (if so) if it's meaningful.
Definition Value.h:44
Type
Supported value types (broad groups, e.g. int32_t and int64_t are both intType)
Definition Value.h:51
virtual Value & operator=(const Value &val)=0
Status status
The value status.
Definition Value.h:100
Definition Guid.h:16
A Unicode-aware string class.
Definition String.h:51
A class to represent a date/time.
Definition Time.h:19
Definition Transportable.h:13