knowL: Knowledge Libraries
Loading...
Searching...
No Matches
ValueMarshal.h
1#pragma once
2
3#include <knowCore/Uris/askcore_datatype.h>
4#include <knowCore/Value.h>
5#include <knowCore/ValueList.h>
6#include <knowRDF/Literal.h>
7
8namespace knowRDF
9{
10 template<typename _T_>
11 struct ValueMarshal;
12
13 template<typename _T_, typename _DO_NOT_SPECIALISED_ = void>
14 cres_qresult<knowCore::Value> toValue(const _T_& _t)
15 {
16 return ValueMarshal<_T_>::convert(_t);
17 }
18
19 template<typename _T_>
20 cres_qresult<_T_> fromValue(const knowCore::Value& _t)
21 {
22 return ValueMarshal<_T_>::convert(_t);
23 }
24
25 template<typename _T_>
27 {
28 static cres_qresult<knowCore::Value> convert(const _T_& _t)
29 {
30 return cres_success(knowCore::Value::fromValue(_t));
31 }
32 static cres_qresult<_T_> convert(const knowCore::Value& _t) { return _t.value<_T_>(); }
33 };
34 template<>
35 struct ValueMarshal<knowCore::Value>
36 {
37 static cres_qresult<knowCore::Value> convert(const knowCore::Value& _t)
38 {
39 return cres_success(_t);
40 }
41 };
42 template<typename _T_>
43 struct ValueMarshal<QList<_T_>>
44 {
45 static cres_qresult<knowCore::Value> convert(const QList<_T_>& _t)
46 {
48 for(const _T_& st : _t)
49 {
50 cres_try(knowCore::Value value, toValue(st));
51 values.append(value);
52 }
53 return cres_success(knowCore::Value::fromValue(knowCore::ValueList(values)));
54 }
55 static cres_qresult<QList<_T_>> convert(const knowCore::Value& _t)
56 {
57 QList<_T_> list;
58 cres_try(knowCore::ValueList value_list, _t.toList());
59 for(const knowCore::Value val : value_list.values())
60 {
61 cres_try(_T_ val_t, fromValue<_T_>(val));
62 list.append(val_t);
63 }
64 return cres_success(list);
65 }
66 };
67} // namespace knowRDF
Definition Forward.h:14
Definition ValueList.h:8
Definition Value.h:21
cres_qresult< ValueList > toList() const
Definition Value.cpp:254
static Value fromValue(const _T_ &_value)
Definition Value.h:241
cres_qresult< _T_ > value(TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
Definition Value.h:353
Definition ValueMarshal.h:27