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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

194 Child libraries<br />

14.2 Specification of generic component<br />

The formal type specification constra<strong>in</strong>s the actual type passed as a parameter to belong to a particular category of<br />

types. Examples of these categories are listed <strong>in</strong> the table below:<br />

Formal type specification In Actual parameter can belong to Note<br />

type T<br />

<strong>Ada</strong> 83 the follow<strong>in</strong>g types<br />

is private √ Any non limited type. 1<br />

is limited private √ Any type. 2<br />

is tagged r Any non limited tagged type. 1<br />

is limited tagged r Any tagged type. 2<br />

is () √ Any discrete type, constra<strong>in</strong>ed type. 1,5<br />

() is private r Any discrete or <strong>in</strong>def<strong>in</strong>ite non 2,3<br />

limited type.<br />

() is limited r Any discrete or <strong>in</strong>def<strong>in</strong>ite type. 2,3<br />

private<br />

is mod r Any modular type. 1<br />

is range √ Any <strong>in</strong>teger type. 1<br />

is digits √ Any float type. 1<br />

is delta √ Any fixed ord<strong>in</strong>ary type. 1<br />

is delta digits r Any fixed decimal type. 1<br />

is access √ Any access type. 4<br />

with procedure ... √ procedure match<strong>in</strong>g the signature. 6<br />

with package ... r package match<strong>in</strong>g the signature. 6<br />

Note 1<br />

Note 2<br />

Note 3<br />

The formal parameter <strong>in</strong> the generic unit is restricted to a use compatible with the actual parameter.<br />

The formal parameter is restricted to operations which are compatible with a limited type. Thus,<br />

assignment of, and the default comparison for equality and not equality are prohibited.<br />

Cannot be used to declare an <strong>in</strong>def<strong>in</strong>ite type without declar<strong>in</strong>g its range. For example, the <strong>in</strong>def<strong>in</strong>ite<br />

type:<br />

type Str<strong>in</strong>g is array (Positive range ) of Character;<br />

cannot be declared without specify<strong>in</strong>g the range.<br />

Note 4 Access types are covered <strong>in</strong> chapter 14.<br />

May also be is access all or is access constant<br />

Note 5<br />

Note 6<br />

<strong>Ada</strong> 83 has the well-known problem that an <strong>in</strong>def<strong>in</strong>ite type may be used as a formal parameter. If the<br />

formal parameter is used to declare an object <strong>in</strong> the body of the generic unit, then on the <strong>in</strong>stantiation<br />

of the unit an error message will be generated from the body of the generic unit.<br />

Used to specify a procedure, function or package that is used <strong>in</strong> the body of the generic unit.<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!