The GOOPS "unbound" value is a unique pair
[bpt/guile.git] / module / oop / goops / active-slot.scm
1 ;;; installed-scm-file
2
3 ;;;; Copyright (C) 1999, 2001, 2006, 2009, 2015 Free Software Foundation, Inc.
4 ;;;; Copyright (C) 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
5 ;;;;
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;;
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ;;;;
20
21 \f
22 ;;;;
23 ;;;; This file was based upon active-slot.stklos from the STk distribution
24 ;;;; version 4.0.1 by Erick Gallesio <eg@unice.fr>.
25 ;;;;
26
27 (define-module (oop goops active-slot)
28 :use-module (oop goops internal)
29 :export (<active-class>))
30
31 (define-class <active-class> (<class>))
32
33 (define-method (compute-get-n-set (class <active-class>) slot)
34 (if (eq? (slot-definition-allocation slot) #:active)
35 (let* ((index (slot-ref class 'nfields))
36 (s (cdr slot))
37 (before-ref (get-keyword #:before-slot-ref s #f))
38 (after-ref (get-keyword #:after-slot-ref s #f))
39 (before-set! (get-keyword #:before-slot-set! s #f))
40 (after-set! (get-keyword #:after-slot-set! s #f))
41 (unbound *unbound*))
42 (slot-set! class 'nfields (+ index 1))
43 (list (lambda (o)
44 (if before-ref
45 (if (before-ref o)
46 (let ((res (struct-ref o index)))
47 (and after-ref (not (eqv? res unbound)) (after-ref o))
48 res)
49 *unbound*)
50 (let ((res (struct-ref o index)))
51 (and after-ref (not (eqv? res unbound)) (after-ref o))
52 res)))
53
54 (lambda (o v)
55 (if before-set!
56 (if (before-set! o v)
57 (begin
58 (struct-set! o index v)
59 (and after-set! (after-set! o v))))
60 (begin
61 (struct-set! o index v)
62 (and after-set! (after-set! o v)))))))
63 (next-method)))