tons of small changes to bring this up to date with maxclaims 2.0
[clinton/lisp-on-lines.git] / src / description-class.lisp
index fb6e7ff..bba188e 100644 (file)
@@ -14,6 +14,7 @@
 
 (define-layered-class description-access-class (standard-layer-class contextl::special-layered-access-class )
   ((defined-in-descriptions :initarg :in-description)
+   (class-active-attributes-definition :initarg :attributes)
    (mixin-class-p :initarg :mixinp)))
 
 (defmethod direct-slot-definition-class
     NIL)
   (:method ((description standard-description-object))
     T))
-  
-(defun initialize-description-class (class)
-
-;;; HACK: initialization does not happ   en properly 
-;;; when compiling and loading or something like that.
-;;; Obviously i'm not sure why.
-;;; So we're going to explicitly initialize things.
-;;; For now. --drewc
-
-  (pushnew class *defined-descriptions*)
 
-;;; ENDHACK.
-  
-  (let* ((description (find-layer class)) 
-        (attribute-objects 
-         (setf (description-class-attributes (class-of description))
-               (mapcar 
-                (lambda (slot)
-                  (or (find-attribute description 
-                                      (slot-definition-name slot))
-                      (let* ((*init-time-description* description)
-                             (attribute-class (or 
-                                               (ignore-errors 
-                                                 (slot-value-using-class 
-                                                  (class-of description) description slot))
-                                               'standard-attribute))
-                             (attribute                     
-                              (apply #'make-instance 
-                                     attribute-class
-                                     :description description
-                                     :attribute-class attribute-class
-                                     (attribute-object-initargs slot))))
-                        (setf (slot-definition-attribute-object slot) attribute))))
-                (remove 'described-object (class-slots (class-of description))
-                        :key #'slot-definition-name))))
-        (defining-classes 
-         (partial-class-defining-classes class)))
+(defun compute-effective-attribute-objects (description)
+  (mapcar 
+   (lambda (slot)
+     (or (find-attribute description 
+                        (slot-definition-name slot) nil)
+        (let* ((*init-time-description* description)
+               (attribute-class (or 
+                                 (ignore-errors 
+                                   (slot-value-using-class 
+                                    (class-of description) description slot))
+                                 'standard-attribute))
+               (attribute                   
+                (apply #'make-instance 
+                       attribute-class
+                       :description description
+                       :attribute-class attribute-class
+                       (attribute-object-initargs slot))))
+          (setf (slot-definition-attribute-object slot) attribute))))
+   (remove 'described-object (class-slots (class-of description))
+          :key #'slot-definition-name)))
+
+(defmacro with-described-object ((object description &rest args)
+                                &body body)
+    `(funcall-with-described-object 
+      (lambda () ,@body)
+      ,object
+      ,description
+      ,@args))
+
+(defun initialize-effective-attribute-values-for-description-class (class description attribute-objects)
 
     (loop 
        :for (layer class) 
-       :on  defining-classes :by #'cddr 
+       :on    (partial-class-defining-classes class) :by #'cddr 
        :do (funcall-with-layer-context 
            (adjoin-layer (find-layer layer) (current-layer-context))
            (lambda ()
                                initargs )
                         (setf (slot-value description (attribute-name attribute)) 
                               (attribute-class attribute))
-                        (apply #'change-class attribute  (attribute-class attribute)
-                               initargs)))))))))
-
-
-#+old(defun initialize-description-class (class)
+                        (apply #'change-class attribute  (find-class (attribute-class attribute))
+                               initargs))))
+             (when (slot-boundp  class 'class-active-attributes-definition)
+             (with-described-object (nil description) 
+               (setf (slot-value (find-attribute description 'active-attributes) 'value) 
+                     (slot-value class 'class-active-attributes-definition))))))))
+    
+(defun initialize-description-class (class)
 
 ;;; HACK: initialization does not happ   en properly 
 ;;; when compiling and loading or something like that.
   (pushnew class *defined-descriptions*)
 
 ;;; ENDHACK.
-
+  
   (let* ((description (find-layer class)) 
         (attribute-objects 
-         (mapcar 
-          (lambda (slot)
-            (let* ((*init-time-description* description)
-                         (attribute                 
-                          (apply #'make-instance 
-                           'standard-attribute
-                           :description description
-                           (attribute-object-initargs slot))))
-              
-                    
-              (setf (slot-definition-attribute-object slot) attribute)))
-          (remove 'described-object (class-slots (class-of description))
-                  :key #'slot-definition-name)))
-        (defining-classes (partial-class-defining-classes (class-of description))))
+         (setf (description-class-attributes (class-of description))
+               (compute-effective-attribute-objects description))))
+
+    (initialize-effective-attribute-values-for-description-class class description attribute-objects)
+))
+
 
-    (loop 
-       :for (layer class) 
-       :on  defining-classes :by #'cddr 
-       :do (funcall-with-layer-context 
-           (adjoin-layer (find-layer layer) (current-layer-context))
-           (lambda ()
-             (loop :for direct-slot :in (class-direct-slots class) 
-                :do (let ((attribute 
-                           (find (slot-definition-name direct-slot) 
-                                 attribute-objects 
-                                 :key #'attribute-name)))
-                      (let ((initargs 
-                             (prepare-initargs attribute (direct-attribute-properties direct-slot))))
-                        
-                        (apply #'reinitialize-instance attribute 
-                               initargs )
-                        (warn "Attribute class for ~A is ~A" attribute (attribute-class attribute))
-                        (when (not (eq (find-class (attribute-class attribute))
-                                       (class-of attribute)))
-                          (warn "~%CHANGING CLASS~%")
-                          
-                          (apply #'change-class attribute  (attribute-class attribute) 
-                                 initargs))))))))))
 
 ;;;; HACK: run this at startup till we figure things out.
 (defun initialize-descriptions () 
   (print-unreadable-object (object stream :type t :identity t)
     (princ  (ignore-errors (description-print-name (find-layer object))) stream)))
 
-(defun find-description (name)
-  (find-layer (find-class (defining-description name))))
+(defun find-description (name &optional (errorp t))
+  (let ((class (find-class (defining-description name) errorp)))
+    (when class (find-layer class))))