r4737: Auto commit for Debian build
[umlisp.git] / class-support.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          classes-support.lisp
6 ;;;; Purpose:       Class defintions for UMLisp
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2000
9 ;;;;
10 ;;;; $Id: class-support.lisp,v 1.2 2003/05/02 05:37:16 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UMLisp, is
13 ;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
14 ;;;;
15 ;;;; UMLisp users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License.
17 ;;;; *************************************************************************
18
19 (in-package :umlisp)
20 (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3)))
21
22
23 ;;; Formatting routines
24
25 (defgeneric fmt-cui (c))
26 (defmethod fmt-cui ((c ucon))
27   (format nil "C~7,'0d" (cui c)))
28
29 (defmethod fmt-cui ((c fixnum))
30   (format nil "C~7,'0d" c))
31
32 (defmethod fmt-cui ((c string))
33   (if (eql (aref c 0) #\C)
34       c
35     (format nil "C~7,'0d" (parse-integer c))))
36
37 (defmethod fmt-cui ((c null))
38   (format nil "nil"))
39
40 (defgeneric fmt-lui (c))
41 (defmethod fmt-lui ((l uterm))
42   (format nil "L~7,'0d" (lui l)))
43
44 (defmethod fmt-lui ((l fixnum))
45   (format nil "L~7,'0d" l))
46
47 (defmethod fmt-lui ((l string))
48   (if (eql (aref l 0) #\L)
49       l
50   (format nil "L~7,'0d" (parse-integer l))))
51
52 (defgeneric fmt-sui (s))
53 (defmethod fmt-sui ((s ustr))
54   (format nil "S~7,'0d" (sui s)))
55
56 (defmethod fmt-sui ((s fixnum))
57   (format nil "S~7,'0d" s))
58
59 (defmethod fmt-sui ((s string))
60   (if (eql (aref s 0) #\S)
61       s
62   (format nil "S~7,'0d" (parse-integer s))))
63
64 (defgeneric fmt-tui (t))
65 (defmethod fmt-tui ((s fixnum))
66   (format nil "T~3,'0d" s))
67
68 (defmethod fmt-tui ((s string))
69   (if (eql (aref s 0) #\T)
70       s
71   (format nil "T~3,'0d" (parse-integer s))))
72
73 (defgeneric fmt-eui (e))
74 (defmethod fmt-eui ((e fixnum))
75   (format nil "E~7,'0d" e))
76
77 (defmethod fmt-eui ((e string))
78   (if (eql (aref e 0) #\E)
79       e
80     (format nil "E~7,'0d" (parse-integer e))))
81
82 (defmethod fmt-eui ((e null))
83   (format nil "nil"))
84
85 ;;; Generic display functions
86
87 (eval-when (:compile-toplevel :load-toplevel :execute)
88 (defun english-term-p (obj)
89   "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM"
90   (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm)
91       (values (string-equal (lat obj) "ENG") t)
92     (values nil nil))))
93
94 (defun english-term-filter (obj)
95   "Retrns NIL if object is a term and not english"
96   (multiple-value-bind (is-english is-term) (english-term-p obj)
97       (or (not is-term) is-english)))
98
99 (defun print-umlsclass (obj &key (stream *standard-output*) (category :compact-text)
100                         (file-wrapper t) (english-only nil) (subobjects nil)
101                         (refvars nil))
102   (view obj :stream stream :category category :subobjects subobjects
103         :file-wrapper file-wrapper
104         :filter (if english-only nil #'english-term-filter)
105         :refvars refvars))
106
107 (defmacro define-lookup-display (newfuncname lookup-func)
108   "Defines functions for looking up and displaying objects"
109   `(defun ,newfuncname  (keyval &key (stream *standard-output*) (category :compact-text)
110                          (file-wrapper t) (english-only nil) (subobjects nil))
111      (let ((obj (funcall ,lookup-func keyval)))
112        (print-umlsclass obj :stream stream :category category
113                         :file-wrapper file-wrapper :english-only english-only
114                         :subobjects subobjects)
115        obj)))
116
117 (define-lookup-display display-con #'find-ucon-cui)
118 (define-lookup-display display-term #'find-uterm-lui)
119 (define-lookup-display display-str #'find-ustr-sui)
120
121 (defun ucon-has-tui (ucon tui)
122   "Returns T if UCON has a semantic type of TUI."
123   (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
124
125 #+(or scl cmu)
126 (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))
127     #+cmu
128     (let ((cl (pcl:find-class c)))
129       (pcl:finalize-inheritance cl))
130     #+scl
131     (let ((cl (find-class c)))
132       (clos:finalize-inheritance cl)))