Skip to content

Commit

Permalink
Clean up table and listings in 'Merging of Modifications'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Sep 22, 2020
1 parent cd4a78a commit 04dc5f8
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions chapters/inheritance.tex
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,14 @@ \subsection{Merging of Modifications}\label{merging-of-modifications}

class C2
class C21
...
$\ldots$
end C21;
end C2;

class C3
extends C1;
C11 t(x=3);
// ok, C11 has been inherited from C1
C21 u;
// ok, even though C21 is inherited below
C11 t(x = 3); // ok, C11 has been inherited from C1
C21 u; // ok, even though C21 is inherited below
extends C2;
end C3;
\end{lstlisting}
Expand All @@ -388,17 +386,16 @@ \subsection{Merging of Modifications}\label{merging-of-modifications}
end A;

model B
parameter A a=A(2, 3);
parameter A a = A(2, 3);
end B;

model C
B b1(a(x=4));
// Error since attempting to override value for a.x when a has a value.
B b1(a(x = 4)); // Error since attempting to override value for a.x when a has a value.
end C;
\end{lstlisting}

The modification environment of the declaration of \lstinline!t! is
(\lstinline!x=3!). The modification environment is built by merging class modifications, as shown by:
(\lstinline!x = 3!). The modification environment is built by merging class modifications, as shown by:
\begin{lstlisting}[language=modelica]
class C1
parameter Real a;
Expand All @@ -410,46 +407,44 @@ \subsection{Merging of Modifications}\label{merging-of-modifications}
end C2;

class C3
parameter Real x1;
// No default value
parameter Real x2=2;
// Default value 2
parameter C1 x3;
// No default value for x3.a
parameter C2 x4(b=4);
// x4.b has default value 4
parameter C1 x5(a=5);
// x5.a has default value 5
extends C1;
// No default value for inherited element a
extends C2(b=6, c=77);
// Inherited b has default value 6
parameter Real x1; // No default value
parameter Real x2 = 2; // Default value 2
parameter C1 x3; // No default value for x3.a
parameter C2 x4(b = 4); // x4.b has default value 4
parameter C1 x5(a = 5); // x5.a has default value 5
extends C1; // No default value for inherited element a
extends C2(b = 6, c = 77); // Inherited b has default value 6
end C3;

class C4
extends C3(x2=22, x3(a=33), x4(c=44), x5=x3, a=55, b=66);
extends C3(x2 = 22, x3(a = 33), x4(c = 44), x5 = x3, a = 55, b = 66);
end C4;
\end{lstlisting}

Outer modifications override inner modifications, e.g., \lstinline!b=66!
overrides the nested class modification of extends \lstinline!C2(b=6)!.
This is known as merging of modifications: merge\lstinline!((b=66), (b=6))!
becomes \lstinline!(b=66)!.
Outer modifications override inner modifications, e.g., \lstinline!b = 66!
overrides the nested class modification of extends \lstinline!C2(b = 6)!.
This is known as merging of modifications: merge\lstinline!((b = 66), (b = 6))!
becomes \lstinline!(b = 66)!.

A flattening of class \lstinline!C4! will give an object with the following variables:
\begin{longtable}[]{|@{}l|l@{}|}
\hline \endhead
\tablehead{Variable} & \tablehead{Default value}\\ \hline
\lstinline!x1! & \lstinline!none!\\ \hline
\lstinline!x2! & \lstinline!22!\\ \hline
\lstinline!x3.a! & \lstinline!33!\\ \hline
\lstinline!x4.b! & \lstinline!4!\\ \hline
\lstinline!x4.c! & \lstinline!44!\\ \hline
\lstinline!x5.a! & \lstinline!x3.a!\\ \hline
\lstinline!a! & \lstinline!55!\\ \hline
\lstinline!b! & \lstinline!66!\\ \hline
\lstinline!c! & \lstinline!77!\\ \hline
\end{longtable}
\begin{center}
\begin{tabular}{l|l}
\hline
\tablehead{Variable} & \tablehead{Default value}\\
\hline
\hline
\lstinline!x1! & \textit{none}\\ % Look of \emph won't be as expected inside example.
\lstinline!x2! & 22\\
\lstinline!x3.a! & 33\\
\lstinline!x4.b! & 4\\
\lstinline!x4.c! & 44\\
\lstinline!x5.a! & \lstinline!x3.a!\\
\lstinline!a! & 55\\
\lstinline!b! & 66\\
\lstinline!c! & 77\\
\hline
\end{tabular}
\end{center}
\end{example}

\subsection{Single Modification}\label{single-modification}
Expand Down

0 comments on commit 04dc5f8

Please sign in to comment.