#include #include #include "pl.h" Query::Query(const module_t ctx, const predicate_t p, const 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 (const term_t t = PL_exception(m_q)) throw t; return 0; } int Query::Close() { if (PL_close_query(m_q)) return 1; if (const term_t t = PL_exception(m_q)) throw t; return 0; } int Query::NextSolution() { if (PL_next_solution(m_q)) return 1; if (const term_t t = PL_exception(m_q)) throw t; return 0; } int PL_get_tchars(const term_t t, TCHAR** const pTsz, const int iFlags) { #ifdef UNICODE size_t len; if (!PL_get_wchars(t, &len, pTsz, iFlags)) return 0; return len; #else if (!PL_get_chars(t, pTsz, iFlags)) return 0; return -1; #endif } int Plx(const char* const szMod, const char* const szPred) { const term_t t = PL_new_term_refs(0); Query q(NULL, PL_predicate(szPred, 0, szMod), t); return q.NextSolution(); }