1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: ml-class.lisp
6 ;;;; Purpose: Markup Language Metaclass
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; This metaclass as functions to classes to allow display
11 ;;;; in Text, HTML, and XML formats. This includes hyperlinking
12 ;;;; capability and sub-objects.
14 ;;;; $Id: ml-class.lisp,v 1.10 2002/10/14 15:25:11 kevin Exp $
16 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
18 ;;;; KMRCL users are granted the rights to distribute and use this software
19 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
20 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
21 ;;;; *************************************************************************
25 (declaim (optimize (speed 3) (safety 1)))
27 (defun ml-class-of (obj)
28 #-(or cmu sbcl) (class-of obj)
29 #+sbcl (sb-pcl:class-of obj)
30 #+cmu (pcl:class-of obj))
32 (defclass ml-class (#-(or cmu sbcl) standard-class
33 #+cmu pcl::standard-class
34 #+sbcl sb-pcl::standard-class)
35 ((title :initarg :title :type string :reader ml-std-title
37 "Print Title for class")
38 (fields :initarg :fields :reader ml-std-fields
40 "List of field lists for printing. Format is
41 ((fieldname type optional-formatter) ... )")
43 :initarg :subobjects-lists :reader ml-std-subobjects-lists
45 "List of fields that contain a list of subobjects objects.")
47 :initarg :ref-fields :type list :reader ml-std-ref-field
49 "List of fields that can be referred to by browsers.
50 Format is ((field-name field-lookup-func other-link-params) ...)")
52 ;;; The remainder of these fields are calculated one time
53 ;;; in finalize-inheritence.
54 (value-func :initform nil :type function :reader ml-std-value-func)
55 (xmlvalue-func :initform nil :type function :reader ml-std-xmlvalue-func)
56 (fmtstr-text :initform nil :type string :reader ml-std-fmtstr-text)
57 (fmtstr-html :initform nil :type string :reader ml-std-fmtstr-html)
58 (fmtstr-xml :initform nil :type string :reader ml-std-fmtstr-xml)
59 (fmtstr-text-labels :initform nil :type string :reader ml-std-fmtstr-text-labels)
60 (fmtstr-html-labels :initform nil :type string :reader ml-std-fmtstr-html-labels)
61 (fmtstr-xml-labels :initform nil :type string :reader ml-std-fmtstr-xml-labels)
62 (fmtstr-html-ref :initform nil :type string :reader ml-std-fmtstr-html-ref)
63 (fmtstr-xml-ref :initform nil :type string :reader ml-std-fmtstr-xml-ref)
64 (fmtstr-html-ref-labels :initform nil :type string :reader ml-std-fmtstr-html-ref-labels)
65 (fmtstr-xml-ref-labels :initform nil :type string :reader ml-std-fmtstr-xml-ref-labels)
67 (:default-initargs :title nil :fields nil :subobjects-lists nil :ref-fields nil)
68 (:documentation "Metaclass for Markup Language classes."))
71 (defmethod pcl:finalize-inheritance :after ((cl ml-class))
76 (defmethod sb-pcl:finalize-inheritance :after ((cl ml-class))
81 (defmethod pcl:validate-superclass ((class ml-class) (superclass pcl::standard-class))
85 (defmethod sb-pcl:validate-superclass ((class ml-class) (superclass sb-pcl::standard-class))
89 (defmethod mop:finalize-inheritance :after ((cl ml-class))
93 (defmethod clos:finalize-inheritance :after ((cl ml-class))
97 ;;(defmethod pcl::class-finalized-p ((cl ml-class))
98 ;; (and (not (null (slot-value cl 'pcl::wrapper)))
99 ;; (not (null (slot-value cl 'fmtstr-text)))))
102 ;;(defmethod sb-pcl::class-finalized-p ((cl ml-class))
103 ;; (and (not (null (slot-value cl 'sb-pcl::wrapper)))
104 ;; (not (null (slot-value cl 'fmtstr-text)))))
107 (defmethod clos:process-a-class-option ((class ml-class)
111 (error "ml-class title must have a value"))
112 (if (null (cdr value))
113 (list name (car value))
114 (list name `',value)))
117 (defmethod clos:process-a-class-option ((class ml-class)
121 (error "ml-class fields must have a value"))
122 (list name `',value))
125 (defmethod clos:process-a-class-option ((class ml-class)
126 (name (eql :ref-fields))
129 (error "ml-class ref-fields must have a value"))
130 (list name `',value))
133 (defmethod clos:process-a-class-option ((class ml-class)
134 (name (eql :subobjects-lists))
137 (error "ml-class subobjects-lists must have a value"))
138 (list name `',value))
140 ;;;; Class initialization function
142 (defun init-ml-class (cl)
143 (let ((fmtstr-text "")
146 (fmtstr-text-labels "")
147 (fmtstr-html-labels "")
148 (fmtstr-xml-labels "")
151 (fmtstr-html-ref-labels "")
152 (fmtstr-xml-ref-labels "")
156 (classname (class-name cl))
157 (ref-fields (slot-value cl 'ref-fields)))
158 (declare (ignore classname))
159 (dolist (f (slot-value cl 'fields))
161 (namestr (symbol-name (car f)))
162 (namestr-lower (string-downcase (symbol-name (car f))))
164 (formatter (caddr f))
166 (plain-value-func nil)
167 html-str xml-str html-label-str xml-label-str)
169 (when (or (eql type :integer) (eql type :fixnum))
170 (setq value-fmt "~d"))
172 (when (eql type :commainteger)
173 (setq value-fmt "~:d"))
175 (when (eql type :boolean)
176 (setq value-fmt "~a"))
179 (setq first-field nil)
181 (string-append fmtstr-text " ")
182 (string-append fmtstr-html " ")
183 (string-append fmtstr-xml " ")
184 (string-append fmtstr-text-labels " ")
185 (string-append fmtstr-html-labels " ")
186 (string-append fmtstr-xml-labels " ")
187 (string-append fmtstr-html-ref " ")
188 (string-append fmtstr-xml-ref " ")
189 (string-append fmtstr-html-ref-labels " ")
190 (string-append fmtstr-xml-ref-labels " ")))
192 (setq html-str value-fmt)
193 (setq xml-str (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">"))
194 (setq html-label-str (concatenate 'string "<i>" namestr-lower "</i> " value-fmt))
195 (setq xml-label-str (concatenate 'string "<label>" namestr-lower "</label> <" namestr-lower ">" value-fmt "</" namestr-lower ">"))
197 (string-append fmtstr-text value-fmt)
198 (string-append fmtstr-html html-str)
199 (string-append fmtstr-xml xml-str)
200 (string-append fmtstr-text-labels namestr-lower " " value-fmt)
201 (string-append fmtstr-html-labels html-label-str)
202 (string-append fmtstr-xml-labels xml-label-str)
204 (if (find name ref-fields :key #'car)
206 (string-append fmtstr-html-ref "<~~a>" value-fmt "</~~a>")
207 (string-append fmtstr-xml-ref "<~~a>" value-fmt "</~~a>")
208 (string-append fmtstr-html-ref-labels "<i>" namestr-lower "</i> <~~a>" value-fmt "</~~a>")
209 (string-append fmtstr-xml-ref-labels "<label>" namestr-lower "</label> <~~a>" value-fmt "</~~a>"))
211 (string-append fmtstr-html-ref html-str)
212 (string-append fmtstr-xml-ref xml-str)
213 (string-append fmtstr-html-ref-labels html-label-str)
214 (string-append fmtstr-xml-ref-labels xml-label-str)))
217 (setq plain-value-func
218 (list `(,formatter (,(concat-symbol-pkg
219 :umlisp namestr) x))))
220 (setq plain-value-func
221 (list `(,(concat-symbol-pkg
222 :umlisp namestr) x))))
223 (setq value-func (append value-func plain-value-func))
225 (if (eql type :cdata)
226 (setq xmlvalue-func (append xmlvalue-func (list `(xml-cdata ,@plain-value-func))))
227 (setq xmlvalue-func (append xmlvalue-func plain-value-func)))
231 (setq value-func `(lambda (x) (values ,@value-func)))
232 (setq value-func `(lambda () (values))))
233 (setq value-func (compile nil (eval value-func)))
236 (setq xmlvalue-func `(lambda (x) (values ,@xmlvalue-func)))
237 (setq xmlvalue-func `(lambda () (values))))
238 (setq xmlvalue-func (compile nil (eval xmlvalue-func)))
240 (setf (slot-value cl 'fmtstr-text) fmtstr-text)
241 (setf (slot-value cl 'fmtstr-html) fmtstr-html)
242 (setf (slot-value cl 'fmtstr-xml) fmtstr-xml)
243 (setf (slot-value cl 'fmtstr-text-labels) fmtstr-text-labels)
244 (setf (slot-value cl 'fmtstr-html-labels) fmtstr-html-labels)
245 (setf (slot-value cl 'fmtstr-xml-labels) fmtstr-xml-labels)
246 (setf (slot-value cl 'fmtstr-html-ref) fmtstr-html-ref)
247 (setf (slot-value cl 'fmtstr-xml-ref) fmtstr-xml-ref)
248 (setf (slot-value cl 'fmtstr-html-ref-labels) fmtstr-html-ref-labels)
249 (setf (slot-value cl 'fmtstr-xml-ref-labels) fmtstr-xml-ref-labels)
250 (setf (slot-value cl 'value-func) value-func)
251 (setf (slot-value cl 'xmlvalue-func) xmlvalue-func))
255 (defun ml-class-fmtstr-text (obj)
256 (slot-value (ml-class-of obj) 'fmtstr-text))
258 (defun ml-class-fmtstr-html (obj)
259 (slot-value (ml-class-of obj) 'fmtstr-html))
261 (defun ml-class-fmtstr-xml (obj)
262 (slot-value (ml-class-of obj) 'fmtstr-xml))
264 (defun ml-class-fmtstr-text-labels (obj)
265 (slot-value (ml-class-of obj) 'fmtstr-text-labels))
267 (defun ml-class-fmtstr-html-labels (obj)
268 (slot-value (ml-class-of obj) 'fmtstr-html-labels))
270 (defun ml-class-fmtstr-xml-labels (obj)
271 (slot-value (ml-class-of obj) 'fmtstr-xml-labels))
273 (defun ml-class-value-func (obj)
274 (slot-value (ml-class-of obj) 'value-func))
276 (defun ml-class-xmlvalue-func (obj)
277 (slot-value (ml-class-of obj) 'xmlvalue-func))
279 (eval-when (:compile-toplevel :load-toplevel :execute)
280 (defun ml-class-title (obj)
281 (awhen (slot-value (ml-class-of obj) 'title)
286 (defun ml-class-subobjects-lists (obj)
287 (slot-value (ml-class-of obj) 'subobjects-lists))
289 (defun ml-class-ref-fields (obj)
290 (slot-value (ml-class-of obj) 'ref-fields))
292 (defun ml-class-fields (obj)
293 (slot-value (ml-class-of obj) 'fields))
295 (defun ml-class-fmtstr-html-ref (obj)
296 (slot-value (ml-class-of obj) 'fmtstr-html-ref))
298 (defun ml-class-fmtstr-xml-ref (obj)
299 (slot-value (ml-class-of obj) 'fmtstr-xml-ref))
301 (defun ml-class-fmtstr-html-ref-labels (obj)
302 (slot-value (ml-class-of obj) 'fmtstr-html-ref-labels))
304 (defun ml-class-fmtstr-xml-ref-labels (obj)
305 (slot-value (ml-class-of obj) 'fmtstr-xml-ref-labels))
307 ;;; Class name functions
309 (defgeneric ml-class-stdname (x))
310 (defmethod ml-class-stdname ((name string))
311 (string-downcase (subseq name 1)))
313 (defmethod ml-class-stdname ((cl standard-object))
314 (string-downcase (subseq (class-name (ml-class-of cl)) 1)))
316 ;;;; Generic Print functions
318 (defparameter *default-textformat* nil)
319 (defparameter *default-htmlformat* nil)
320 (defparameter *default-htmlrefformat* nil)
321 (defparameter *default-xmlformat* nil)
322 (defparameter *default-xmlrefformat* nil)
323 (defparameter *default-nullformat* nil)
324 (defparameter *default-init-format?* nil)
326 (defun make-format-instance (fmt)
327 (unless *default-init-format?*
328 (setq *default-textformat* (make-instance 'textformat))
329 (setq *default-htmlformat* (make-instance 'htmlformat))
330 (setq *default-htmlrefformat* (make-instance 'htmlrefformat))
331 (setq *default-xmlformat* (make-instance 'xmlformat))
332 (setq *default-xmlrefformat* (make-instance 'xmlrefformat))
333 (setq *default-nullformat* (make-instance 'nullformat))
334 (setq *default-init-format?* t))
337 (:text *default-textformat*)
338 (:html *default-htmlformat*)
339 (:htmlref *default-htmlrefformat*)
340 (:xml *default-xmlformat*)
341 (:xmlref *default-xmlrefformat*)
342 (:null *default-nullformat*)
343 (otherwise *default-textformat*)))
345 ;;;; Output format classes for print ml-classes
347 (defclass dataformat ()
348 ((file-start-str :type string :initarg :file-start-str :reader file-start-str)
349 (file-end-str :type string :initarg :file-end-str :reader file-end-str)
350 (list-start-fmtstr :type string :initarg :list-start-fmtstr :reader list-start-fmtstr)
351 (list-start-value-func :type function :initarg :list-start-value-func :reader list-start-value-func)
352 (list-start-indent :initarg :list-start-indent :reader list-start-indent)
353 (list-end-fmtstr :type string :initarg :list-end-fmtstr :reader list-end-fmtstr)
354 (list-end-value-func :type function :initarg :list-end-value-func :reader list-end-value-func)
355 (list-end-indent :initarg :list-end-indent :reader list-end-indent)
356 (obj-start-fmtstr :type string :initarg :obj-start-fmtstr :reader obj-start-fmtstr)
357 (obj-start-value-func :initarg :obj-start-value-func :reader obj-start-value-func)
358 (obj-start-indent :initarg :obj-start-indent :reader obj-start-indent)
359 (obj-end-fmtstr :type string :initarg :obj-end-fmtstr :reader obj-end-fmtstr)
360 (obj-end-value-func :initarg :obj-end-value-func :reader obj-end-value-func)
361 (obj-end-indent :initarg :obj-end-indent :reader obj-end-indent)
362 (obj-data-indent :initarg :obj-data-indent :reader obj-data-indent)
363 (obj-data-fmtstr :initarg :obj-data-fmtstr :reader obj-data-fmtstr)
364 (obj-data-fmtstr-labels :initarg :obj-data-fmtstr-labels :reader obj-data-fmtstr-labels)
365 (obj-data-end-fmtstr :initarg :obj-data-end-fmtstr :reader obj-data-end-fmtstr)
366 (obj-data-value-func :initarg :obj-data-value-func :reader obj-data-value-func)
367 (link-ref :initarg :link-ref :reader link-ref))
368 (:default-initargs :file-start-str nil :file-end-str nil :list-start-fmtstr nil :list-start-value-func nil
369 :list-start-indent nil :list-end-fmtstr nil :list-end-value-func nil :list-end-indent nil
370 :obj-start-fmtstr nil :obj-start-value-func nil :obj-start-indent nil
371 :obj-end-fmtstr nil :obj-end-value-func nil :obj-end-indent nil
372 :obj-data-indent nil :obj-data-fmtstr nil :obj-data-fmtstr-labels nil :obj-data-end-fmtstr nil
373 :obj-data-value-func nil :link-ref nil)
374 (:documentation "Parent for all dataformat objects"))
376 (defclass binaryformat (dataformat)
379 (defclass nullformat (dataformat)
382 (defun text-list-start-value-func (obj nitems)
383 (values (ml-class-title obj) nitems))
385 (defclass textformat (dataformat)
387 (:default-initargs :list-start-fmtstr "~a~P:~%"
388 :list-start-value-func #'text-list-start-value-func
391 :obj-data-fmtstr #'ml-class-fmtstr-text
392 :obj-data-fmtstr-labels #'ml-class-fmtstr-text-labels
393 :obj-data-end-fmtstr "~%"
394 :obj-data-value-func #'ml-class-value-func))
396 (defclass htmlformat (textformat)
398 (:default-initargs :file-start-str "<html><body>~%"
399 :file-end-str "</body><html>~%"
401 :list-start-fmtstr "<p><b>~a~P:</b></p><ul>~%"
402 :list-start-value-func #'text-list-start-value-func
403 :list-end-fmtstr "</ul>~%"
405 :list-end-value-func #'identity
407 :obj-start-fmtstr "<li>"
408 :obj-start-value-func #'identity
410 :obj-end-fmtstr "</li>~%"
411 :obj-end-value-func #'identity
413 :obj-data-fmtstr #'ml-class-fmtstr-html-labels
414 :obj-data-fmtstr-labels #'ml-class-fmtstr-html-labels
415 :obj-data-value-func #'ml-class-value-func))
418 (defun class-name-of (obj)
419 (string-downcase (class-name (ml-class-of obj))))
421 (defun xmlformat-list-end-value-func (x)
422 (format nil "~alist" (string-downcase (class-name (ml-class-of x)))))
424 (defun xmlformat-list-start-value-func (x nitems)
425 (values (format nil "~alist" (string-downcase (class-name (ml-class-of x)))) (ml-class-title x) nitems))
427 (defclass xmlformat (textformat)
429 (:default-initargs :file-start-str "" ; (std-xml-header)
431 :list-start-fmtstr "<~a><title>~a~p:</title> ~%"
432 :list-start-value-func #'xmlformat-list-start-value-func
434 :list-end-fmtstr "</~a>~%"
435 :list-end-value-func #'xmlformat-list-end-value-func
436 :obj-start-fmtstr "<~a>"
437 :obj-start-value-func #'class-name-of
439 :obj-end-fmtstr "</~a>~%"
440 :obj-end-value-func #'class-name-of
443 :obj-data-fmtstr #'ml-class-fmtstr-xml
444 :obj-data-fmtstr-labels #'ml-class-fmtstr-xml-labels
445 :obj-data-value-func #'ml-class-xmlvalue-func))
447 (defclass link-ref ()
448 ((fmtstr :type function :initarg :fmtstr :accessor fmtstr)
449 (fmtstr-labels :type function :initarg :fmtstr-labels :accessor fmtstr-labels)
450 (page-name :type string :initarg :page-name :accessor page-name)
451 (href-head :type string :initarg :href-head :accessor href-head)
452 (href-end :type string :initarg :href-end :accessor href-end)
453 (ampersand :type string :initarg :ampersand :accessor ampersand))
454 (:default-initargs :fmtstr nil
456 :page-name "disp-func1"
457 :href-head nil :href-end nil :ampersand nil)
458 (:documentation "Formatting for a linked reference"))
460 (defclass html-link-ref (link-ref)
462 (:default-initargs :fmtstr #'ml-class-fmtstr-html-ref
463 :fmtstr-labels #'ml-class-fmtstr-html-ref-labels
468 (defclass xml-link-ref (link-ref)
470 (:default-initargs :fmtstr #'ml-class-fmtstr-xml-ref
471 :fmtstr-labels #'ml-class-fmtstr-xml-ref-labels
472 :href-head "xmllink xlink:type=\"simple\" xlink:href="
477 (defclass htmlrefformat (htmlformat)
479 (:default-initargs :link-ref (make-instance 'html-link-ref)))
481 (defclass xmlrefformat (xmlformat)
483 (:default-initargs :link-ref (make-instance 'xml-link-ref)))
486 ;;; File Start and Ends
488 (defgeneric fmt-file-start (fmt s))
489 (defmethod fmt-file-start ((fmt dataformat) (s stream)))
491 (defmethod fmt-file-start ((fmt textformat) (s stream))
492 (aif (file-start-str fmt)
495 (defgeneric fmt-file-end (fmt s))
496 (defmethod fmt-file-end ((fmt textformat) (s stream))
497 (aif (file-end-str fmt)
500 ;;; List Start and Ends
502 (defgeneric fmt-list-start (obj fmt s &optional indent num-items))
503 (defmethod fmt-list-start (x (fmt textformat) (s stream) &optional (indent 0) (num-items 1))
504 (if (list-start-indent fmt)
505 (indent-spaces indent s))
506 (aif (list-start-fmtstr fmt)
509 (funcall (list-start-value-func fmt) x num-items)))))
511 (defgeneric fmt-list-end (obj fmt s &optional indent num-items))
512 (defmethod fmt-list-end (x (fmt textformat) (s stream) &optional (indent 0) (num-items 1))
513 (declare (ignore num-items))
514 (if (list-end-indent fmt)
515 (indent-spaces indent s))
516 (aif (list-end-fmtstr fmt)
519 (funcall (list-end-value-func fmt) x)))))
521 ;;; Object Start and Ends
523 (defgeneric fmt-obj-start (obj fmt s &optional indent))
524 (defmethod fmt-obj-start (x (fmt textformat) (s stream) &optional (indent 0))
525 (if (obj-start-indent fmt)
526 (indent-spaces indent s))
527 (aif (obj-start-fmtstr fmt)
530 (funcall (obj-start-value-func fmt) x)))))
532 (defgeneric fmt-obj-end (obj fmt s &optional indent))
533 (defmethod fmt-obj-end (x (fmt textformat) (s stream) &optional (indent 0))
534 (if (obj-end-indent fmt)
535 (indent-spaces indent s))
536 (aif (obj-end-fmtstr fmt)
539 (funcall (obj-end-value-func fmt) x)))))
543 (defgeneric make-link-start (obj ref fieldname fieldfunc fieldvalue refvars))
544 (defmethod make-link-start (obj (ref link-ref) fieldname fieldfunc fieldvalue refvars)
545 (declare (ignore obj fieldname))
546 (format nil "~a\"~a?func=~a~akey=~a~a\""
547 (href-head ref) (make-url (page-name ref)) fieldfunc
548 (ampersand ref) fieldvalue
551 (dolist (var refvars)
552 (string-append varstr (format nil "~a~a=~a"
553 (ampersand ref) (car var) (cadr var))))
557 (defgeneric make-link-end (obj ref fieldname))
558 (defmethod make-link-end (obj (ref link-ref) fieldname)
559 (declare (ignore obj fieldname))
560 (format nil "~a" (href-end ref))
563 (defgeneric fmt-obj-data (obj fmt s &optional indent label refvars))
564 (defmethod fmt-obj-data (x (fmt textformat) s
565 &optional (indent 0) (label nil) (refvars nil))
566 (if (obj-data-indent fmt)
567 (indent-spaces indent s))
569 (fmt-obj-data-with-ref x fmt s label refvars)
570 (fmt-obj-data-plain x fmt s label))
571 (aif (obj-data-end-fmtstr fmt)
574 (defgeneric fmt-obj-data-plain (obj fmt s label))
575 (defmethod fmt-obj-data-plain (x (fmt textformat) s label)
578 (funcall (obj-data-fmtstr-labels fmt) x)
580 (funcall (funcall (obj-data-value-func fmt) x) x)))
581 (apply #'format s (funcall (obj-data-fmtstr fmt) x)
583 (funcall (funcall (obj-data-value-func fmt) x) x)))))
585 (defgeneric fmt-obj-data-with-ref (obj fmt s label refvars))
586 (defmethod fmt-obj-data-with-ref (x (fmt textformat) s label refvars)
587 (let ((refstr (make-ref-data-str x fmt label))
591 (funcall (funcall (obj-data-value-func fmt) x) x))))
593 ;; make list of reference link fields for printing to refstr template
594 (dolist (field (ml-class-ref-fields x))
596 (make-link-start x (link-ref fmt) (car field) (cadr field)
597 (nth (position (car field) (ml-class-fields x) :key #'car) field-values)
598 (append (caddr field) refvars)))
599 (link-end (make-link-end x (link-ref fmt) (car field))))
600 (push link-start refvalues)
601 (push link-end refvalues)))
602 (setq refvalues (nreverse refvalues))
604 (apply #'format s refstr refvalues)))
606 (defgeneric obj-data (obj))
607 (defmethod obj-data (x)
608 "Returns the objects data as a string. Used by common-graphics outline function"
609 (let ((fmt (make-format-instance :text)))
610 (apply #'format nil (funcall (obj-data-fmtstr fmt) x)
612 (funcall (funcall (obj-data-value-func fmt) x) x)))))
614 (defgeneric make-ref-data-str (obj fmt &optional label))
615 (defmethod make-ref-data-str (x (fmt textformat) &optional (label nil))
616 "Return fmt string for that contains ~a slots for reference link start and end"
617 (unless (link-ref fmt)
618 (error "fmt does not contain a link-ref"))
621 (apply #'format nil (funcall (fmtstr-labels (link-ref fmt)) x)
623 (funcall (funcall (obj-data-value-func fmt) x) x)))
624 (apply #'format nil (funcall (fmtstr (link-ref fmt)) x)
625 (multiple-value-list (funcall (funcall (obj-data-value-func fmt) x) x))))))
628 ;;; Display method for objects
631 (defgeneric load-all-subobjects (objs))
632 (defmethod load-all-subobjects (objs)
633 "Load all subobjects if they have not already been loaded."
635 (let ((objlist (mklist objs)))
636 (dolist (obj objlist)
637 (awhen (ml-class-subobjects-lists obj) ;; access list of functions
638 (dolist (child-obj it) ;; for each child function
639 (awhen (funcall (car child-obj) obj)
640 (load-all-subobjects it))))))
643 (defgeneric output-ml-class (objs fmt strm &optional label english-only-function indent subobjects refvars))
644 (defmethod output-ml-class (objs (fmt dataformat) (strm stream)
645 &optional (label nil) (english-only-function nil)
646 (indent 0) (subobjects nil) (refvars nil))
647 "Display a single or list of ml-class instances and their subobjects"
649 (setq objs (mklist objs))
650 (let ((nobjs (length objs)))
651 (fmt-list-start (car objs) fmt strm indent nobjs)
653 (unless (and english-only-function (not (funcall english-only-function obj)))
654 (fmt-obj-start obj fmt strm indent)
655 (fmt-obj-data obj fmt strm (1+ indent) label refvars)
657 (awhen (ml-class-subobjects-lists obj) ;; access list of functions
658 (dolist (child-obj it) ;; for each child function
659 (awhen (funcall (car child-obj) obj) ;; access set of child objects
660 (output-ml-class it fmt strm label
661 english-only-function
662 (1+ indent) subobjects refvars)))))
663 (fmt-obj-end obj fmt strm indent)))
664 (fmt-list-end (car objs) fmt strm indent nobjs))
667 (defun display-ml-class (objs &key (os *standard-output*) (format :text)
668 (label nil) (english-only-function nil) (subobjects nil)
669 (file-wrapper t) (refvars nil))
670 "EXPORTED Function: displays a ml-class. Simplies call to output-ml-class"
671 (let ((fmt (make-format-instance format)))
673 (fmt-file-start fmt os))
675 (output-ml-class objs fmt os label english-only-function 0 subobjects refvars))
677 (fmt-file-end fmt os)))