1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10-*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: attrib-class.lisp
6 ;;;; Purpose: Defines metaclass allowing use of attributes on slots
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; This file, part of KMRCL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
12 ;;;; KMRCL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
17 ;; Disable attrib class until understand changes in sbcl/cmucl
18 ;; using COMPUTE-SLOT-ACCESSOR-INFO and defining method
19 ;; for slot access of ALL-ATTRIBUTES. Does this work on Allegro/LW?
21 ;;;; Defines a metaclass that allows the use of attributes (or subslots)
22 ;;;; on slots. Based on example in AMOP, but modified to use ACL's MOP.
26 (defclass attributes-class (kmr-mop:standard-class)
28 (:documentation "metaclass that implements attributes on slots. Based
29 on example from AMOP"))
31 (defclass attributes-dsd (kmr-mop:standard-direct-slot-definition)
32 ((attributes :initarg :attributes :initform nil
33 :accessor dsd-attributes)))
35 (defclass attributes-esd (kmr-mop:standard-effective-slot-definition)
36 ((attributes :initarg :attributes :initform nil
37 :accessor esd-attributes)))
39 ;; encapsulating macro for Lispworks
40 (kmr-mop:process-slot-option attributes-class :attributes)
42 #+(or cmu scl sbcl ccl)
43 (defmethod kmr-mop:validate-superclass ((class attributes-class)
44 (superclass kmr-mop:standard-class))
47 (defmethod kmr-mop:direct-slot-definition-class ((cl attributes-class) #+kmrcl::normal-dsdc &rest initargs)
48 (declare (ignore initargs))
49 (kmr-mop:find-class 'attributes-dsd))
51 (defmethod kmr-mop:effective-slot-definition-class ((cl attributes-class) #+kmrcl::normal-dsdc &rest initargs)
52 (declare (ignore initargs))
53 (kmr-mop:find-class 'attributes-esd))
55 (defmethod kmr-mop:compute-effective-slot-definition
56 ((cl attributes-class) #+kmrcl::normal-cesd name dsds)
57 #+kmrcl::normal-cesd (declare (ignore name))
58 (let ((esd (call-next-method)))
59 (setf (esd-attributes esd) (remove-duplicates (mapappend #'dsd-attributes dsds)))
62 ;; This does not work in Lispworks prior to version 4.3
64 (defmethod kmr-mop:compute-slots ((class attributes-class))
65 (let* ((normal-slots (call-next-method))
68 (cons (kmr-mop:slot-definition-name slot)
69 (mapcar #'(lambda (attr) (list attr))
70 (esd-attributes slot))))
77 :initfunction #'(lambda () alist)
79 :documentation "Attribute bucket"
84 (defun slot-attribute (instance slot-name attribute)
85 (cdr (slot-attribute-bucket instance slot-name attribute)))
87 (defun (setf slot-attribute) (new-value instance slot-name attribute)
88 (setf (cdr (slot-attribute-bucket instance slot-name attribute))
91 (defun slot-attribute-bucket (instance slot-name attribute)
92 (let* ((all-buckets (slot-value instance 'all-attributes))
93 (slot-bucket (assoc slot-name all-buckets)))
95 (error "The slot named ~S of ~S has no attributes."
97 (let ((attr-bucket (assoc attribute (cdr slot-bucket))))
99 (error "The slot named ~S of ~S has no attributes named ~S."
100 slot-name instance attribute))