aboutsummaryrefslogtreecommitdiff
path: root/c/pl.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/pl.h')
-rw-r--r--c/pl.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/c/pl.h b/c/pl.h
index 4a5ea41..c0af4bc 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -33,8 +33,11 @@ struct Query
Query(module_t ctx, predicate_t p, term_t t0);
~Query();
int Cut();
+ int Cut(std::nothrow_t);
int Close();
+ int Close(std::nothrow_t);
int NextSolution();
+ int NextSolution(std::nothrow_t);
private:
qid_t m_q;
};
@@ -92,28 +95,31 @@ inline bool PlGetN(term_t) { return true; }
template <typename T, typename... U>
inline bool PlGetN(term_t t, T x, U... xs) { return PlGet(t, x) && PlGetN(t+1, xs...); }
-/* Call Prolog predicate, propagating Prolog exceptions. */
-template <typename... T>
-int Plx(const char* const szMod, const char* const szPred, T... xs)
+/* Call Prolog predicate. */
+template <bool Except = false, typename... T>
+int Pl(const char* const szMod, const char* const szPred, T... xs)
{
Frame f;
const term_t t = PL_new_term_refs(sizeof...(T));
+
if (!PlPutN(t, xs...)) return 0;
Query q(NULL, PL_predicate(szPred, sizeof...(T), szMod), t);
- if (!q.NextSolution()) return 0;
+
+ if constexpr (Except) {
+ if (!q.NextSolution()) return 0;
+ } else {
+ if (!q.NextSolution(std::nothrow)) return 0;
+ }
+
if (!PlGetN(t, xs...)) return 0;
return 1;
}
-/* Call Prolog predicate, ignoring Prolog exceptions. */
+/* Call Prolog predicate, propagating Prolog exceptions. */
template <typename... T>
-int Pl(const char* const szMod, const char* const szPred, T... xs)
+int Plx(const char* const szMod, const char* const szPred, T... xs)
{
- try {
- return Plx(szMod, szPred, xs...);
- } catch (const term_t& t) {
- return 0;
- }
+ return Pl<true>(szMod, szPred, xs...);
}
#endif