3 ;;;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
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.
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.
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
22 ;;;; This software is a derivative work of other copyrighted softwares; the
23 ;;;; copyright notices of these softwares are placed in the file COPYRIGHTS
25 ;;;; This file is based upon composite-slot.stklos from the STk
26 ;;;; distribution by Erick Gallesio <eg@unice.fr>.
29 (define-module (oop goops composite-slot)
30 :use-module (oop goops))
32 (export <composite-class>)
35 ;;; (define-class CLASS SUPERS
39 ;;; (SLOT #:allocation #:propagated
40 ;;; #:propagate-to '(PROPAGATION ...))
42 ;;; #:metaclass <composite-class>)
44 ;;; PROPAGATION ::= OBJECT | (OBJECT TARGETSLOT)
46 ;;; The slot SLOT will be propagated to the slot TARGETSLOT in the object
47 ;;; stored in slot OBJECT. If TARGETSLOT is omitted, assume that the target
48 ;;; slot is named SLOT.
51 (define-class <composite-class> (<class>))
53 (define-method compute-get-n-set ((class <composite-class>) slot)
54 (if (eq? (slot-definition-allocation slot) #:propagated)
55 (compute-propagated-get-n-set slot)
58 (define (compute-propagated-get-n-set s)
59 (let ((prop (get-keyword #:propagate-to (cdr s) #f))
60 (s-name (slot-definition-name s)))
63 (goops-error "Propagation not specified for slot ~S" s-name))
64 (if (not (pair? prop))
65 (goops-error "Bad propagation list for slot ~S" s-name))
67 (let ((objects (map (lambda (p) (if (pair? p) (car p) p)) prop))
68 (slots (map (lambda (p) (if (pair? p) (cadr p) s-name)) prop)))
69 (let ((first-object (car objects))
70 (first-slot (car slots)))
74 (slot-ref (slot-ref o first-object) first-slot))
77 (if (null? (cdr objects))
79 (slot-set! (slot-ref o first-object) first-slot v))
81 (for-each (lambda (object slot)
82 (slot-set! (slot-ref o object) slot v))