knowL: Knowledge Libraries
Loading...
Searching...
No Matches
knowl
src
knowCore
Uris
Uris.h
1
#pragma once
2
3
#include <knowCore/UriManager.h>
4
#include <knowCore/UrisRegistry.h>
5
#include <knowCore/Uri.h>
6
7
namespace
knowCore::Uris
8
{
9
template
<
typename
_T_>
10
struct
IsUriDefinition
: std::false_type {};
11
12
template
<
typename
_T1_,
typename
_T2_>
13
inline
std::enable_if_t<IsUriDefinitionV<_T1_> and IsUriDefinitionV<_T2_>,
knowCore::Uri
> select(
bool
_cond,
const
_T1_& _t1,
const
_T2_& _t2)
14
{
15
return
_cond ?
knowCore::Uri
(_t1) : knowCore::
Uri
(_t2);
16
}
17
}
18
19
template
<
typename
_T_,
typename
Char >
20
struct
fmt::formatter<_T_, Char, std::enable_if_t<knowCore::Uris::IsUriDefinition<_T_>::value>> : fmt::formatter<knowCore::Uri> {
21
};
22
23
// On a side node, the operator from "UriDefinition" should be assumed to be "static".
24
// They might be called before the UriDefinition is initialised. Which works fine because they don't depend
25
// on anything. (even though it is clearly ugly)
26
27
#define __KNOWCORE_DECLARE_URI_C(_NAME_, _URL_) \
28
class _NAME_ ## UriDefinition { \
29
public: \
30
inline operator knowCore::Uri() const \
31
{ \
32
static knowCore::Uri uri = knowCore::Uri(QStringLiteral(_URL_)); \
33
return uri; \
34
} \
35
inline operator QString() const \
36
{ \
37
return knowCore::Uri(*this); \
38
} \
39
}; \
40
static _NAME_ ## UriDefinition _NAME_;
41
42
#define __KNOWCORE_DECLARE_URI_2(_NS_, _URL_, _NAME_, _LABEL_) \
43
__KNOWCORE_DECLARE_URI_C(_NAME_, _URL_ _LABEL_)
44
45
#define __KNOWCORE_DECLARE_URI_1(_NS_, _URL_, _NAME_) \
46
__KNOWCORE_DECLARE_URI_C(_NAME_, _URL_ # _NAME_)
47
48
#define KNOWCORE_DECLARE_URI_CHOOSER(A, B, C, ...) __KNOWCORE_GET_2ND_ARG(__VA_OPT__(,) __VA_ARGS__, __KNOWCORE_DECLARE_URI_2, __KNOWCORE_DECLARE_URI_1, )
49
50
#define __KNOWCORE_DECLARE_URI(...) KNOWCORE_DECLARE_URI_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
51
52
#define __KNOWCORE_DECLARE_URI_TRAITS_C(_NS_, _NAME_) \
53
template<> struct knowCore::Uris::IsUriDefinition<_NS_::_NAME_ ## UriDefinition> : std::true_type {}; \
54
template<> \
55
inline QVariant QVariant::fromValue<_NS_::_NAME_ ## UriDefinition>(const _NS_::_NAME_ ## UriDefinition& _ud) \
56
{ return QVariant::fromValue(knowCore::Uri(_ud)); }
57
58
#define __KNOWCORE_DECLARE_URI_TRAITS_2(_NS_, _URL_, _NAME_, _LABEL_) \
59
__KNOWCORE_DECLARE_URI_TRAITS_C(_NS_, _NAME_)
60
61
#define __KNOWCORE_DECLARE_URI_TRAITS_1(_NS_, _URL_, _NAME_) \
62
__KNOWCORE_DECLARE_URI_TRAITS_C(_NS_, _NAME_)
63
64
#define KNOWCORE_DECLARE_URI_TRAITS_CHOOSER(A, B, C, ...) __KNOWCORE_GET_2ND_ARG(__VA_OPT__(,) __VA_ARGS__, __KNOWCORE_DECLARE_URI_TRAITS_2, __KNOWCORE_DECLARE_URI_TRAITS_1, )
65
66
#define __KNOWCORE_DECLARE_URI_TRAITS(...) KNOWCORE_DECLARE_URI_TRAITS_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
67
68
#define __KNOWCORE_DEFINE_URI_C(_NS_, _NAME_) \
69
_NS_::_NAME_ ## UriDefinition _NS_::_NAME_;
70
71
#define __KNOWCORE_DEFINE_URI_2(_NS_, _URL_, _NAME_, _LABEL_ ) \
72
__KNOWCORE_DEFINE_URI_C(_NS_, _NAME_)
73
74
#define __KNOWCORE_DEFINE_URI_1(_NS_, _URL_, _NAME_) \
75
__KNOWCORE_DEFINE_URI_C(_NS_, _NAME_)
76
77
#define KNOWCORE_DEFINE_URI_CHOOSER(A, B, C, ...) __KNOWCORE_GET_2ND_ARG(__VA_OPT__(,) __VA_ARGS__, __KNOWCORE_DEFINE_URI_2, __KNOWCORE_DEFINE_URI_1, )
78
79
#define __KNOWCORE_DEFINE_URI(...) KNOWCORE_DEFINE_URI_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
80
81
#define __KNOWCORE_DECLARE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_) \
82
namespace _CPP_NAMESPACE_ { \
83
class _CNS_ \
84
{ \
85
_CNS_(); \
86
~_CNS_(); \
87
public: \
88
class UriDefinition { \
89
public: \
90
inline operator knowCore::Uri() const \
91
{ \
92
static knowCore::Uri uri = knowCore::Uri(QStringLiteral(_URL_)); \
93
return uri; \
94
} \
95
inline operator std::optional<knowCore::Uri>() const \
96
{ \
97
static knowCore::Uri uri = knowCore::Uri(QStringLiteral(_URL_)); \
98
return uri; \
99
} \
100
inline operator QString() const \
101
{ \
102
return knowCore::Uri(*this); \
103
} \
104
knowCore::Uri resolved(const knowCore::Uri& _url) const \
105
{ \
106
return knowCore::Uri(*this).resolved(_url); \
107
} \
108
}; \
109
static const UriDefinition base; \
110
class PrefixDefinition { \
111
public: \
112
inline operator QString() const \
113
{ \
114
return QString(_PREFIX_); \
115
} \
116
}; \
117
static const PrefixDefinition prefix; \
118
_NSE_(__KNOWCORE_DECLARE_URI, _CNS_, _URL_) \
119
}; \
120
} \
121
_NSE_(__KNOWCORE_DECLARE_URI_TRAITS, _CPP_NAMESPACE_::_CNS_, _URL_)
122
123
#ifdef KNOWCORE_ENABLE_ONTOLOGY_URIS_DEFINITION
124
125
#define __KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_) \
126
__KNOWCORE_DECLARE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_) \
127
namespace _CPP_NAMESPACE_ { \
128
_NSE_(__KNOWCORE_DEFINE_URI, _CNS_, _URL_) \
129
const _CNS_::UriDefinition _CNS_::base; \
130
const _CNS_::PrefixDefinition _CNS_::prefix; \
131
struct _CNS_ ## _Registration { \
132
_CNS_ ## _Registration() \
133
{ \
134
knowCore::UrisRegistry::manager()->addPrefix(_CNS_::prefix, \
135
knowCore::Uri(_CNS_::base)); \
136
} \
137
}; \
138
_CNS_ ## _Registration _CNS_ ## _registration; \
139
}
140
141
#else
142
143
#define __KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_) \
144
__KNOWCORE_DECLARE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_)
145
146
#endif
147
148
#define _KNOWCORE_ONTOLOGY_URIS_2(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_) __KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, _PREFIX_)
149
#define _KNOWCORE_ONTOLOGY_URIS_1(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_) __KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, # _CNS_)
150
151
#define _KNOWCORE_ONTOLOGY_URIS_CHOOSER(A, B, C, D, ...) __KNOWCORE_GET_2ND_ARG(__VA_OPT__(,) __VA_ARGS__ , _KNOWCORE_ONTOLOGY_URIS_2, _KNOWCORE_ONTOLOGY_URIS_1, )
152
153
#define ___KNOWCORE_ONTOLOGY_URIS(...) _KNOWCORE_ONTOLOGY_URIS_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
154
155
#define KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_, ...) \
156
___KNOWCORE_ONTOLOGY_URIS(_CPP_NAMESPACE_, _NSE_, _CNS_, _URL_ __VA_OPT__(,) __VA_ARGS__)
knowCore::Uri
Definition
Uri.h:14
knowCore::Uris::IsUriDefinition
Definition
Uris.h:10
Generated by
1.12.0