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.

180 Child libraries<br />

The implementation of = is as follows:<br />

function "=" ( F:<strong>in</strong> Bounded_Str<strong>in</strong>g; S:<strong>in</strong> Bounded_Str<strong>in</strong>g )<br />

return Boolean is<br />

beg<strong>in</strong><br />

return F.V_Str.Chrs = S.V_Str.Chrs;<br />

end "=";<br />

end Class_bounded_str<strong>in</strong>g;<br />

Note:<br />

To compare an <strong>in</strong>stance of a Bounded_Str<strong>in</strong>g and an <strong>in</strong>stance of an <strong>Ada</strong> str<strong>in</strong>g a user would have<br />

to convert the <strong>Ada</strong> str<strong>in</strong>g to a Bounded_Str<strong>in</strong>g. For example:<br />

Name : Bounded_Str<strong>in</strong>g;<br />

if Name > To_Bounded_Str<strong>in</strong>g( "Brighton" ) then<br />

12.3.3 Putt<strong>in</strong>g it all together<br />

procedure Ma<strong>in</strong> is<br />

Town, County, Address : Bounded_Str<strong>in</strong>g;<br />

beg<strong>in</strong><br />

Town := To_Bounded_Str<strong>in</strong>g( "Brighton" );<br />

County := To_Bounded_Str<strong>in</strong>g( "East Sussex" );<br />

Address := Town & " " & County;<br />

Put( To_Str<strong>in</strong>g(Address) ); New_L<strong>in</strong>e;<br />

Put( Slice( County & " UK", 6, 14 ) );<br />

New_L<strong>in</strong>e;<br />

end Ma<strong>in</strong>;<br />

When run, this would produce the follow<strong>in</strong>g results:<br />

Brighton East Sussex<br />

Sussex UK<br />

12.3.4 <strong>Ada</strong>.Str<strong>in</strong>gs.Bounded a standard library<br />

In the standard library there is a package <strong>Ada</strong>.Str<strong>in</strong>gs.Bounded which the above class Bounded_Str<strong>in</strong>g<br />

is based on. The generic library package <strong>Ada</strong>.Str<strong>in</strong>gs.Bounded.Generic_bounded_length allows<br />

the maximum length of the stored str<strong>in</strong>g to be def<strong>in</strong>ed by a user of the package. Chapter 13 describes the concepts<br />

of generics. Appendix C.8 lists the specification of the library package <strong>Ada</strong>.Str<strong>in</strong>gs.Bounded.<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!