Coverage report: /development/source/library/com/dydra/gitlab/dydra-cgi/ffi/lisp/rdfcache/term-cursor.lisp

KindCoveredAll%
expression0124 0.0
branch010 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (in-package :rdfcache)
2
 
3
 ;; Term Cursor API: Private
4
 
5
 (defun term-cursor-init (cursor-pointer term-position &key (distinct t) (ordered t))
6
   (declare (type foreign-pointer cursor-pointer)
7
            (type keyword term-position)
8
            (type boolean distinct ordered)
9
            (ignore ordered)) ;; TODO: do something useful with ORDERED
10
   (with-checked-errno-result "rdfcache_term_cursor_init"
11
     (%%term-cursor-init cursor-pointer
12
                         (the fixnum (if distinct 1 0))
13
                         term-position)))
14
 
15
 (defun term-cursor-dispose (cursor-pointer)
16
   (declare (type foreign-pointer cursor-pointer))
17
   (with-checked-errno-result "rdfcache_term_cursor_dispose"
18
     (%%term-cursor-dispose cursor-pointer)))
19
 
20
 (defun term-cursor-open (cursor-pointer transaction-pointer &key (context-number *all-context-number*))
21
   (declare (type foreign-pointer cursor-pointer transaction-pointer)
22
            (type fixnum context-number))
23
   (with-checked-int-result "rdfcache_term_cursor_open"
24
     (%%term-cursor-open cursor-pointer
25
                         (transaction-uuid-pointer transaction-pointer)
26
                         context-number)))
27
 
28
 (defun term-cursor-count (cursor-pointer)
29
   (declare (type foreign-pointer cursor-pointer))
30
   (with-checked-long-result "rdfcache_term_cursor_count"
31
     (%%term-cursor-count cursor-pointer)))
32
 
33
 (declaim (inline term-cursor-next))
34
 (defun term-cursor-next (cursor-pointer)
35
   (declare (type foreign-pointer cursor-pointer))
36
   (not (zerop (%%term-cursor-next cursor-pointer))))
37
 
38
 (defun term-cursor-skip (cursor-pointer &optional (count 1))
39
   (declare (type foreign-pointer cursor-pointer)
40
            (type fixnum count))
41
   (%%term-cursor-skip cursor-pointer count))
42
 
43
 (defun term-cursor-close (cursor-pointer)
44
   (declare (type foreign-pointer cursor-pointer))
45
   (with-checked-errno-result "rdfcache_term_cursor_close"
46
     (%%term-cursor-close cursor-pointer)))
47
 
48
 ;; Term Cursor API: Macros
49
 
50
 (defmacro term-cursor-term-number (cursor-var)
51
   `(foreign-slot-value ,cursor-var 'term-cursor 'term-number))
52
 
53
 (defmacro with-context-cursor ((cursor-var transaction-pointer &key (distinct t) (ordered t)) &body body)
54
   `(with-foreign-object (,cursor-var '(:struct term-cursor))
55
      (term-cursor-init ,cursor-var :context :distinct ,distinct :ordered ,ordered)
56
      (unwind-protect (progn (term-cursor-open ,cursor-var ,transaction-pointer)
57
                             ,@body)
58
        (term-cursor-close ,cursor-var)
59
        (term-cursor-dispose ,cursor-var))))
60
 
61
 (defun map-term-numbers (function %transaction position &key (distinct t) (ordered t) (context *all-context-number*))
62
   (declare (dynamic-extent function))
63
   (with-foreign-object (%cursor '(:struct term-cursor))
64
     (term-cursor-init %cursor position :distinct distinct :ordered ordered)
65
     (unwind-protect (progn (term-cursor-open %cursor %transaction :context-number context)
66
                            (loop for count from 0
67
                                  until (null (term-cursor-next %cursor))
68
                                  do (funcall function (term-cursor-term-number %cursor))
69
                                  finally (return count)))
70
        (term-cursor-close %cursor)
71
        (term-cursor-dispose %cursor))))
72
 
73
 ;; Term Cursor API: Public
74
 
75
 (defun map-context-numbers (function transaction-pointer &key (distinct t) (ordered t)) ;; used by SPOCQ
76
   (declare (dynamic-extent function))
77
   (with-context-cursor (cursor transaction-pointer :distinct distinct :ordered ordered)
78
     (loop for count from 0
79
           until (null (term-cursor-next cursor))
80
           do (funcall function (term-cursor-term-number cursor))
81
           finally (return count))))
82
 
83
 (defun map-subject-numbers (function %transaction &key (distinct t) (ordered t) (context *all-context-number*)) ;; used by SPOCQ
84
   (declare (dynamic-extent function))
85
   (map-term-numbers function %transaction :subject
86
                     :distinct distinct :ordered ordered :context context))
87
 
88
 (defun map-predicate-numbers (function %transaction &key (distinct t) (ordered t) (context *all-context-number*)) ;; used by SPOCQ
89
   (declare (dynamic-extent function))
90
   (map-term-numbers function %transaction :predicate
91
                     :distinct distinct :ordered ordered :context context))
92
 
93
 (defun map-object-numbers (function %transaction &key (distinct t) (ordered t) (context *all-context-number*)) ;; used by SPOCQ
94
   (declare (dynamic-extent function))
95
   (map-term-numbers function %transaction :object
96
                     :distinct distinct :ordered ordered :context context))