X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=hyperobject.lisp;h=ee71a8feeff1013961b457395d0fab719dc1451b;hb=7ffe31bff2d7daa3df28ed34fe439f7e541ffbb5;hp=0e34dcdfc22141da79484a1b529e921d8e2ca18f;hpb=eeecdad997c633f810028c741e9562554e6f105d;p=hyperobject.git diff --git a/hyperobject.lisp b/hyperobject.lisp index 0e34dcd..ee71a8f 100644 --- a/hyperobject.lisp +++ b/hyperobject.lisp @@ -11,13 +11,13 @@ ;;;; in Text, HTML, and XML formats. This includes hyperlinking ;;;; capability and sub-objects. ;;;; -;;;; $Id: hyperobject.lisp,v 1.2 2002/11/03 20:06:19 kevin Exp $ +;;;; $Id: hyperobject.lisp,v 1.6 2002/11/22 15:43:22 kevin Exp $ ;;;; ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg ;;;; ;;;; ************************************************************************* -(in-package :hyperobject) +(in-package :hyperobject-mop) (eval-when (:compile-toplevel :execute) @@ -26,34 +26,69 @@ ;; Utilities -(defun kmr-class-of (obj) +(defun portable-class-of (obj) #-(or cmu sbcl) (class-of obj) #+sbcl (sb-pcl:class-of obj) #+cmu (pcl:class-of obj)) -(defun kmr-class-name (obj) +(defun portable-class-name (obj) #-(or cmu sbcl) (class-name obj) #+sbcl (sb-pcl:class-name obj) #+cmu (pcl:class-name obj)) +(defun portable-class-slots (obj) + #+allegro (mop:class-slots obj) + #+lispworks (clos:class-slots obj) + #+sbcl (sb-pcl:class-slots obj) + #+(or cmu scl) (pcl:class-slots obj)) + +(defun portable-slot-name (obj) + #+allegro (mop::slot-definition-name obj) + #+lispworks (clos::slot-definition-name obj) + #+sbcl (sb-pcl::slot-definition-name obj) + #+(or cmu scl) (pcl::slot-definition-name obj)) + + +;; Slot definitions + + + +(defclass hyperobject-dsd (#+allegro mop::standard-direct-slot-definition + #+lispworks clos:standard-direct-slot-definition + #+sbcl sb-pcl::standard-direct-slot-definition + #+(or scl cmucl) pcl::standard-direct-slot-definition + ) + ((ho-type :initarg :ho-type :initform nil :accessor dsd-ho-type) + (format-func :initarg :format-func :initform nil :accessor dsd-format-func) + (subobject :initarg :subobject :initform nil :accessor dsd-subobject) + (reference :initarg :reference :initform nil :accessor dsd-reference) + )) + +(defclass hyperobject-esd (#+allegro mop::standard-effective-slot-definition + #+lispworks clos:standard-effective-slot-definition + #+sbcl sb-pcl::standard-effective-slot-definition + #+(or scl cmucl) pcl::standard-effective-slot-definition + ) + ((ho-type :initarg :ho-type :initform nil :accessor esd-ho-type) + (format-func :initarg :format-func :initform nil :accessor esd-format-func) + (subobject :initarg :subobject :initform nil :accessor esd-subobject) + (reference :initarg :reference :initform nil :accessor esd-reference) + )) + ;; Main class -(defclass ho-class (#-(or cmu sbcl) standard-class +(defclass hyperobject-class (#-(or cmu sbcl) standard-class #+cmu pcl::standard-class #+sbcl sb-pcl::standard-class) ((title :initarg :title :type string :reader ml-std-title :documentation "Print Title for class") - (fields :initarg :fields :reader ml-std-fields - :documentation -"List of field lists for printing. Format is - ((fieldname type optional-formatter) ... )") - (subobjects-lists - :initarg :subobjects-lists :reader ml-std-subobjects-lists + (subobjects + :initarg :subobjects :documentation "List of fields that contain a list of subobjects objects.") - (ref-fields - :initarg :ref-fields :type list :reader ml-std-ref-field + (references + :initarg :references :type list :reader ml-std-references :documentation "List of fields that can be referred to by browsers. Format is ((field-name field-lookup-func other-link-params) ...)") @@ -73,80 +108,139 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (fmtstr-html-ref-labels :initform nil :type string :reader ml-std-fmtstr-html-ref-labels) (fmtstr-xml-ref-labels :initform nil :type string :reader ml-std-fmtstr-xml-ref-labels) ) - (:default-initargs :title nil :fields nil :subobjects-lists nil :ref-fields nil) + (:default-initargs :title nil :subobjects nil :references nil) (:documentation "Metaclass for Markup Language classes.")) +(defclass subobject () + ((name :type symbol :initform nil :initarg :name :reader name) + (reader :type function :initform nil :initarg :reader :reader reader))) + +(defmethod print-object ((obj subobject) (s stream)) + (print-unreadable-object (obj s :type t :identity t) + (format s "~S" (name obj)))) + +(defclass reference () + ((name :type symbol :initform nil :initarg :name :reader name) + (lookup :type function :initform nil :initarg :lookup :reader lookup) + (link-parameters :type list :initform nil :initarg :link-parameters + :reader link-parameters))) + +(defmethod print-object ((obj reference) (s stream)) + (print-unreadable-object (obj s :type t :identity t) + (format s "~S" (name obj)))) + #+cmu -(defmethod pcl:finalize-inheritance :after ((cl ho-class)) - (init-ho-class cl)) +(defmethod pcl:finalize-inheritance :after ((cl hyperobject-class)) + (init-hyperobject-class cl)) #+scl -(defmethod clos:finalize-inheritance :after ((cl ho-class)) - (init-ho-class cl)) +(defmethod clos:finalize-inheritance :after ((cl hyperobject-class)) + (init-hyperobject-class cl)) #+sbcl -(defmethod sb-pcl:finalize-inheritance :after ((cl ho-class)) - (init-ho-class cl)) +(defmethod sb-pcl:finalize-inheritance :after ((cl hyperobject-class)) + (init-hyperobject-class cl)) #+cmu -(defmethod pcl:validate-superclass ((class ho-class) (superclass pcl::standard-class)) +(defmethod pcl:validate-superclass ((class hyperobject-class) (superclass pcl::standard-class)) t) #+scl -(defmethod clos:validate-superclass ((class ho-class) (superclass standard-class)) +(defmethod clos:validate-superclass ((class hyperobject-class) (superclass standard-class)) t) #+sbcl -(defmethod sb-pcl:validate-superclass ((class ho-class) (superclass sb-pcl::standard-class)) +(defmethod sb-pcl:validate-superclass ((class hyperobject-class) (superclass sb-pcl::standard-class)) t) #+allegro -(defmethod mop:finalize-inheritance :after ((cl ho-class)) - (init-ho-class cl)) +(defmethod mop:finalize-inheritance :after ((cl hyperobject-class)) + (init-hyperobject-class cl)) #+lispworks -(defmethod clos:finalize-inheritance :after ((cl ho-class)) - (init-ho-class cl)) +(defmethod clos:finalize-inheritance :after ((cl hyperobject-class)) + (init-hyperobject-class cl)) + +;; Slot definitions +#+allegro +(defmethod mop:direct-slot-definition-class ((cl hyperobject-class) + &rest iargs) + (find-class 'hyperobject-dsd)) + +#+lispworks +(defmethod clos:direct-slot-definition-class ((cl hyperobject-class) iargs) + (find-class 'hyperobject-dsd)) + +#+sbcl +(defmethod sb-pcl:direct-slot-definition-class ((cl hyperobject-class) iargs) + (find-class 'hyperobject-dsd)) + +#+(or cmucl scl) +(defmethod pcl:direct-slot-definition-class ((cl hyperobject-class) iargs) + (find-class 'hyperobject-dsd)) + + + #+lispworks -(defmethod clos:process-a-class-option ((class ho-class) +(defmethod clos:process-a-class-option ((class hyperobject-class) (name (eql :title)) value) (unless value - (error "ho-class title must have a value")) + (error "hyperobject-class title must have a value")) (if (null (cdr value)) (list name (car value)) (list name `',value))) -#+lispworks -(defmethod clos:process-a-class-option ((class ho-class) - (name (eql :fields)) - value) - (unless value - (error "ho-class fields must have a value")) - (list name `',value)) - -#+lispworks -(defmethod clos:process-a-class-option ((class ho-class) - (name (eql :ref-fields)) - value) - (unless value - (error "ho-class ref-fields must have a value")) - (list name `',value)) +(defmethod + #+allegro clos:compute-effective-slot-definition + #+lispworks clos:compute-effective-slot-definition + #+sbcl sb-pcl::compute-effective-slot-definition + #+(or cmucl scl) pcl::compute-effective-slot-definition + :around ((cl hyperobject-class) #+(or allegro lispworks) slot dsds) + (declare (ignorable slot)) + (let* ((dsd (car dsds)) + (ho-type (slot-value dsd 'type))) + (setf (slot-value dsd 'ho-type) ho-type) + (setf (slot-value dsd 'type) (convert-ho-type ho-type)) + (let ((ia + #+allegro (excl::compute-effective-slot-definition-initargs cl dsds) + #+lispworks (clos::compute-effective-slot-definition-initargs cl slot dsds) + #+sbcl (sb-pcl::compute-effective-slot-definition-initargs cl dsds) + #+(or cmucl scl) (pcl::compute-effective-slot-definition-initargs cl dsds) + )) + (apply + #'make-instance 'hyperobject-esd + :ho-type ho-type + :format-func (slot-value dsd 'format-func) + :subobject (slot-value dsd 'subobject) + :reference (slot-value dsd 'reference) + ia))) + ) -#+lispworks -(defmethod clos:process-a-class-option ((class ho-class) - (name (eql :subobjects-lists)) - value) - (unless value - (error "ho-class subobjects-lists must have a value")) - (list name `',value)) +(defun convert-ho-type (ho-type) + (check-type ho-type symbol) + (case (intern (symbol-name ho-type) (symbol-name :keyword)) + (:string + 'string) + (:fixnum + 'fixnum) + (:boolean + 'boolean) + (:integer + 'integer) + (:cdata + 'string) + (:float + 'float) + (otherwise + ho-type))) ;;;; Class initialization function -(defun init-ho-class (cl) +(defun init-hyperobject-class (cl) (let ((fmtstr-text "") (fmtstr-html "") (fmtstr-xml "") @@ -160,48 +254,55 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (first-field t) (value-func '()) (xmlvalue-func '()) - (classname (class-name cl)) - (package (symbol-package (kmr-class-name cl))) - (ref-fields (slot-value cl 'ref-fields))) + (classname (portable-class-name cl)) + (package (symbol-package (portable-class-name cl))) + (references nil) + (subobjects nil)) (declare (ignore classname)) - (dolist (f (slot-value cl 'fields)) - (let ((name (car f)) - (namestr (symbol-name (car f))) - (namestr-lower (string-downcase (symbol-name (car f)))) - (type (cadr f)) - (formatter (caddr f)) - (value-fmt "~a") - (plain-value-func nil) - html-str xml-str html-label-str xml-label-str) - - (when (or (eql type :integer) (eql type :fixnum)) - (setq value-fmt "~d")) - - (when (eql type :commainteger) - (setq value-fmt "~:d")) - - (when (eql type :boolean) - (setq value-fmt "~a")) - - (if first-field - (setq first-field nil) - (progn - (string-append fmtstr-text " ") - (string-append fmtstr-html " ") - (string-append fmtstr-xml " ") - (string-append fmtstr-text-labels " ") - (string-append fmtstr-html-labels " ") - (string-append fmtstr-xml-labels " ") - (string-append fmtstr-html-ref " ") - (string-append fmtstr-xml-ref " ") - (string-append fmtstr-html-ref-labels " ") - (string-append fmtstr-xml-ref-labels " "))) - - (setq html-str (concatenate 'string "" value-fmt "")) - (setq xml-str (concatenate 'string "<" namestr-lower ">" value-fmt "")) - (setq html-label-str (concatenate 'string "" namestr-lower " " value-fmt "")) - (setq xml-label-str (concatenate 'string " <" namestr-lower ">" value-fmt "")) - + (dolist (f (portable-class-slots cl)) + (if (slot-value f 'subobject) + (push (make-instance 'subobject :name (portable-slot-name f) + :reader (if (eq t (esd-subobject f)) + (portable-slot-name f) + (esd-subobject f))) + subobjects) + (let ((name (portable-slot-name f)) + (namestr (symbol-name (portable-slot-name f))) + (namestr-lower (string-downcase (symbol-name (portable-slot-name f)))) + (type (slot-value f 'ho-type)) + (formatter (slot-value f 'format-func)) + (value-fmt "~a") + (plain-value-func nil) + html-str xml-str html-label-str xml-label-str) + + (when (or (eql type :integer) (eql type :fixnum)) + (setq value-fmt "~d")) + + (when (eql type :commainteger) + (setq value-fmt "~:d")) + + (when (eql type :boolean) + (setq value-fmt "~a")) + + (if first-field + (setq first-field nil) + (progn + (string-append fmtstr-text " ") + (string-append fmtstr-html " ") + (string-append fmtstr-xml " ") + (string-append fmtstr-text-labels " ") + (string-append fmtstr-html-labels " ") + (string-append fmtstr-xml-labels " ") + (string-append fmtstr-html-ref " ") + (string-append fmtstr-xml-ref " ") + (string-append fmtstr-html-ref-labels " ") + (string-append fmtstr-xml-ref-labels " "))) + + (setq html-str (concatenate 'string "" value-fmt "")) + (setq xml-str (concatenate 'string "<" namestr-lower ">" value-fmt "")) + (setq html-label-str (concatenate 'string "" namestr-lower " " value-fmt "")) + (setq xml-label-str (concatenate 'string " <" namestr-lower ">" value-fmt "")) + (string-append fmtstr-text value-fmt) (string-append fmtstr-html html-str) (string-append fmtstr-xml xml-str) @@ -209,29 +310,34 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (string-append fmtstr-html-labels html-label-str) (string-append fmtstr-xml-labels xml-label-str) - (if (find name ref-fields :key #'car) - (progn - (string-append fmtstr-html-ref "<~~a>" value-fmt "") - (string-append fmtstr-xml-ref "<~~a>" value-fmt "") - (string-append fmtstr-html-ref-labels "" namestr-lower " <~~a>" value-fmt "") - (string-append fmtstr-xml-ref-labels " <~~a>" value-fmt "")) - (progn - (string-append fmtstr-html-ref html-str) - (string-append fmtstr-xml-ref xml-str) - (string-append fmtstr-html-ref-labels html-label-str) - (string-append fmtstr-xml-ref-labels xml-label-str))) + (if (esd-reference f) + (progn + (string-append fmtstr-html-ref "<~~a>" value-fmt "") + (string-append fmtstr-xml-ref "<~~a>" value-fmt "") + (string-append fmtstr-html-ref-labels "" namestr-lower " <~~a>" value-fmt "") + (string-append fmtstr-xml-ref-labels " <~~a>" value-fmt "") + (push (make-instance 'reference :name name :lookup (esd-reference f)) + references)) + (progn + (string-append fmtstr-html-ref html-str) + (string-append fmtstr-xml-ref xml-str) + (string-append fmtstr-html-ref-labels html-label-str) + (string-append fmtstr-xml-ref-labels xml-label-str))) (if formatter (setq plain-value-func - (list `(,formatter (,(intern namestr package) x)))) - (setq plain-value-func - (list `(,(intern namestr package) x)))) + (list `(,formatter (,(intern namestr package) x)))) + (setq plain-value-func + (list `(,(intern namestr package) x)))) (setq value-func (append value-func plain-value-func)) (if (eql type :cdata) (setq xmlvalue-func (append xmlvalue-func (list `(xml-cdata ,@plain-value-func)))) - (setq xmlvalue-func (append xmlvalue-func plain-value-func))) - )) + (setq xmlvalue-func (append xmlvalue-func plain-value-func))) + ))) + + (setf (slot-value cl 'references) references) + (setf (slot-value cl 'subobjects) subobjects) (if value-func (setq value-func `(lambda (x) (values ,@value-func))) @@ -258,66 +364,66 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (values)) -(defun ho-class-fmtstr-text (obj) - (slot-value (kmr-class-of obj) 'fmtstr-text)) +(defun hyperobject-class-fmtstr-text (obj) + (slot-value (portable-class-of obj) 'fmtstr-text)) -(defun ho-class-fmtstr-html (obj) - (slot-value (kmr-class-of obj) 'fmtstr-html)) +(defun hyperobject-class-fmtstr-html (obj) + (slot-value (portable-class-of obj) 'fmtstr-html)) -(defun ho-class-fmtstr-xml (obj) - (slot-value (kmr-class-of obj) 'fmtstr-xml)) +(defun hyperobject-class-fmtstr-xml (obj) + (slot-value (portable-class-of obj) 'fmtstr-xml)) -(defun ho-class-fmtstr-text-labels (obj) - (slot-value (kmr-class-of obj) 'fmtstr-text-labels)) +(defun hyperobject-class-fmtstr-text-labels (obj) + (slot-value (portable-class-of obj) 'fmtstr-text-labels)) -(defun ho-class-fmtstr-html-labels (obj) - (slot-value (kmr-class-of obj) 'fmtstr-html-labels)) +(defun hyperobject-class-fmtstr-html-labels (obj) + (slot-value (portable-class-of obj) 'fmtstr-html-labels)) -(defun ho-class-fmtstr-xml-labels (obj) - (slot-value (kmr-class-of obj) 'fmtstr-xml-labels)) +(defun hyperobject-class-fmtstr-xml-labels (obj) + (slot-value (portable-class-of obj) 'fmtstr-xml-labels)) -(defun ho-class-value-func (obj) - (slot-value (kmr-class-of obj) 'value-func)) +(defun hyperobject-class-value-func (obj) + (slot-value (portable-class-of obj) 'value-func)) -(defun ho-class-xmlvalue-func (obj) - (slot-value (kmr-class-of obj) 'xmlvalue-func)) +(defun hyperobject-class-xmlvalue-func (obj) + (slot-value (portable-class-of obj) 'xmlvalue-func)) (eval-when (:compile-toplevel :load-toplevel :execute) -(defun ho-class-title (obj) - (awhen (slot-value (kmr-class-of obj) 'title) +(defun hyperobject-class-title (obj) + (awhen (slot-value (portable-class-of obj) 'title) (if (consp it) (car it) it)))) -(defun ho-class-subobjects-lists (obj) - (slot-value (kmr-class-of obj) 'subobjects-lists)) +(defun hyperobject-class-subobjects (obj) + (slot-value (portable-class-of obj) 'subobjects)) -(defun ho-class-ref-fields (obj) - (slot-value (kmr-class-of obj) 'ref-fields)) +(defun hyperobject-class-references (obj) + (slot-value (portable-class-of obj) 'references)) -(defun ho-class-fields (obj) - (slot-value (kmr-class-of obj) 'fields)) +(defun hyperobject-class-fields (obj) + (portable-class-slots (portable-class-of obj))) -(defun ho-class-fmtstr-html-ref (obj) - (slot-value (kmr-class-of obj) 'fmtstr-html-ref)) +(defun hyperobject-class-fmtstr-html-ref (obj) + (slot-value (portable-class-of obj) 'fmtstr-html-ref)) -(defun ho-class-fmtstr-xml-ref (obj) - (slot-value (kmr-class-of obj) 'fmtstr-xml-ref)) +(defun hyperobject-class-fmtstr-xml-ref (obj) + (slot-value (portable-class-of obj) 'fmtstr-xml-ref)) -(defun ho-class-fmtstr-html-ref-labels (obj) - (slot-value (kmr-class-of obj) 'fmtstr-html-ref-labels)) +(defun hyperobject-class-fmtstr-html-ref-labels (obj) + (slot-value (portable-class-of obj) 'fmtstr-html-ref-labels)) -(defun ho-class-fmtstr-xml-ref-labels (obj) - (slot-value (kmr-class-of obj) 'fmtstr-xml-ref-labels)) +(defun hyperobject-class-fmtstr-xml-ref-labels (obj) + (slot-value (portable-class-of obj) 'fmtstr-xml-ref-labels)) ;;; Class name functions -(defgeneric ho-class-stdname (x)) -(defmethod ho-class-stdname ((name string)) +(defgeneric hyperobject-class-stdname (x)) +(defmethod hyperobject-class-stdname ((name string)) (string-downcase (subseq name 1))) -(defmethod ho-class-stdname ((cl standard-object)) - (string-downcase (subseq (kmr-class-name (kmr-class-of cl)) 1))) +(defmethod hyperobject-class-stdname ((cl standard-object)) + (string-downcase (subseq (portable-class-name (portable-class-of cl)) 1))) ;;;; Generic Print functions @@ -357,7 +463,7 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (:null *default-nullformat*) (otherwise *default-textformat*))) -;;;; Output format classes for print ho-classes +;;;; Output format classes for print hyperobject-classes (defclass dataformat () ((file-start-str :type string :initarg :file-start-str :reader file-start-str) @@ -395,7 +501,7 @@ Format is ((field-name field-lookup-func other-link-params) ...)") ()) (defun text-list-start-value-func (obj nitems) - (values (ho-class-title obj) nitems)) + (values (hyperobject-class-title obj) nitems)) (defclass textformat (dataformat) () @@ -403,17 +509,17 @@ Format is ((field-name field-lookup-func other-link-params) ...)") :list-start-value-func #'text-list-start-value-func :list-start-indent t :obj-data-indent t - :obj-data-fmtstr #'ho-class-fmtstr-text - :obj-data-fmtstr-labels #'ho-class-fmtstr-text-labels + :obj-data-fmtstr #'hyperobject-class-fmtstr-text + :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-text-labels :obj-data-end-fmtstr "~%" - :obj-data-value-func #'ho-class-value-func)) + :obj-data-value-func #'hyperobject-class-value-func)) (defun class-name-of (obj) - (string-downcase (kmr-class-name (kmr-class-of obj)))) + (string-downcase (portable-class-name (portable-class-of obj)))) (defun htmlformat-list-start-value-func (x nitems) - (values (ho-class-title x) nitems (class-name-of x))) + (values (hyperobject-class-title x) nitems (class-name-of x))) (defclass htmlformat (textformat) () @@ -432,9 +538,9 @@ Format is ((field-name field-lookup-func other-link-params) ...)") :obj-end-fmtstr "~%" :obj-end-value-func #'identity :obj-data-indent t - :obj-data-fmtstr #'ho-class-fmtstr-html-labels - :obj-data-fmtstr-labels #'ho-class-fmtstr-html-labels - :obj-data-value-func #'ho-class-value-func)) + :obj-data-fmtstr #'hyperobject-class-fmtstr-html-labels + :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-html-labels + :obj-data-value-func #'hyperobject-class-value-func)) (defclass xhtmlformat (textformat) () @@ -453,16 +559,16 @@ Format is ((field-name field-lookup-func other-link-params) ...)") :obj-end-fmtstr "~%" :obj-end-value-func #'identity :obj-data-indent t - :obj-data-fmtstr #'ho-class-fmtstr-html-labels - :obj-data-fmtstr-labels #'ho-class-fmtstr-html-labels - :obj-data-value-func #'ho-class-xmlvalue-func)) + :obj-data-fmtstr #'hyperobject-class-fmtstr-html-labels + :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-html-labels + :obj-data-value-func #'hyperobject-class-xmlvalue-func)) (defun xmlformat-list-end-value-func (x) (format nil "~alist" (class-name-of x))) (defun xmlformat-list-start-value-func (x nitems) - (values (format nil "~alist" (class-name-of x)) (ho-class-title x) nitems)) + (values (format nil "~alist" (class-name-of x)) (hyperobject-class-title x) nitems)) (defclass xmlformat (textformat) () @@ -480,9 +586,9 @@ Format is ((field-name field-lookup-func other-link-params) ...)") :obj-end-value-func #'class-name-of :obj-end-indent nil :obj-data-indent nil - :obj-data-fmtstr #'ho-class-fmtstr-xml - :obj-data-fmtstr-labels #'ho-class-fmtstr-xml-labels - :obj-data-value-func #'ho-class-xmlvalue-func)) + :obj-data-fmtstr #'hyperobject-class-fmtstr-xml + :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-xml-labels + :obj-data-value-func #'hyperobject-class-xmlvalue-func)) (defclass link-ref () ((fmtstr :type function :initarg :fmtstr :accessor fmtstr) @@ -499,24 +605,24 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (defclass html-link-ref (link-ref) () - (:default-initargs :fmtstr #'ho-class-fmtstr-html-ref - :fmtstr-labels #'ho-class-fmtstr-html-ref-labels + (:default-initargs :fmtstr #'hyperobject-class-fmtstr-html-ref + :fmtstr-labels #'hyperobject-class-fmtstr-html-ref-labels :href-head "a href=" :href-end "a" :ampersand "&")) (defclass xhtml-link-ref (link-ref) () - (:default-initargs :fmtstr #'ho-class-fmtstr-html-ref - :fmtstr-labels #'ho-class-fmtstr-html-ref-labels + (:default-initargs :fmtstr #'hyperobject-class-fmtstr-html-ref + :fmtstr-labels #'hyperobject-class-fmtstr-html-ref-labels :href-head "a href=" :href-end "a" :ampersand "&")) (defclass xml-link-ref (link-ref) () - (:default-initargs :fmtstr #'ho-class-fmtstr-xml-ref - :fmtstr-labels #'ho-class-fmtstr-xml-ref-labels + (:default-initargs :fmtstr #'hyperobject-class-fmtstr-xml-ref + :fmtstr-labels #'hyperobject-class-fmtstr-xml-ref-labels :href-head "xmllink xlink:type=\"simple\" xlink:href=" :href-end "xmllink" :ampersand "&") @@ -654,12 +760,16 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (funcall (funcall (obj-data-value-func fmt) x) x)))) ;; make list of reference link fields for printing to refstr template - (dolist (field (ho-class-ref-fields x)) + (dolist (ref (hyperobject-class-references x)) (let ((link-start - (make-link-start x (link-ref fmt) (car field) (cadr field) - (nth (position (car field) (ho-class-fields x) :key #'car) field-values) - (append (caddr field) refvars))) - (link-end (make-link-end x (link-ref fmt) (car field)))) + (make-link-start x (link-ref fmt) (name ref) (lookup ref) + (nth (position (name ref) + (hyperobject-class-fields x) + :key #'(lambda (x) + (portable-slot-name x))) + field-values) + (append (link-parameters ref) refvars))) + (link-end (make-link-end x (link-ref fmt) (name ref)))) (push link-start refvalues) (push link-end refvalues))) (setq refvalues (nreverse refvalues)) @@ -697,21 +807,21 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (when objs (let ((objlist (mklist objs))) (dolist (obj objlist) - (awhen (ho-class-subobjects-lists obj) ;; access list of functions + (awhen (hyperobject-class-subobjects obj) ;; access list of functions (dolist (child-obj it) ;; for each child function - (awhen (funcall (car child-obj) obj) + (awhen (funcall (reader child-obj) obj) (load-all-subobjects it)))))) objs)) -(defgeneric output-ho-class (objs fmt strm +(defgeneric print-hyperobject-class (objs fmt strm &optional label english-only-function indent subobjects refvars)) -(defmethod output-ho-class (objs (fmt dataformat) (strm stream) +(defmethod print-hyperobject-class (objs (fmt dataformat) (strm stream) &optional (label nil) (indent 0) (english-only-function nil) (subobjects nil) (refvars nil)) - "Display a single or list of ho-class instances and their subobjects" +"Display a single or list of hyperobject-class instances and their subobjects" (when objs (setq objs (mklist objs)) (let ((nobjs (length objs))) @@ -723,26 +833,42 @@ Format is ((field-name field-lookup-func other-link-params) ...)") (fmt-obj-start obj fmt strm indent) (fmt-obj-data obj fmt strm (1+ indent) label refvars) (if subobjects - (awhen (ho-class-subobjects-lists obj) ;; access list of functions + (awhen (hyperobject-class-subobjects obj) ;; access list of functions (dolist (child-obj it) ;; for each child function - (awhen (funcall (car child-obj) obj) ;; access set of child objects - (output-ho-class it fmt strm label - english-only-function - (1+ indent) subobjects refvars))))) + (awhen (funcall (reader child-obj) obj) ;; access set of child objects + (print-hyperobject-class it fmt strm label + (1+ indent) english-only-function + subobjects refvars))))) (fmt-obj-end obj fmt strm indent))) (fmt-list-end (car objs) fmt strm indent nobjs)) t)) -(defun print-ho (objs &key (os *standard-output*) (format :text) + +(defun print-hyperobject (objs &key (os *standard-output*) (format :text) (label nil) (english-only-function nil) (subobjects nil) (file-wrapper t) (refvars nil)) - "EXPORTED Function: prints ho-class objects. Simplies call to output-ho-class" + "EXPORTED Function: prints hyperobject-class objects. Simplies call to print-hyperobject-class" (let ((fmt (make-format-instance format))) (if file-wrapper (fmt-file-start fmt os)) (when objs - (output-ho-class objs fmt os label english-only-function 0 subobjects refvars)) + (print-hyperobject-class objs fmt os label 0 english-only-function subobjects refvars)) (if file-wrapper (fmt-file-end fmt os))) objs) + + +(defclass hyperobject () + () + (:metaclass hyperobject-class)) + + +(defmethod print-object ((obj hyperobject) (s stream)) + (print-unreadable-object (obj s :type t :identity t) + (let ((fmt (make-instance 'hyperobject::textformat))) + (apply #'format + s (funcall (hyperobject-mop::obj-data-fmtstr fmt) obj) + (multiple-value-list + (funcall (funcall (hyperobject-mop::obj-data-value-func fmt) obj) obj)))))) +