X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=attrib-class.lisp;h=1c15e345d27c5e3990be8e63d79421afd4069b8c;hp=215089f03a0e3d3e868334005ec794294dfd98a2;hb=4de7f25a69c218303f170314ac26217770a531ed;hpb=0e5343fda28c559f11e003805727f4c625d178f3 diff --git a/attrib-class.lisp b/attrib-class.lisp index 215089f..1c15e34 100644 --- a/attrib-class.lisp +++ b/attrib-class.lisp @@ -7,12 +7,13 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: attrib-class.lisp,v 1.2 2002/10/06 13:30:17 kevin Exp $ +;;;; $Id: attrib-class.lisp,v 1.6 2003/04/28 23:51:59 kevin Exp $ ;;;; -;;;; This file, part of Kmrcl, is Copyright (c) 2002 by Kevin M. Rosenberg +;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; -;;;; Kmrcl users are granted the rights to distribute and use this software -;;;; as governed by the terms of the GNU General Public License. +;;;; KMRCL users are granted the rights to distribute and use this software +;;;; as governed by the terms of the Lisp Lesser GNU Public License +;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. ;;;; ************************************************************************* ;;;; Defines a metaclass that allows the use of attributes (or subslots) @@ -20,58 +21,64 @@ (in-package :kmrcl) -(defclass attributes-dsd (mop::standard-direct-slot-definition) - ((attributes :initarg :attributes :initform nil - :accessor attributes))) +(defclass attributes-dsd (kmr-mop:standard-direct-slot-definition) + ((attributes :initarg :attributes :initform nil + :accessor dsd-attributes))) -(defclass attributes-esd (mop::standard-effective-slot-definition) +(defclass attributes-esd (kmr-mop:standard-effective-slot-definition) ((attributes :initarg :attributes :initform nil - :accessor slot-definition-attributes))) + :accessor esd-attributes))) -(defclass attributes-class (mop::standard-class) +(defclass attributes-class (kmr-mop:standard-class) () - ) + (:documentation "metaclass that implements attributes on slots. Based +on example from AMOP")) -(defmethod mop::direct-slot-definition-class ((cl attributes-class) - &rest iargs &key attributes) - (declare (ignorable attributes)) -;; (format t "attributes:~s iargs:~s~%" attributes iargs) - (find-class 'attributes-dsd)) +#+(or cmu scl sbcl) +(defmethod kmr-mop:validate-superclass ((class attributes-class) + (superclass kmr-mop:standard-class)) + t) -(defmethod mop::compute-effective-slot-definition :around - ((cl attributes-class) slot dsds) - (declare (ignorable slot)) +(defmethod kmr-mop:direct-slot-definition-class ((cl attributes-class) + &rest iargs &key attributes) + (declare (ignore attributes)) + ;; (format t "attributes:~s iargs:~s~%" attributes iargs) + (kmr-mop:find-class 'attributes-dsd)) + +(defmethod kmr-mop:compute-effective-slot-definition :around + ((cl attributes-class) #+kmr-named-cesd name dsds) + #+kmr-named-cesd (declare (ignore name)) (apply #'make-instance 'attributes-esd - :attributes (remove-duplicates (gu:mapappend #'attributes dsds)) - (excl::compute-effective-slot-definition-initargs cl dsds)) + :attributes (remove-duplicates (mapappend #'dsd-attributes dsds)) + (kmr-mop:compute-effective-slot-definition-initargs cl dsds)) ) - #+ignore -(defmethod mop::compute-effective-slot-definition ((cl attributes-class) slot dsds) - (declare (ignorable slot)) +(defmethod kmr-mop:compute-effective-slot-definition :around + ((cl attributes-class) #+kmr-named-cesd name dsds) + #+kmr-named-cesd (declare (ignore name)) (let ((normal-slot (call-next-method))) - (setf (slot-definition-attributes normal-slot) + (setf (esd-attributes normal-slot) (remove-duplicates - (mapappend #'slot-definition-attributes dsds))) + (mapappend #'esd-attributes dsds))) normal-slot)) -(defmethod mop::compute-slots ((class attributes-class)) +(defmethod kmr-mop:compute-slots ((class attributes-class)) (let* ((normal-slots (call-next-method)) (alist (mapcar #'(lambda (slot) (let ((attr-list (mapcar #'(lambda (attr) (cons attr nil)) - (slot-definition-attributes slot)))) + (esd-attributes slot)))) (when attr-list - (cons (mop::slot-definition-name slot) attr-list)))) + (cons (kmr-mop:slot-definition-name slot) attr-list)))) normal-slots))) (setq alist (delete nil alist)) - (cons (mop::make-instance 'mop::standard-effective-slot-definition + (cons (make-instance 'kmr-mop:standard-effective-slot-definition :name 'all-attributes :initform `',alist :initfunction #'(lambda () alist)) @@ -96,29 +103,6 @@ slot-name instance attribute)) attr-bucket))) +(eval-when (:compile-toplevel :load-toplevel :execute) + (export '(attributes-class slot-attributes))) -#|| -(in-package :kmrcl) - -(defclass credit-rating () - ((level :attributes (date-set time-set)) - (id :attributes (person-setting))) - (:metaclass kmrcl:attributes-class)) -(defparameter cr (make-instance 'credit-rating)) - -(format t "~&date-set: ~a" (gu:slot-attribute cr 'level 'date-set)) -(setf (gu:slot-attribute cr 'level 'date-set) "12/15/1990") -(format t "~&date-set: ~a" (gu:slot-attribute cr 'level 'date-set)) - -(defclass monitored-credit-rating (credit-rating) - ((level :attributes (last-checked interval date-set)) - (cc :initarg :cc) - (id :attributes (verified)) - ) - (:metaclass gu:attributes-class)) -(defparameter mcr (make-instance 'monitored-credit-rating)) - -(setf (gu:slot-attribute mcr 'level 'date-set) "01/05/2002") -(format t "~&date-set for mcr: ~a" (gu:slot-attribute mcr 'level 'date-set)) - -||#