18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

116 Arrays<br />

8.6.1 Multidimensional <strong>in</strong>itializations<br />

A cursor on a black and white screen can be def<strong>in</strong>ed by the follow<strong>in</strong>g declaration of an object cursor_style:<br />

Bits_Cursor : constant Positive := 5;<br />

type Bit is new Integer range 0 .. 1;<br />

type Cursor_Index is new Positive range 1 .. Bits_Cursor;<br />

type Cursor is array( Cursor_Index,<br />

Cursor_Index ) of Bit;<br />

Cursor_Style : Cursor;<br />

Black is represented by 1<br />

White is represented by 0<br />

Figure 8.3 Black and white cursor.<br />

The cursor as illustrated <strong>in</strong> Figure 8.3 could be set up <strong>in</strong> cursor_style with any of the follow<strong>in</strong>g three<br />

declarations:<br />

• by <strong>in</strong>itializ<strong>in</strong>g every cell <strong>in</strong> the cursor <strong>in</strong>dividually:<br />

Cursor_Style := Cursor'( (1, 0, 0, 0, 1),<br />

(0, 1, 1, 1, 0),<br />

(0, 0, 1, 0, 0),<br />

(0, 1, 1, 1, 0),<br />

(1, 0, 0, 0, 1) );<br />

Note: The prefix to the array constant is optional <strong>in</strong> this case.<br />

• by us<strong>in</strong>g an others clause to set up the white elements:<br />

Cursor_Style := Cursor'( 1=> ( 1=>1, 5=>1, others => 0 ),<br />

2=> ( 2..4 =>1, others => 0 ),<br />

3=> ( 3=>1, others => 0 ),<br />

4=> ( 2..4 =>1, others => 0 ),<br />

5=> ( 1=>1, 5=>1, others => 0 ) );<br />

• by us<strong>in</strong>g | clauses to comb<strong>in</strong>e any identical <strong>in</strong>itializations:<br />

Cursor_Style := Cursor'( 1|5=> ( 1|5 =>1, others => 0 ),<br />

2|4=> ( 2..4=>1, others => 0 ),<br />

3 => ( 3 =>1, others => 0 ) );<br />

In a program us<strong>in</strong>g a colour monitor, the cursor could have been described as follows:<br />

Bits_Cursor: constant Positive := 5;<br />

type Colour is ( Red, Green, Blue );<br />

type Intensity is range 0 .. 255;<br />

type Pixel_Array is array( Colour ) of Intensity;<br />

type Cursor_Index is new Positive range 1 .. Bits_Cursor;<br />

type Cursor is array( Cursor_Index,<br />

Cursor_Index ) of Pixel_Array;<br />

Cursor_Style : Cursor;<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!