7 #ifndef WOLF_NULLABLE_H
8 #define WOLF_NULLABLE_H
10 #ifndef WOLF_BASE_EXPORT
11 #define WOLF_BASE_EXPORT Q_DECL_IMPORT
26 template<
typename T>
operator T*()
const{
return (T*)
nullptr;}
30 bool operator==(
const std::nullptr_t&)
const{
return true;}
31 bool operator!=(
const std::nullptr_t&)
const{
return false;}
33 template<
typename T>
bool operator==(
const T*p)
const{
return p==
nullptr;}
34 template<
typename T>
bool operator!=(
const T*p)
const{
return p!=
nullptr;}
50 explicit Nullable(
const std::nullptr_t&):isnull(true),elem(){}
65 operator T()
const{
if(isnull)
return T();
else return elem;}
70 T
value(
const T&defaultval=T())
const{
if(isnull)
return defaultval;
else return elem;}
78 T
data(
const T&defaultval=T())
const{
if(isnull)
return defaultval;
else return elem;}
83 T* operator ->()
const{
if(isnull)
return nullptr;
else return const_cast<T*
>(&elem);}
86 bool operator==(
const T&t)
const{
if(isnull)
return false;
else return elem == t;}
88 bool operator!=(
const T&t)
const{
if(isnull)
return true;
else return elem != t;}
92 if(isnull != t.isnull)
return false;
93 if(isnull)
return true;
94 else return elem == t.elem;}
97 if(isnull != t.isnull)
return true;
98 if(isnull)
return false;
99 else return elem != t.elem;}
125 Q_DECLARE_SMART_POINTER_METATYPE(
Nullable)
bool isNull() const
Definition: nullable.h:62
bool operator==(const NullValue &) const
compares the Nullable with the special null value
Definition: nullable.h:102
Definition: nullable.h:41
bool operator!=(const T &t) const
Definition: nullable.h:88
Nullable(const std::nullptr_t &)
Definition: nullable.h:50
Nullable(const Nullable< T > &t)
Definition: nullable.h:54
#define WOLF_BASE_EXPORT
Definition: nullable.h:11
bool operator!=(const NullValue &) const
compares the Nullable with the special null value
Definition: nullable.h:104
bool operator==(const Nullable< T > &t) const
Definition: nullable.h:91
bool operator!=(const Nullable< T > &t) const
Definition: nullable.h:96
NullValue(const std::nullptr_t &)
Definition: nullable.h:23
bool operator!=(const std::nullptr_t &) const
compares the Nullable with the special null value
Definition: nullable.h:108
T valueOrDefault() const
Helper to automatically convert to base type.
Definition: nullable.h:72
Nullable(const T &t)
Definition: nullable.h:52
bool operator==(const T &t) const
Definition: nullable.h:86
T dataOrDefault() const
Helper to automatically convert to base type.
Definition: nullable.h:80
T & value()
Definition: nullable.h:68
Nullable< T > & operator=(const T &t)
Definition: nullable.h:57
Definition: nullable.h:18
NullValue()
Definition: nullable.h:21
Nullable(const NullValue &)
Definition: nullable.h:47
bool operator==(const T *p) const
Definition: nullable.h:33
Q_DECLARE_METATYPE(NullValue)
bool operator==(const NullValue &) const
Definition: nullable.h:28
bool operator==(const std::nullptr_t &) const
compares the Nullable with the special null value
Definition: nullable.h:106
T data(const T &defaultval=T()) const
Definition: nullable.h:78
bool operator!=(const NullValue &) const
Definition: nullable.h:29
bool operator==(const std::nullptr_t &) const
Definition: nullable.h:30
Nullable< T > & operator=(const Nullable< T > &t)
Definition: nullable.h:59
Nullable()
Definition: nullable.h:45
bool operator!=(const std::nullptr_t &) const
Definition: nullable.h:31
const NullValue nullval
special null value
Definition: nullable.h:38
T & data()
Definition: nullable.h:76
T value(const T &defaultval=T()) const
Definition: nullable.h:70
NullValue(const NullValue &)
Definition: nullable.h:22
bool operator!=(const T *p) const
Definition: nullable.h:34
WOLF_BASE_EXPORT bool operator==(Nullable< qint64 > i1, int i2)
Definition: nullable.h:127