;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*- ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; ;;;; Name: classes-support.lisp ;;;; Purpose: Support for UMLisp classes ;;;; Author: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; ;;;; $Id: class-support.lisp,v 1.6 2003/05/14 21:33:02 kevin Exp $ ;;;; ;;;; This file, part of UMLisp, is ;;;; Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D. ;;;; ;;;; UMLisp users are granted the rights to distribute and use this software ;;;; as governed by the terms of the GNU General Public License. ;;;; ************************************************************************* (in-package #:umlisp) ;;; Formatting routines (defgeneric fmt-cui (c)) (defmethod fmt-cui ((c ucon)) (fmt-cui (cui c))) (defmethod fmt-cui ((c fixnum)) (prefixed-fixnum-string c #\C 8)) (defmethod fmt-cui ((c string)) (if (eql (aref c 0) #\C) c (fmt-cui (parse-integer c)))) (defmethod fmt-cui ((c null)) (format nil "nil")) (defgeneric fmt-lui (c)) (defmethod fmt-lui ((l uterm)) (fmt-lui (lui l))) (defmethod fmt-lui ((l fixnum)) (prefixed-fixnum-string l #\L 8)) (defmethod fmt-lui ((l string)) (if (eql (aref l 0) #\L) l (fmt-lui (parse-integer l)))) (defgeneric fmt-sui (s)) (defmethod fmt-sui ((s ustr)) (fmt-sui (sui s))) (defmethod fmt-sui ((s fixnum)) (prefixed-fixnum-string s #\S 8)) (defmethod fmt-sui ((s string)) (if (eql (aref s 0) #\S) s (fmt-sui (parse-integer s)))) (defgeneric fmt-tui (t)) (defmethod fmt-tui ((t fixnum)) (prefixed-fixnum-string t #\T 4)) (defmethod fmt-tui ((s string)) (if (eql (aref s 0) #\T) s (fmt-tui (parse-integer s)))) (defgeneric fmt-eui (e)) (defmethod fmt-eui ((e fixnum)) (prefixed-fixnum-string e #\E 8)) (defmethod fmt-eui ((e string)) (if (eql (aref e 0) #\E) e (fmt-eui (parse-integer e)))) (defmethod fmt-eui ((e null)) (format nil "nil")) ;;; Generic display functions (eval-when (:compile-toplevel :load-toplevel :execute) (defun english-term-p (obj) "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM" (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm) (values (string-equal (lat obj) "ENG") t) (values nil nil)))) (defun english-term-filter (obj) "Retrns NIL if object is a term and not english" (multiple-value-bind (is-english is-term) (english-term-p obj) (or (not is-term) is-english))) (defun print-umlsclass (obj &key (stream *standard-output*) (category :compact-text) (file-wrapper t) (english-only nil) (subobjects nil) (refvars nil)) (view obj :stream stream :category category :subobjects subobjects :file-wrapper file-wrapper :filter (if english-only nil #'english-term-filter) :refvars refvars)) (defmacro define-lookup-display (newfuncname lookup-func) "Defines functions for looking up and displaying objects" `(defun ,newfuncname (keyval &key (stream *standard-output*) (category :compact-text) (file-wrapper t) (english-only nil) (subobjects nil)) (let ((obj (funcall ,lookup-func keyval))) (print-umlsclass obj :stream stream :category category :file-wrapper file-wrapper :english-only english-only :subobjects subobjects) obj))) (define-lookup-display display-con #'find-ucon-cui) (define-lookup-display display-term #'find-uterm-lui) (define-lookup-display display-str #'find-ustr-sui) (defun ucon-has-tui (ucon tui) "Returns T if UCON has a semantic type of TUI." (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon))) (defgeneric suistr (lo)) (defmethod suistr ((lo ulo)) "Return the string for a ulo object" (find-string-sui (sui lo))) #+(or scl cmu) (dolist (c '(urank udef usat uso ucxt ustr ulo uterm usty urel ucoc uatx ucon uxw uxnw uxns lexterm labr lagr lcmp lmod lnom lprn lprp lspl ltrm ltyp lwd sdef sstr sstre1 sstre2 usrl)) #+cmu (let ((cl (pcl:find-class c))) (pcl:finalize-inheritance cl)) #+scl (let ((cl (find-class c))) (clos:finalize-inheritance cl)))