r4827: 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.3 2003/05/06 02:15:41 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
21
22 ;;; Formatting routines
23
24 (defgeneric fmt-cui (c))
25 (defmethod fmt-cui ((c ucon))
26   (format nil "C~7,'0d" (cui c)))
27
28 (defmethod fmt-cui ((c fixnum))
29   (format nil "C~7,'0d" c))
30
31 (defmethod fmt-cui ((c string))
32   (if (eql (aref c 0) #\C)
33       c
34     (format nil "C~7,'0d" (parse-integer c))))
35
36 (defmethod fmt-cui ((c null))
37   (format nil "nil"))
38
39 (defgeneric fmt-lui (c))
40 (defmethod fmt-lui ((l uterm))
41   (format nil "L~7,'0d" (lui l)))
42
43 (defmethod fmt-lui ((l fixnum))
44   (format nil "L~7,'0d" l))
45
46 (defmethod fmt-lui ((l string))
47   (if (eql (aref l 0) #\L)
48       l
49   (format nil "L~7,'0d" (parse-integer l))))
50
51 (defgeneric fmt-sui (s))
52 (defmethod fmt-sui ((s ustr))
53   (format nil "S~7,'0d" (sui s)))
54
55 (defmethod fmt-sui ((s fixnum))
56   (format nil "S~7,'0d" s))
57
58 (defmethod fmt-sui ((s string))
59   (if (eql (aref s 0) #\S)
60       s
61   (format nil "S~7,'0d" (parse-integer s))))
62
63 (defgeneric fmt-tui (t))
64 (defmethod fmt-tui ((s fixnum))
65   (format nil "T~3,'0d" s))
66
67 (defmethod fmt-tui ((s string))
68   (if (eql (aref s 0) #\T)
69       s
70   (format nil "T~3,'0d" (parse-integer s))))
71
72 (defgeneric fmt-eui (e))
73 (defmethod fmt-eui ((e fixnum))
74   (format nil "E~7,'0d" e))
75
76 (defmethod fmt-eui ((e string))
77   (if (eql (aref e 0) #\E)
78       e
79     (format nil "E~7,'0d" (parse-integer e))))
80
81 (defmethod fmt-eui ((e null))
82   (format nil "nil"))
83
84 ;;; Generic display functions
85
86 (eval-when (:compile-toplevel :load-toplevel :execute)
87 (defun english-term-p (obj)
88   "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM"
89   (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm)
90       (values (string-equal (lat obj) "ENG") t)
91     (values nil nil))))
92
93 (defun english-term-filter (obj)
94   "Retrns NIL if object is a term and not english"
95   (multiple-value-bind (is-english is-term) (english-term-p obj)
96       (or (not is-term) is-english)))
97
98 (defun print-umlsclass (obj &key (stream *standard-output*) (category :compact-text)
99                         (file-wrapper t) (english-only nil) (subobjects nil)
100                         (refvars nil))
101   (view obj :stream stream :category category :subobjects subobjects
102         :file-wrapper file-wrapper
103         :filter (if english-only nil #'english-term-filter)
104         :refvars refvars))
105
106 (defmacro define-lookup-display (newfuncname lookup-func)
107   "Defines functions for looking up and displaying objects"
108   `(defun ,newfuncname  (keyval &key (stream *standard-output*) (category :compact-text)
109                          (file-wrapper t) (english-only nil) (subobjects nil))
110      (let ((obj (funcall ,lookup-func keyval)))
111        (print-umlsclass obj :stream stream :category category
112                         :file-wrapper file-wrapper :english-only english-only
113                         :subobjects subobjects)
114        obj)))
115
116 (define-lookup-display display-con #'find-ucon-cui)
117 (define-lookup-display display-term #'find-uterm-lui)
118 (define-lookup-display display-str #'find-ustr-sui)
119
120 (defun ucon-has-tui (ucon tui)
121   "Returns T if UCON has a semantic type of TUI."
122   (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
123
124 #+(or scl cmu)
125 (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))
126     #+cmu
127     (let ((cl (pcl:find-class c)))
128       (pcl:finalize-inheritance cl))
129     #+scl
130     (let ((cl (find-class c)))
131       (clos:finalize-inheritance cl)))