ActiveLib
Loading...
Searching...
No Matches
Value.h
1
6#ifndef ACTIVE_SETTING_VALUE
7#define ACTIVE_SETTING_VALUE
8
9#include "Active/Utility/Cloner.h"
10#include "Active/Utility/Guid.h"
11#include "Active/Utility/String.h"
12#include "Active/Utility/Time.h"
13
14namespace active::setting {
15
32 public:
33
34 // MARK: - Types
35
37 using Unique = std::unique_ptr<Value>;
39 using Shared = std::shared_ptr<Value>;
41 using Option = std::optional<Value>;
42
44 enum class Status {
45 undefined = 0,
46 bad,
47 good,
48 };
49
51 enum class Type {
52 null = 0,
53 boolType,
54 idType,
55 intType,
56 floatType,
57 stringType,
58 timeType,
59 };
60
61 using enum Status;
62 using enum Type;
63
64 // MARK: - Static functions
65
71 static std::optional<Type> typeFromName(const utility::String& text);
77 static utility::String nameForType(Type type);
78
79 // MARK: - Constructors
80
85 Value(Status stat = good) { status = stat; }
89 virtual ~Value() = default;
90
95 virtual Value* clonePtr() const override = 0;
96
97 // MARK: - Public variables
98
101
102 // MARK: - Operators
103
109 virtual bool operator==(const Value& ref) const = 0;
115 bool operator!=(const Value& ref) const { return !((*this) == ref); }
121 virtual bool operator<(const Value& ref) const = 0;
127 virtual Value& operator=(const Value& val) = 0;
133 virtual Value& operator=(bool val) = 0;
139 virtual Value& operator=(int32_t val) = 0;
145 virtual Value& operator=(uint32_t val) = 0;
151 virtual Value& operator=(int64_t val) = 0;
157 virtual Value& operator=(double val) = 0;
163 virtual Value& operator=(const active::utility::String& val) = 0;
169 virtual Value& operator=(const char* val) { return operator=(utility::String{val}); }
175 virtual Value& operator=(const active::utility::Guid& val) = 0;
181 virtual Value& operator=(const active::utility::Time& val) = 0;
182
183 // MARK: - Conversion operators
184
189 virtual operator bool() const = 0;
194 virtual operator int32_t() const = 0;
199 virtual operator uint32_t() const = 0;
204 virtual operator int64_t() const = 0;
209 virtual operator double() const = 0;
214 virtual operator active::utility::String() const = 0;
219 virtual operator active::utility::Guid() const = 0;
224 virtual operator active::utility::Time() const = 0;
225
226 // MARK: - Functions (const)
227
232 virtual bool isGood() const { return (status == good); }
237 virtual bool isNull() const = 0;
242 virtual Type getType() const = 0;
243
244 // MARK: - Functions (mutating)
245
247 virtual void setDefault() = 0;
248 };
249
250 // MARK: - Value smart pointer comparisons
251
258 inline bool operator==(const Value::Unique& lhs, const Value::Unique& rhs) {
259 return (!lhs || !rhs) ? !(!lhs ^ !rhs) : lhs->operator==(*rhs);
260 }
261
268 inline bool operator!=(const Value::Unique& lhs, const Value::Unique& rhs) {
269 return !(lhs == rhs);
270 }
271
278 inline bool operator<(const Value::Unique& lhs, const Value::Unique& rhs) {
279 return (!lhs || !rhs) ? (!lhs && rhs) : lhs->operator<(*rhs);
280 }
281
288 inline bool operator==(const Value::Shared& lhs, const Value::Shared& rhs) {
289 return (!lhs || !rhs) ? !(!lhs ^ !rhs) : lhs->operator==(*rhs);
290 }
291
298 inline bool operator!=(const Value::Shared& lhs, const Value::Shared& rhs) {
299 return !(lhs == rhs);
300 }
301
308 inline bool operator<(const Value::Shared& lhs, const Value::Shared& rhs) {
309 return (!lhs || !rhs) ? (!lhs && rhs) : lhs->operator<(*rhs);
310 }
311
312}
313
314#endif //ACTIVE_SETTING_VALUE
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
static std::optional< Type > typeFromName(const utility::String &text)
Definition Value.cpp:36
virtual Value & operator=(bool val)=0
Type
Supported value types (broad groups, e.g. int32_t and int64_t are both intType)
Definition Value.h:51
virtual Value & operator=(int64_t val)=0
virtual Value & operator=(const Value &val)=0
virtual ~Value()=default
virtual Value & operator=(double val)=0
static utility::String nameForType(Type type)
Definition Value.cpp:51
std::unique_ptr< Value > Unique
Unique pointer.
Definition Value.h:37
Value(Status stat=good)
Definition Value.h:85
virtual Type getType() const =0
virtual Value & operator=(const char *val)
Definition Value.h:169
virtual Value & operator=(const active::utility::Guid &val)=0
Status status
The value status.
Definition Value.h:100
std::shared_ptr< Value > Shared
Shared pointer.
Definition Value.h:39
virtual Value & operator=(uint32_t val)=0
virtual Value & operator=(const active::utility::Time &val)=0
virtual Value & operator=(const active::utility::String &val)=0
virtual bool operator<(const Value &ref) const =0
bool operator!=(const Value &ref) const
Definition Value.h:115
virtual Value & operator=(int32_t val)=0
virtual bool operator==(const Value &ref) const =0
virtual bool isGood() const
Definition Value.h:232
virtual Value * clonePtr() const override=0
virtual void setDefault()=0
std::optional< Value > Option
Optional.
Definition Value.h:41
virtual bool isNull() const =0
Definition Cloner.h:17
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
bool operator==(const Value::Unique &lhs, const Value::Unique &rhs)
Definition Value.h:258
bool operator<(const Value::Unique &lhs, const Value::Unique &rhs)
Definition Value.h:278
bool operator!=(const Value::Unique &lhs, const Value::Unique &rhs)
Definition Value.h:268