-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessing.tex
154 lines (115 loc) · 4.21 KB
/
preprocessing.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% ========================================================================
% PlantUML : a free UML diagram generator
% ========================================================================
%
% (C) Copyright 2009, Arnaud Roques
%
% Project Info: http://plantuml.sourceforge.net
%
% This file is part of PlantUML.
%
% PlantUML is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% PlantUML distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
%
% You should have received a copy of the GNU General Public
% License along with this library; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
% USA.
%
% [Java is a trademark or registered trademark of Sun Microsystems, Inc.
% in the United States and other countries.]
%
% Original Author: Arnaud Roques
%
\section{Preprocessing}
Some minor preprocessing capabilities are included in PlantUML, and available for all diagrams.
Thoses functionnalities are very similar to the \textbf{C} language
preprocessor, except that the special character "\texttt{\#}" has been changed
to the exclamation mark "\texttt{!}".
% ========================================================================
\subsection{Including files}
Use the \texttt{!include} directive to include file in your diagram.
Imagine you have the very same class that appears in many diagrams. Instead of duplicating the
description of this class, you can define a file that contains the description.
\begin{lstlisting}
@startuml
!include List.iuml
List <|.. ArrayList
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{preprocessing.png}
\end{center}
File List.iuml:
\begin{lstlisting}
interface List
List : int size()
List : void clear()
\end{lstlisting}
The file \texttt{List.iuml} can be included in many diagrams, and any
modification in this file will change all diagrams that include it.
% ========================================================================
\newpage \subsection{Constant definition}
You can define constant using the \texttt{!define} directive. As in \textbf{C}
language, a constant name can only use alphanumeric and underscore characters, and cannot start with a digit.
\begin{lstlisting}
@startuml
!define SEQUENCE (S,#AAAAAA) Database Sequence
!define TABLE (T,#FFAAAA) Database Table
class USER << TABLE >>
class ACCOUNT << TABLE >>
class UID << SEQUENCE >>
USER "1" -- "*" ACCOUNT
USER -> UID
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=80mm]{preprocessing_001.png}
\end{center}
Of course, you can use the \texttt{!include} directive to define all your
constants in a single file that you include in your diagram.
Constant can be undefined with the \texttt{!undef} XXX directive.
% ========================================================================
\newpage \subsection{Conditions}
You can use \texttt{!ifdef XXX} and \texttt{!endif} directives to have
conditionnal drawings.
The lines between those two directives will be included only if the constant
after the \texttt{!ifdef} directive has been defined before.
You can also provide a \texttt{!else} part which will be included if the
constant has not been defined.
\begin{lstlisting}
@startuml
!include ArrayList.iuml
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{preprocessing_002.png}
\end{center}
File ArrayList.iuml:
\begin{lstlisting}
class ArrayList
!ifdef SHOW_METHODS
ArrayList : int size()
ArrayList : void clear()
!endif
\end{lstlisting}
You can then use the \texttt{!define} directive to activate the conditionnal
part of the diagram.
\begin{lstlisting}
@startuml
!define SHOW_METHODS
!include ArrayList.iuml
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{preprocessing_003.png}
\end{center}
You can also use the \texttt{!ifndef} directive that includes lines if the
provided constant has \textit{NOT} been defined.