@@ -136,6 +136,7 @@ static typename RELATION_TYPE::Ground ground(const tuple<Ts...> &atom)
136
136
template <typename RELATION_TYPE, typename ... Ts>
137
137
struct AtomTypeSpecifier {
138
138
typedef RELATION_TYPE RelationType;
139
+ // TODO: why not references?
139
140
typedef tuple<Ts...> AtomType;
140
141
AtomType atom;
141
142
};
@@ -189,22 +190,20 @@ struct Externals {
189
190
tuple<const EXTERNAL_TYPEs&...> externals;
190
191
};
191
192
193
+ template <typename ... BODY_ATOM_SPECIFIERs>
194
+ struct BodyAtoms {
195
+ // TODO: why not references?
196
+ tuple<typename BODY_ATOM_SPECIFIERs::AtomType...> body;
197
+ };
198
+
192
199
template <typename HEAD_ATOM_SPECIFIER, typename ... BODY_ATOM_SPECIFIERs>
193
200
struct RuleInstance {
194
201
typedef Rule<typename HEAD_ATOM_SPECIFIER::RelationType, typename BODY_ATOM_SPECIFIERs::RelationType...> RuleType;
195
202
typedef typename HEAD_ATOM_SPECIFIER::AtomType HeadType;
196
203
HeadType head;
204
+ // TODO: why not references?
197
205
typedef tuple<typename BODY_ATOM_SPECIFIERs::AtomType...> BodyType;
198
206
BodyType body;
199
-
200
- template <typename ... EXTERNAL_TYPEs>
201
- ExternalRuleInstance<Externals<EXTERNAL_TYPEs...>, HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> externals (
202
- const EXTERNAL_TYPEs&... externals
203
- ) {
204
- typedef ExternalRuleInstance<Externals<EXTERNAL_TYPEs...>, HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> RuleInstanceType;
205
- return RuleInstanceType{head, body, Externals<EXTERNAL_TYPEs...>{externals...}};
206
- }
207
-
208
207
};
209
208
210
209
template <typename EXTERNALS_TYPE, typename HEAD_ATOM_SPECIFIER, typename ... BODY_ATOM_SPECIFIERs>
@@ -223,26 +222,51 @@ static RuleInstance<HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> rule(
223
222
return RuleInstanceType{head, body};
224
223
}
225
224
225
+ template <typename HEAD_ATOM_SPECIFIER, typename ... BODY_ATOM_SPECIFIERs>
226
+ static RuleInstance<HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> rule (
227
+ const HEAD_ATOM_SPECIFIER& h,
228
+ const BodyAtoms<BODY_ATOM_SPECIFIERs...>& b
229
+ ) {
230
+ typedef RuleInstance<HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> RuleInstanceType;
231
+ typename RuleInstanceType::HeadType head{h.atom };
232
+ return RuleInstanceType{head, b.body };
233
+ }
234
+
226
235
// Rules with external functions
227
236
228
- template <typename T, typename ... ATOM_TYPE_SPECIFIERs >
237
+ template <typename T>
229
238
struct ExternalFunction {
230
239
Variable<T>& bindVariable;
231
- typedef tuple<const ATOM_TYPE_SPECIFIERs&...> AtomsTupleType;
232
- AtomsTupleType boundAtoms;
233
- typedef tuple<const typename ATOM_TYPE_SPECIFIERs::RelationType::Ground&...> ArgsType;
234
- function<T(const ArgsType&)> externalFunction;
240
+ typedef function<T()> ExternalFunctionType;
241
+ ExternalFunctionType externalFunction;
235
242
};
236
243
237
- template <typename T, typename ... ATOM_TYPE_SPECIFIERs >
238
- static ExternalFunction<T, ATOM_TYPE_SPECIFIERs... > external (
244
+ template <typename T>
245
+ static ExternalFunction<T> external (
239
246
unique_ptr<Variable<T>>& bindVariable,
240
- function<T(const typename ExternalFunction<T, ATOM_TYPE_SPECIFIERs...>::ArgsType&)> externalFunction,
241
- const ATOM_TYPE_SPECIFIERs&... boundAtoms
247
+ typename ExternalFunction<T>::ExternalFunctionType externalFunction) {
248
+ return ExternalFunction<T> {*bindVariable, externalFunction};
249
+ }
250
+
251
+ template <typename ... BODY_ATOM_SPECIFIERs>
252
+ static BodyAtoms<BODY_ATOM_SPECIFIERs...> body (BODY_ATOM_SPECIFIERs&&... bodyAtoms) {
253
+ return BodyAtoms<BODY_ATOM_SPECIFIERs...>{{bodyAtoms.atom ...}};
254
+ }
255
+
256
+ template <typename ... BODY_ATOM_SPECIFIERs>
257
+ static BodyAtoms<BODY_ATOM_SPECIFIERs...> body (BODY_ATOM_SPECIFIERs&... bodyAtoms) {
258
+ return BodyAtoms<BODY_ATOM_SPECIFIERs...>{{bodyAtoms.atom ...}};
259
+ }
260
+
261
+ template <typename HEAD_ATOM_SPECIFIER, typename ... BODY_ATOM_SPECIFIERs, typename ... EXTERNAL_TYPEs>
262
+ static ExternalRuleInstance<Externals<EXTERNAL_TYPEs...>, HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs...> rule (
263
+ const HEAD_ATOM_SPECIFIER& h,
264
+ const BodyAtoms<BODY_ATOM_SPECIFIERs...>& b,
265
+ const EXTERNAL_TYPEs&... externals
242
266
) {
243
- return ExternalFunction<T, ATOM_TYPE_SPECIFIERs ...> {
244
- *bindVariable, {boundAtoms...}, externalFunction
245
- };
267
+ typedef ExternalRuleInstance<Externals<EXTERNAL_TYPEs...>, HEAD_ATOM_SPECIFIER, BODY_ATOM_SPECIFIERs ...> RuleInstanceType;
268
+ typename RuleInstanceType::HeadType head{h. atom };
269
+ return RuleInstanceType{head, b. body , Externals<EXTERNAL_TYPEs...>{externals...} };
246
270
}
247
271
248
272
template <typename RELATION_TYPE>
0 commit comments