T& value(){return elem;}
/**returns the original value, if it is currently NULL it returns the given default value, if no default is given an instance created with the default constructor is returned*/
T value(const T&defaultval=T())const{if(isnull)return defaultval;else return elem;}
+ ///Helper to automatically convert to base type
+ T valueOrDefault()const{return value(T());}
+ ///converts the nullable to a pointer of the wrapped class - acting like a smart pointer
+ T* operator ->()const{if(isnull)return nullptr;else return const_cast<T*>(&elem);}
/**compares this instance with a value of the original class, NULL is different from ANY instance of the original class*/
bool operator==(const T&t)const{if(isnull)return false;else return elem == t;}
Q_DECLARE_METATYPE(Nullable<quint64>)
Q_DECLARE_METATYPE(Nullable<QString>)
Q_DECLARE_METATYPE(Nullable<QByteArray>)
+Q_DECLARE_SMART_POINTER_METATYPE(Nullable)
inline WOLF_BASE_EXPORT bool operator==(Nullable<qint64> i1,int i2){return i1.operator==(i2);}
inline WOLF_BASE_EXPORT bool operator==(Nullable<quint32> i1,int i2){return i1.operator==(i2);}
#include "Nullable"
#include <QDomDocument>
+#include <QString>
+#include <QDebug>
QDomElement WObject::toXml(QDomDocument&doc,QString name)
{
return doc.createElement(name);
}
+static inline bool w(bool b){qDebug()<<"registering"<<b;return b;}
+
static int itype0=
+ qRegisterMetaType<Nullable<int> >()+
qRegisterMetaType<Nullable<qint32> >()+
qRegisterMetaType<Nullable<qint64> >()+
qRegisterMetaType<Nullable<quint32> >()+
qRegisterMetaType<Nullable<QString> >()+
qRegisterMetaType<Nullable<QByteArray> >()+
qRegisterMetaType<Nullable<bool> >();
+
+static bool btype0=
+ //String/bytes to self
+ QMetaType::registerConverter<Nullable<QString>,QString>(&Nullable<QString>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<QByteArray>,QByteArray>(&Nullable<QByteArray>::valueOrDefault)|
+ //int/bool to self
+ QMetaType::registerConverter<Nullable<bool>,bool>(&Nullable<bool>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<int>,int>(&Nullable<int>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<qint32>,qint32>(&Nullable<qint32>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<qint64>,qint64>(&Nullable<qint64>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<quint32>,quint32>(&Nullable<quint32>::valueOrDefault)|
+ QMetaType::registerConverter<Nullable<quint64>,quint64>(&Nullable<quint64>::valueOrDefault)|
+ //int upgrade with keeping sign
+ QMetaType::registerConverter<Nullable<int>,qint64>([](Nullable<int>v)->qint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<qint32>,qint64>([](Nullable<qint32>v)->qint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<quint32>,quint64>([](Nullable<quint32>v)->quint64{return v.valueOrDefault();})|
+ //risky int upgrade unsigned<->signed
+ QMetaType::registerConverter<Nullable<int>,quint64>([](Nullable<int>v)->quint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<qint32>,quint64>([](Nullable<qint32>v)->quint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<qint64>,quint64>([](Nullable<qint64>v)->quint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<quint32>,qint64>([](Nullable<quint32>v)->qint64{return v.valueOrDefault();})|
+ QMetaType::registerConverter<Nullable<quint64>,qint64>([](Nullable<quint64>v)->qint64{return v.valueOrDefault();})|
+ //int to string
+ QMetaType::registerConverter<Nullable<int>,QString>([](Nullable<int> v)->QString{return QString::number(v.valueOrDefault());})|
+ QMetaType::registerConverter<Nullable<qint32>,QString>([](Nullable<qint32> v)->QString{return QString::number(v.valueOrDefault());})|
+ QMetaType::registerConverter<Nullable<qint64>,QString>([](Nullable<qint64> v)->QString{return QString::number(v.valueOrDefault());})|
+ QMetaType::registerConverter<Nullable<quint32>,QString>([](Nullable<quint32> v)->QString{return QString::number(v.valueOrDefault());})|
+ QMetaType::registerConverter<Nullable<quint64>,QString>([](Nullable<quint64> v)->QString{return QString::number(v.valueOrDefault());})|
+ true;