Automated commit for debian release 6.7.2-1
[clsql.git] / sql / kmr-mop.lisp
index c628dc2d6c98b9079af6884f440ffc48a6801660..f35528272204bdd94c4749ef483d69639a3795bd 100644 (file)
@@ -7,8 +7,6 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2003
 ;;;;
-;;;; $Id$
-;;;;
 ;;;; This file imports MOP symbols into the CLSQL-MOP package and then
 ;;;; re-exports into CLSQL-SYS them to hide differences in
 ;;;; MOP implementations.
   #+mop-slot-order-reversed (reverse (class-slots class))
   #-mop-slot-order-reversed (class-slots class))
 
+(defun ordered-class-direct-slots (class)
+  "Gets an ordered list of direct class slots"
+  ;; NB: this used to return effective-slot-definitions in direct
+  ;; opposition to the function name.  Not sure why
+  (setf class (to-class class))
+  #+mop-slot-order-reversed (reverse (class-direct-slots class))
+  #-mop-slot-order-reversed (class-direct-slots class))
+
+(defun find-slot-if (class predicate &optional direct? recurse?)
+  "Looks up a direct-slot-definition by name"
+  (setf class (to-class class))
+  (labels ((find-it (class)
+             (let* ((slots (if direct?
+                               (ordered-class-direct-slots class)
+                               (ordered-class-slots class)))
+                    (it (find-if predicate slots)))
+               (or it
+                   (when recurse?
+                     (loop for sup in (class-direct-superclasses class)
+                           for rtn = (find-it sup)
+                           until rtn
+                           finally (return rtn)))))))
+    (find-it class)))
+
+(defun find-slot-by-name (class slot-name &optional direct? recurse?)
+  "Looks up a direct-slot-definition by name"
+  (setf class (to-class class)
+        slot-name (to-slot-name slot-name))
+  (find-slot-if class (lambda (slot-def) (eql (to-slot-name slot-def) slot-name))
+                direct? recurse?))
+
 ;; Lispworks has symbol for slot rather than the slot instance
 (defun %svuc-slot-name (slot)
   #+lispworks slot