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

KindCoveredAll%
expression0115 0.0
branch02 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (in-package :dydra-ndk)
2
 
3
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
 
5
 (defctype term-id :int64
6
   "Term identifier.")
7
 
8
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 ;;; Term API: Foreign Symbols
10
 
11
 (defcfunwi ("dydra_term_datatype_id" %%term-datatype-id) term-id (term-id term-id))
12
 
13
 (defcfun ("dydra_term_compare" %%term-compare) :int (term1-id term-id) (term2-id term-id))
14
 
15
 (defcfunwi ("dydra_term_value_as_string" %%term-value-as-string) :string (term-id term-id) (errno-pointer :pointer))
16
 (defcfunwi ("dydra_term_value_as_bool" %%term-value-as-bool) (:boolean :int8) (term-id term-id) (errno-pointer :pointer))
17
 (defcfunwi ("dydra_term_value_as_float" %%term-value-as-float) :float (term-id term-id) (errno-pointer :pointer))
18
 (defcfunwi ("dydra_term_value_as_double" %%term-value-as-double) :double (term-id term-id) (errno-pointer :pointer))
19
 (defcfunwi ("dydra_term_value_as_int8" %%term-value-as-int8) :int8 (term-id term-id) (errno-pointer :pointer))
20
 (defcfunwi ("dydra_term_value_as_uint8" %%term-value-as-uint8) :uint8 (term-id term-id) (errno-pointer :pointer))
21
 (defcfunwi ("dydra_term_value_as_int16" %%term-value-as-int16) :int16 (term-id term-id) (errno-pointer :pointer))
22
 (defcfunwi ("dydra_term_value_as_uint16" %%term-value-as-uint16) :uint16 (term-id term-id) (errno-pointer :pointer))
23
 (defcfunwi ("dydra_term_value_as_int32" %%term-value-as-int32) :int32 (term-id term-id) (errno-pointer :pointer))
24
 (defcfunwi ("dydra_term_value_as_uint32" %%term-value-as-uint32) :uint32 (term-id term-id) (errno-pointer :pointer))
25
 (defcfunwi ("dydra_term_value_as_int64" %%term-value-as-int64) :int64 (term-id term-id) (errno-pointer :pointer))
26
 (defcfunwi ("dydra_term_value_as_uint64" %%term-value-as-uint64) :uint64 (term-id term-id) (errno-pointer :pointer))
27
 (defcfunwi ("dydra_term_value_as_time_in_usec" %%term-value-as-time-in-usec) :int64 (term-id term-id) (errno-pointer :pointer))
28
 
29
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30
 ;;; Term API: Wrappers
31
 
32
 (defun term-compare (term1-id term2-id)
33
   "Compares the two RDF terms denoted by TERM1-ID and TERM2-ID.
34
    Returns -1, 0, 1, or NIL (if the terms are incommensurable).
35
    Signals an error if either of the term identifiers is invalid."
36
   (declare (type fixnum term1-id term2-id))
37
   (let ((result (%%term-compare term1-id term2-id)))
38
     (case result ((-1 0 1) result) (t nil))))
39
 
40
 (declaim (inline term-datatype-id))
41
 (defun term-datatype-id (term-id)
42
   "Returns the term identifier representing the XSD datatype URI of a
43
    literal term."
44
   (declare (type fixnum term-id))
45
   (%%term-datatype-id term-id))
46
 
47
 (declaim (inline term-value-as-string))
48
 (defun term-value-as-string (term-id)
49
   "Returns the value of a term as a string."
50
   (declare (type fixnum term-id))
51
   (%%term-value-as-string term-id (null-pointer)))
52
 
53
 (declaim (inline term-value-as-boolean))
54
 (defun term-value-as-boolean (term-id)
55
   "Returns the value of a term as a boolean."
56
   (declare (type fixnum term-id))
57
   (%%term-value-as-bool term-id (null-pointer)))
58
 
59
 (declaim (inline term-value-as-float))
60
 (defun term-value-as-float (term-id)
61
   "Returns the value of a term as a single-precision floating point number."
62
   (declare (type fixnum term-id))
63
   (%%term-value-as-float term-id (null-pointer)))
64
 
65
 (declaim (inline term-value-as-double))
66
 (defun term-value-as-double (term-id)
67
   "Returns the value of a term as a double-precision floating point number."
68
   (declare (type fixnum term-id))
69
   (%%term-value-as-double term-id (null-pointer)))
70
 
71
 (declaim (inline term-value-as-int8))
72
 (defun term-value-as-int8 (term-id)
73
   "Returns the value of a term as an 8-bit signed integer."
74
   (declare (type fixnum term-id))
75
   (%%term-value-as-int8 term-id (null-pointer)))
76
 
77
 (declaim (inline term-value-as-uint8))
78
 (defun term-value-as-uint8 (term-id)
79
   "Returns the value of a term as an 8-bit unsigned integer."
80
   (declare (type fixnum term-id))
81
   (%%term-value-as-uint8 term-id (null-pointer)))
82
 
83
 (declaim (inline term-value-as-int16))
84
 (defun term-value-as-int16 (term-id)
85
   "Returns the value of a term as a 16-bit signed integer."
86
   (declare (type fixnum term-id))
87
   (%%term-value-as-int16 term-id (null-pointer)))
88
 
89
 (declaim (inline term-value-as-uint16))
90
 (defun term-value-as-uint16 (term-id)
91
   "Returns the value of a term as a 16-bit unsigned integer."
92
   (declare (type fixnum term-id))
93
   (%%term-value-as-uint16 term-id (null-pointer)))
94
 
95
 (declaim (inline term-value-as-int32))
96
 (defun term-value-as-int32 (term-id)
97
   "Returns the value of a term as a 32-bit signed integer."
98
   (declare (type fixnum term-id))
99
   (%%term-value-as-int32 term-id (null-pointer)))
100
 
101
 (declaim (inline term-value-as-uint32))
102
 (defun term-value-as-uint32 (term-id)
103
   "Returns the value of a term as a 32-bit unsigned integer."
104
   (declare (type fixnum term-id))
105
   (%%term-value-as-uint32 term-id (null-pointer)))
106
 
107
 (declaim (inline term-value-as-int64))
108
 (defun term-value-as-int64 (term-id)
109
   "Returns the value of a term as a 64-bit signed integer."
110
   (declare (type fixnum term-id))
111
   (%%term-value-as-int64 term-id (null-pointer)))
112
 
113
 (declaim (inline term-value-as-uint64))
114
 (defun term-value-as-uint64 (term-id)
115
   "Returns the value of a term as a 64-bit unsigned integer."
116
   (declare (type fixnum term-id))
117
   (%%term-value-as-uint64 term-id (null-pointer)))
118
 
119
 (declaim (inline term-value-as-integer))
120
 (defun term-value-as-integer (term-id)
121
   "Returns the value of a term as an integer."
122
   (declare (type fixnum term-id))
123
   (parse-integer (%%term-value-as-string term-id (null-pointer)) :junk-allowed t))
124
 
125
 (declaim (inline term-value-as-decimal))
126
 (defun term-value-as-decimal (term-id)
127
   "Returns the value of a term as a decimal number."
128
   (declare (type fixnum term-id))
129
   (parse-decimal (%%term-value-as-string term-id (null-pointer))))
130
 
131
 (declaim (inline term-value-as-universal-time))
132
 (defun term-value-as-universal-time (term-id)
133
   "Returns the value of a term as a universal time.
134
    Returns NIL for times prior to midnight on January 1, 1900 UTC."
135
   (declare (type fixnum term-id))
136
   (let* ((unix-epoch #.(encode-universal-time 0 0 0 1 1 1970 0))
137
          (unix-time-in-useconds (%%term-value-as-time-in-usec term-id (null-pointer)))
138
          (unix-time-in-seconds (truncate unix-time-in-useconds 1000000))
139
          (lisp-time-in-seconds (+ unix-epoch unix-time-in-seconds)))
140
     (when (>= lisp-time-in-seconds 0) lisp-time-in-seconds)))
141
 
142
 (declaim (inline term-value-as-decoded-time))
143
 (defun term-value-as-decoded-time (term-id)
144
   "Returns the value of a term as a decoded time."
145
   (declare (type fixnum term-id))
146
   (let ((u-time (term-value-as-universal-time term-id)))
147
     (when u-time (decode-universal-time u-time 0))))
148
 
149
 (declaim (inline term-value-as-unix-time))
150
 (defun term-value-as-unix-time (term-id)
151
   "Returns the value of this term as microseconds since the Unix epoch."
152
   (declare (type fixnum term-id))
153
   (%%term-value-as-time-in-usec term-id (null-pointer)))