YAP 7.1.0
heap.cxx
1#if 0
2#include <cxx4yap.hh>
3#include <queue>
4
5using namespace std;
6
7class YAPDBTerm: YAPTerm {
8 void * d;
9public:
10 YAPDBTerm() {
11 d=0;
12 }
13
14 YAPDBTerm(Term inp) {
15 d=Yap_StoreTermInDB( t, 0);
16 }
17
18 Term getTerm() {
19 return Yap_FetchTermFromDB( d );
20 }
21
22void release() {
23 Yap_ReleaseTermFromDB(d);
24 d= 0;
25 }
26
27 ~YAPDBTerm() {
28 Yap_ReleaseTermFromDB(d);
29 d= 0;
30 }
31 };
32
33
34class X_API YAPHeap: public std::priority_queue<YAPDBTerm>, public YAPDBTerm {
35 // Create the queue
36
37
38 // now, let us link to Prolog
39
40
41 bool proxy(const std::string f, YAPHeap me, std::list<Term> inp, std::list<Term> out ) {
42 //> Test whether container is empty,
43
44 if (f == "empty") return empty();
45 if (f == "size") { out.push_front(MkIntegerTerm( size() )) ; return true; }
46 //> return size (public member function )
47 if (f == "top") { out.push_front( (const_cast<YAPDBTerm&>(top())).getTerm() ) ; return true; }
48 if (f == "push") { push (YAPDBTerm(inp.front())); return true; }
49 if (f == "emplace") { emplace (YAPDBTerm(inp.front()) ); return true; }
50 if (f == "pop") { (const_cast<YAPDBTerm&>( top())).release(); pop () ; return true; }
51 }
52
53
54
55 YAPHeap(size_t sz)
56 {
57 }
58
59 ~YAPHeap() {
60 while(!empty()) {
61 (const_cast<YAPDBTerm&>(top())).release();
62 pop();
63 }
64};
65
66
68static Int
69cxx_object(void) {
70
71 Term t = Deref(ARG1);
72
73
74 //must_be_text(t)
75 const char *s = Yap_TextTermToText(t);
76 if (!s || s[0] == '\0')
77 return false;
78 Term o = cxx[s](t);
79 return Yap_unify(ARG2, MkAddressTerm(o) );
80}
81 };
82
83static int
84 cxx_method(void)
85{
86 Term t = Deref(ARG1);
87
88
89 //must_be_text(t)
90 const char *s = Yap_TextTermToText(t);
91 if (!s || s[0] == '\0')
92 return false;
93 Term o = cxx[s](t);
94 return Yap_unify(ARG2, MkAddressTerm(o) );
95
96
97}
98#endif
Generic Prolog Term.
Definition: yapt.hh:42