*** empty log message ***
[bpt/guile.git] / oop / goops / active-slot.scm
1 ;;; installed-scm-file
2
3 ;;;; Copyright (C) 1999 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
9 ;;;;
10 ;;;; This program 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
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 ;;;; Boston, MA 02111-1307 USA
19 ;;;;
20 \f
21
22 ;;;; This software is a derivative work of other copyrighted softwares; the
23 ;;;; copyright notices of these softwares are placed in the file COPYRIGHTS
24 ;;;;
25 ;;;; This file is based upon active-slot.stklos from the STk
26 ;;;; distribution by Erick Gallesio <eg@unice.fr>.
27 ;;;;
28
29 (define-module (oop goops active-slot)
30 :use-module (oop goops internal))
31
32 (export <active-class>)
33
34 (define-class <active-class> (<class>))
35
36 (define-method compute-get-n-set ((class <active-class>) slot)
37 (if (eq? (slot-definition-allocation slot) #:active)
38 (let* ((index (slot-ref class 'nfields))
39 (name (car slot))
40 (s (cdr slot))
41 (env (class-environment class))
42 (before-ref (get-keyword #:before-slot-ref s #f))
43 (after-ref (get-keyword #:after-slot-ref s #f))
44 (before-set! (get-keyword #:before-slot-set! s #f))
45 (after-set! (get-keyword #:after-slot-set! s #f))
46 (unbound (make-unbound)))
47 (slot-set! class 'nfields (+ index 1))
48 (list (lambda (o)
49 (if before-ref
50 (if (before-ref o)
51 (let ((res (%fast-slot-ref o index)))
52 (and after-ref (not (eqv? res unbound)) (after-ref o))
53 res)
54 (make-unbound))
55 (let ((res (%fast-slot-ref o index)))
56 (and after-ref (not (eqv? res unbound)) (after-ref o))
57 res)))
58
59 (lambda (o v)
60 (if before-set!
61 (if (before-set! o v)
62 (begin
63 (%fast-slot-set! o index v)
64 (and after-set! (after-set! o v))))
65 (begin
66 (%fast-slot-set! o index v)
67 (and after-set! (after-set! o v)))))))
68 (next-method)))