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