type
identifier [discriminant_part] is
[limited
] private
;
deferred_constant_declaration ::=
identifier_list : constant
type_mark;
type
KEY is private
;
type
FILE_NAME is limited private
;
limited
appears in the private type declaration (see 7.4.4).
limited
appears in the declaration), membership tests, selected components for the selection of any discriminant, qualification, and explicit conversions.
limited
appears in the private type declaration.
package
KEY_MANAGER is
type
KEY is
private
;
NULL_KEY : constant
KEY;
procedure
GET_KEY(K : out
KEY);
function
"<" (X, Y : KEY) return
BOOLEAN;
private
type
KEY is new
NATURAL;
NULL_KEY : constant
KEY := 0;
end
;
package body
KEY_MANAGER is
LAST_KEY : KEY := 0;
procedure
GET_KEY(K : out
KEY) is
begin
LAST_KEY := LAST_KEY + 1;
K := LAST_KEY;
end
GET_KEY;
function
"<" (X, Y : KEY) return
BOOLEAN is
begin
return
INTEGER(X) < INTEGER(Y);
end
"<";
end
KEY_MANAGER;
not
(X >= Y), since the operator ">=" is not redefined.
limited
declares a limited type. A task type is a limited type. A type derived from a limited type is itself a limited type. Finally, a composite type is limited if the type of any of its subcomponents is limited.
out
is only allowed if this type is private and the subprogram declaration occurs within the visible part of the package that declares the private type. The same holds for formal parameters of entry declarations and of generic procedure declarations. The corresponding full type must not be limited if the mode out
is used for any such formal parameter. Otherwise, the corresponding full type is allowed (but not required) to be a limited type (in particular, it is allowed to be a task type). If the full type corresponding to a limited private type is not itself limited, then assignment for the type is available within the package, but not outside.
package
I_O_PACKAGE is
type
FILE_NAME is limited private
; procedure
OPEN (F : in out
FILE_NAME);
procedure
CLOSE(F : in out
FILE_NAME);
procedure
READ (F : in
FILE_NAME; ITEM : out
INTEGER);
procedure
WRITE(F : in
FILE_NAME; ITEM : in
INTEGER);
private
type
FILE_NAME is
record
INTERNAL_NAME : INTEGER := 0;
end record
;
end
I_O_PACKAGE;
package body
I_O_PACKAGE is
LIMIT : constant
:= 200;
type
FILE_DESCRIPTOR is record
... end record
;
DIRECTORY : array (1 .. LIMIT) of FILE_DESCRIPTOR;
...
procedure
OPEN (F : in out
FILE_NAME) is
... end
;
procedure
CLOSE(F : in out
FILE_NAME) is
... end
;
procedure
READ (F : in
FILE_NAME; ITEM : out
INTEGER) is
...
end
;
procedure
WRITE(F : in
FILE_NAME; ITEM : in
INTEGER) is
...
end
;
begin
...
end
I_O_PACKAGE;