knowL: Knowledge Libraries
Loading...
Searching...
No Matches
ag.h
1#include <ag/qt.h>
2#include <knowCore/Value.h>
3
4namespace ag
5{
6 template<typename _T_>
7 struct TypeSupport<_T_, false, std::enable_if_t<knowCore::HasMetaTypeInformationV<_T_> and not std::is_same_v<_T_, QString>>>
8 {
9 static void hash(QCryptographicHash* _hash, const _T_& _t)
10 {
11 _hash->addData(knowCore::Value::fromValue(_t).md5().expectSuccess());
12 }
13 static _T_ init()
14 {
15 return _T_();
16 }
17 static void clean(_T_* _t)
18 {
19 *_t = _T_();
20 }
21 static _T_ clone(const _T_ _t)
22 {
23 return _t;
24 }
25 };
26
27 template<typename _T_>
28 struct SerialisationSupport<_T_, false, std::enable_if_t<knowCore::HasMetaTypeInformationV<_T_> and not std::is_same_v<_T_, QString>>>
29 {
30 static QJsonValue toJson(const _T_& _t)
31 {
32 return knowCore::Value::fromValue(_t).toJsonValue().expectSuccess();
33 }
34 static bool fromJson(_T_* _t, const QJsonValue& _value, QString* _errorMessage)
35 {
36 auto const [success, value, errorMessage] = knowCore::Value::fromJsonValue(knowCore::MetaTypeInformation<_T_>::uri(), _value);
37 if(success)
38 {
39 auto const [success_value, value_t, errorMessage_value] = value.template value<_T_>();
40 if(success_value)
41 {
42 *_t = value_t;
43 return true;
44 } else {
45 *_errorMessage = errorMessage_value;
46 return false;
47 }
48 } else {
49 *_errorMessage = errorMessage;
50 return false;
51 }
52 }
53 static QCborValue toCbor(const _T_ _t)
54 {
55 return knowCore::Value::fromValue(_t).toCborValue().expectSuccess();
56 }
57 static bool fromCbor(_T_* _t, const QCborValue& _value, QString* _errorMessage)
58 {
59 auto const [success, value, errorMessage] = knowCore::Value::fromCborValue(knowCore::MetaTypeInformation<_T_>::uri(), _value);
60 if(success)
61 {
62 auto const [success_value, value_t, errorMessage_value] = value.template value<_T_>();
63 if(success_value)
64 {
65 *_t = value_t;
66 return true;
67 } else {
68 *_errorMessage = errorMessage_value;
69 return false;
70 }
71 } else {
72 *_errorMessage = errorMessage;
73 return false;
74 }
75 }
76 };
77
78}
Definition MetaType.h:58
static Value fromValue(const _T_ &_value)
Definition Value.h:184