blob: ace83e74dfd4b8d45a9552675f2d1061f44c52a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <SWI-Prolog.h>
#include "pl.h"
Query::Query(module_t ctx, predicate_t p, term_t t0)
{
m_q = PL_open_query(ctx, PL_Q_CATCH_EXCEPTION, p, t0);
}
Query::~Query()
{
PL_cut_query(m_q);
}
int Query::Cut()
{
if (PL_cut_query(m_q)) return 1;
if (term_t t = PL_exception(m_q)) throw t;
return 0;
}
int Query::Close()
{
if (PL_close_query(m_q)) return 1;
if (term_t t = PL_exception(m_q)) throw t;
return 0;
}
int Query::NextSolution()
{
if (PL_next_solution(m_q)) return 1;
if (term_t t = PL_exception(m_q)) throw t;
return 0;
}
int Plx(const char *szMod, const char *szPred)
{
term_t t = PL_new_term_refs(0);
Query q(NULL, PL_predicate(szPred, 0, szMod), t);
return q.NextSolution();
}
|