home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / lrm / chap07.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  39.6 KB  |  1,784 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. The following document is a draft  of  the  corresponding  chapter  of  the
  7. version  of  the  Ada  Reference  Manual  produced  in response to the Ansi
  8. Canvass.  It is given a limited circulation  to  Ada  implementers  and  to
  9. other groups contributing comments (according to the conventions defined in
  10. RRM.comments).  This draft should not be referred to in any publication.
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                       ANSI-RM-07-v23 - Draft Chapter
  17.  
  18.                                 7  Packages
  19.                                 version 23
  20.  
  21.                                  83-02-11
  22.  
  23.  
  24. This revision has addressed comments up to #5795
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                                 7. Packages
  78.  
  79.  
  80.  
  81. Packages  are  one of the four forms of program unit, of which programs can
  82. be composed.  The other forms are  subprograms,  task  units,  and  generic
  83. units.
  84.  
  85. Packages  allow  the specification of groups of logically related entities.
  86. In their simplest form packages specify pools of  common  object  and  type
  87. declarations.   More  generally,  packages can be used to specify groups of
  88. related entities including also subprograms that can be called from outside
  89. the package, while their inner workings remain concealed and protected from
  90. outside users.
  91.  
  92.  
  93. References:  generic unit 12, program unit 6, subprogram 6,  task  unit  9,
  94. type declaration 3.3.1
  95.  
  96.  
  97.  
  98.  
  99. 7.1  Package Structure
  100.  
  101.  
  102. A  package is generally provided in two parts:  a package specification and
  103. a package body.  Every package has a package  specification,  but  not  all
  104. packages have a package body.
  105.  
  106.     package_declaration ::= package_specification;
  107.  
  108.     package_specification ::=
  109.         package identifier is
  110.           {basic_declarative_item}
  111.        [private
  112.           {basic_declarative_item}]
  113.         end [package_simple_name]
  114.  
  115.     package_body ::=
  116.         package body package_simple_name is
  117.            [declarative_part]
  118.        [begin
  119.             sequence_of_statements
  120.        [exception
  121.             exception_handler
  122.            {exception_handler}]]
  123.         end [package_simple_name];
  124.  
  125. The  simple  name  at  the  start of a package body must repeat the package
  126. identifier.  Similarly if a simple name appears at the end of  the  package
  127.  
  128.  
  129.                                    7 - 1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. specification or body, it must repeat the package identifier.
  139.  
  140. If  a subprogram declaration, a package declaration, a task declaration, or
  141. a  generic  declaration  is  a  declarative  item  of   a   given   package
  142. specification, then the body (if there is one) of the program unit declared
  143. by  the  declarative  item  must  itself  be  a  declarative  item  of  the
  144. declarative part of the body of the given package.
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                    7 - 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. Notes:
  205.  
  206. A simple form of package, specifying a pool of objects and types, does  not
  207. require  a  package  body.   One  of  the  possible uses of the sequence of
  208. statements of a package body is  to  initialize  such  objects.   For  each
  209. subprogram  declaration   there  must be a corresponding body (except for a
  210. subprogram written in another language, as explained in section 13.9).   If
  211. the  body  of  a  program  unit  is a body stub, then a separately compiled
  212. subunit containing the  corresponding  proper  body  is  required  for  the
  213. program  unit  (see  10.2).   A body is not a basic declarative item and so
  214. cannot appear in a package specification.
  215.  
  216. A package  declaration  is  either  a  library  package  (see  10.2)  or  a
  217. declarative item declared within another program unit.
  218.  
  219.  
  220. References:   basic  declarative item 3.9, body stub 10.2, declarative item
  221. 3.9, declarative part 3.9,  exception  handler  11.2,  generic  body  12.2,
  222. generic  declaration  12.1,  identifier 2.3, library unit 10.1, object 3.2,
  223. package body 7.3, program unit 6, proper body 3.9, sequence  of  statements
  224. 5.1,  simple  name  4.1,  subprogram  body 6.3, subprogram declaration 6.1,
  225. subunit 10.2, task body 9.1, task declaration 9.1, type 3.3
  226.  
  227.  
  228.  
  229.  
  230. 7.2  Package Specifications and Declarations
  231.  
  232.  
  233. The first list of declarative items  of  a package specification is  called
  234. the  visible  part  of the package.  The optional list of declarative items
  235. after the reserved word private is called the private part of the  package.
  236.  
  237. An  entity declared in the private part of a package is not visible outside
  238. the package itself  (a name denoting such an entity is only possible within
  239. the package).  In contrast, expanded names denoting  entities  declared  in
  240. the visible part can be used even outside the package;  furthermore, direct
  241. visibility  of  such  entities can be achieved by means of use clauses (see
  242. 4.1.3 and 8.4).
  243.  
  244. The elaboration of a package declaration consists of the elaboration of its
  245. basic declarative items in the given order.
  246.  
  247. Notes:
  248.  
  249. The visible part of a package contains all  the  information  that  another
  250. program  unit  is  able to know about the package.  A package consisting of
  251. only a package specification (that is, without a package body) can be  used
  252. to  represent a group of common constants or variables, or a common pool of
  253. objects and types, as in the examples below.
  254.  
  255. Example of a package describing a group of common variables:
  256.  
  257.     package PLOTTING_DATA is
  258.        PEN_UP : BOOLEAN;
  259.  
  260.  
  261.                                    7 - 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.        CONVERSION_FACTOR,
  271.        X_OFFSET, Y_OFFSET,
  272.        X_MIN,    Y_MIN,
  273.        X_MAX,    Y_MAX:   REAL;     --  see 3.5.7
  274.  
  275.        X_VALUE : array (1 .. 500) of REAL;
  276.        Y_VALUE : array (1 .. 500) of REAL;
  277.     end PLOTTING_DATA;
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                    7 - 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. Example of a package describing a common pool of objects and types:
  337.  
  338.  
  339.     package WORK_DATA is
  340.        type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN);
  341.        type HOURS_SPENT is delta 0.25 range 0.0 .. 24.0;
  342.        type TIME_TABLE  is array (DAY) of HOURS_SPENT;
  343.  
  344.        WORK_HOURS   : TIME_TABLE;
  345.        NORMAL_HOURS : constant TIME_TABLE :=
  346.                          (MON .. THU => 8.25, FRI => 7.0, SAT | SUN => 0.0);
  347.     end WORK_DATA;
  348.  
  349.  
  350.  
  351. References:  basic declarative item 3.9, constant 3.2.1,  declarative  item
  352. 3.9, direct visibility 8.3, elaboration 3.9, expanded name 4.1.3, name 4.1,
  353. number  declaration  3.2.2,  object  declaration  3.2.1, package 7, package
  354. declaration 7.1, package identifier 7.1, package specification  7.1,  scope
  355. 8.2,  simple  name  4.1,  type  declaration 3.3.1, use clause 8.4, variable
  356. 3.2.1
  357.  
  358.  
  359.  
  360.  
  361. 7.3  Package Bodies
  362.  
  363.  
  364. In contrast to the entities declared in  the  visible  part  of  a  package
  365. specification,  the  entities declared in the package body are only visible
  366. within the package body itself.  As a consequence, a package with a package
  367. body can be used for the construction of a group of related subprograms  (a
  368. package  in  the usual sense), in which the logical operations available to
  369. the users are clearly isolated from the internal entities.
  370.  
  371. For the elaboration of a  package  body,  its  declarative  part  is  first
  372. elaborated,  and its sequence of statements (if any) is then executed.  The
  373. optional  exception  handlers  at  the  end  of  a  package  body   service
  374. exceptions raised during the execution of the sequence of statements of the
  375. package body.
  376.  
  377.  
  378. Notes:
  379.  
  380. A  variable  declared  in the body of a package is only visible within this
  381. body and, consequently, its value can only be changed  within  the  package
  382. body.   In the absence of local tasks, the value of such a variable remains
  383. unchanged between calls issued from  outside  the  package  to  subprograms
  384. declared  in  the  visible  part.   The  properties  of such a variable are
  385. similar to those of an "own" variable of Algol 60.
  386.  
  387. The elaboration of the body of a subprogram declared in the visible part of
  388. a package is caused by the elaboration of the body of the package.  Hence a
  389. call of such a subprogram by an outside program unit raises  the  exception
  390. PROGRAM_ERROR if the call takes place before the elaboration of the package
  391.  
  392.  
  393.                                    7 - 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. body (see 3.9).
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                    7 - 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. Example of a package:
  470.  
  471.  
  472.     package RATIONAL_NUMBERS is
  473.  
  474.        type RATIONAL is
  475.           record
  476.              NUMERATOR   : INTEGER;
  477.              DENOMINATOR : POSITIVE;
  478.           end record;
  479.  
  480.        function EQUAL(X,Y : RATIONAL) return BOOLEAN;
  481.  
  482.        function "/"  (X,Y : INTEGER)  return RATIONAL;  --  to construct a rational number
  483.  
  484.        function "+"  (X,Y : RATIONAL) return RATIONAL;
  485.        function "-"  (X,Y : RATIONAL) return RATIONAL;
  486.        function "*"  (X,Y : RATIONAL) return RATIONAL;
  487.        function "/"  (X,Y : RATIONAL) return RATIONAL;
  488.     end;
  489.  
  490.     package body RATIONAL_NUMBERS is
  491.  
  492.        procedure SAME_DENOMINATOR (X,Y : in out RATIONAL) is
  493.        begin
  494.           --  reduces X and Y to the same denominator:
  495.           ...
  496.        end;
  497.  
  498.        function EQUAL(X,Y : RATIONAL) return BOOLEAN is
  499.           U,V : RATIONAL;
  500.        begin
  501.           U := X;
  502.           V := Y;
  503.           SAME_DENOMINATOR (U,V);
  504.           return U.NUMERATOR = V.NUMERATOR;
  505.        end EQUAL;
  506.  
  507.        function "/" (X,Y : INTEGER) return RATIONAL is
  508.        begin
  509.           if Y > 0 then
  510.              return (NUMERATOR => X,  DENOMINATOR => Y);
  511.           else
  512.              return (NUMERATOR => -X, DENOMINATOR => -Y);
  513.           end if;
  514.        end "/";
  515.  
  516.        function "+" (X,Y : RATIONAL) return RATIONAL is ...  end "+";
  517.        function "-" (X,Y : RATIONAL) return RATIONAL is ...  end "-";
  518.        function "*" (X,Y : RATIONAL) return RATIONAL is ...  end "*";
  519.        function "/" (X,Y : RATIONAL) return RATIONAL is ...  end "/";
  520.  
  521.     end RATIONAL_NUMBERS;
  522.  
  523.  
  524.  
  525.                                    7 - 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535. References:   declaration  3.1,  declarative part 3.9, elaboration 3.1 3.9,
  536. exception 11, exception handler 11.2, name 4.1, package specification  7.1,
  537. program  unit  6, program_error exception 11.1, sequence of statements 5.1,
  538. subprogram 6, variable 3.2.1, visible part 7.2
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                    7 - 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604. 7.4  Private Type and Deferred Constant Declarations
  605.  
  606.  
  607. The declaration of a type as a private  type  in  the  visible  part  of  a
  608. package serves to separate the characteristics that can be used directly by
  609. outside  program  units  (that  is,  the  logical  properties)  from  other
  610. characteristics whose direct use is confined to the package (the details of
  611. the definition of the type itself).  Deferred constant declarations declare
  612. constants of private types.
  613.  
  614.     private_type_declaration ::=
  615.        type identifier [discriminant_part] is [limited] private;
  616.  
  617.     deferred_constant_declaration ::=
  618.        identifier_list : constant type_mark;
  619.  
  620. A private type declaration is only  allowed as a declarative  item  of  the
  621. visible  part  of  a package, or as the generic parameter declaration for a
  622. generic formal type in a generic formal part.
  623.  
  624. The type mark of a deferred constant declaration must denote a private type
  625. or a subtype of a private type;  a deferred constant  declaration  and  the
  626. declaration  of  the  corresponding  private  type must both be declarative
  627. items of the visible  part  of  the  same  package.   A  deferred  constant
  628. declaration  with several identifiers is equivalent to a sequence of single
  629. deferred constant declarations as explained in section 3.2.
  630.  
  631. Examples of private type declarations:
  632.  
  633.     type KEY is private;
  634.     type FILE_NAME is limited private;
  635.  
  636. Example of deferred constant declaration:
  637.  
  638.     NULL_KEY : constant KEY;
  639.  
  640.  
  641. References:   constant  3.2.1,  declaration  3.1,  declarative  item   3.9,
  642. deferred constant 7.4.3, discriminant part 3.7.1, generic formal part 12.1,
  643. generic  formal  type  12.1, generic parameter declaration 12.1, identifier
  644. 2.3, identifier list 3.2, limited  type  7.4.4,  package  7,  private  type
  645. 7.4.1, program unit 6, subtype 3.3, type 3.3, type mark 3.3.2, visible part
  646. 7.2
  647.  
  648.  
  649.  
  650.  
  651. 7.4.1  Private Types
  652.  
  653.  
  654.  
  655.  
  656.  
  657.                                    7 - 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666. If  a  private  type declaration is given in the visible part of a package,
  667. then a corresponding declaration of a type with the  same  identifier  must
  668. appear  as  a  declarative  item  of  the private part of the package.  The
  669. corresponding declaration must be either a full  type  declaration  or  the
  670. declaration  of  a task type.  In the rest of this section explanations are
  671. given in terms of full type declarations;  the same  rules  apply  also  to
  672. declarations of task types.
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                   7 - 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. A  private  type  declaration  and  the corresponding full type declaration
  733. define a single type.  The private  type  declaration,  together  with  the
  734. visible  part,  define the operations that are available to outside program
  735. units (see section 7.4.2 on the operations that are available  for  private
  736. types).   On  the  other  hand,  the  full  type  declaration defines other
  737. operations whose direct use is only possible within the package itself.
  738.  
  739. If the private type declaration includes  a  discriminant  part,  the  full
  740. declaration  must  include a discriminant part that conforms (see 6.3.1 for
  741. the conformance rules) and its  type  definition  must  be  a  record  type
  742. definition.  Conversely, if the private type declaration does not include a
  743. discriminant part, the type declared by the full type declaration (the full
  744. type)  must not be an unconstrained type with discriminants.  The full type
  745. must not be an unconstrained array type.  A limited type (in  particular  a
  746. task  type)  is allowed for the full type only if the reserved word limited
  747. appears in the private type declaration (see 7.4.4).
  748.  
  749. Within the specification of the package that declares a  private  type  and
  750. before  the  end  of the corresponding full type declaration, a restriction
  751. applies to the use of a name that denotes the private type or a subtype  of
  752. the  private type and, likewise, to the use of a name that denotes any type
  753. or subtype that has a subcomponent of the private type.  The  only  allowed
  754. occurrences  of  such a name are in a deferred constant declaration, a type
  755. or  subtype  declaration,  a  subprogram   specification,   or   an   entry
  756. declaration;   moreover,  occurrences  within  derived  type definitions or
  757. within simple expressions are not allowed.
  758.  
  759. The elaboration of a private type declaration creates a private  type.   If
  760. the  private  type  declaration  has  a discriminant part, this elaboration
  761. includes that of the discriminant part.  The elaboration of the  full  type
  762. declaration  consists  of  the  elaboration  of  the  type definition;  the
  763. discriminant  part,  if  any,  is  not  elaborated  (since  the  conforming
  764. discriminant  part  of  the  private  type  declaration  has  already  been
  765. elaborated).
  766.  
  767. Notes:
  768.  
  769. It follows from the given rules that neither the declaration of a  variable
  770. of  a  private  type,  nor the creation by an allocator of an object of the
  771. private  type  are  allowed  before  the  full  declaration  of  the  type.
  772. Similarly  before the full declaration, the name of the private type cannot
  773. be used in a generic instantiation or in a representation clause.
  774.  
  775.  
  776. References:  allocator 4.8, array type 3.6, conform 6.3.1, declarative item
  777. 3.9, deferred constant declaration 7.4.3, derived  type  3.4,  discriminant
  778. part  3.7.1,  elaboration  3.9, entry declaration 9.5, expression 4.4, full
  779. type  declaration  3.3.1,  generic  instantiation  12.3,  identifier   2.3,
  780. incomplete  type declaration 3.8.1, limited type 7.4.4, name 4.1, operation
  781. 3.3, package 7, package specification 7.1, private part 7.2,  private  type
  782. 7.4,   private   type   declaration   7.4,   record  type  definition  3.7,
  783. representation clause 13.1, reserved word 2.9, subcomponent 3.3, subprogram
  784. specification 6.1, subtype 3.3, subtype declaration 3.3.2, type  3.3,  type
  785. declaration  3.3.1,  type  definition  3.3.1, unconstrained array type 3.6,
  786. variable 3.2.1, visible part 7.2
  787.  
  788.  
  789.                                   7 - 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801. 7.4.2  Operations of a Private Type
  802.  
  803.  
  804. The operations that are implicitly declared by a private  type  declaration
  805. include  basic operations.  These are the operations involved in assignment
  806. (unless the reserved word limited appears in the  declaration),  membership
  807. tests,   selected   components  for  the  selection  of  any  discriminant,
  808. qualification, and explicit conversions.
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                   7 - 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. For a private type T, the basic  operations  also  include  the  attributes
  865. T'BASE  (see  3.3.3) and T'SIZE (see 13.7.2).  For an object A of a private
  866. type, the basic operations  include  the  attribute  A'CONSTRAINED  if  the
  867. private type has discriminants (see 3.7.4), and in any case, the attributes
  868. A'SIZE and A'ADDRESS (see 13.7.2).
  869.  
  870. Finally,  the  operations implicitly declared by a private type declaration
  871. include the predefined comparison for equality and  inequality  unless  the
  872. reserved word limited appears in the private type declaration.
  873.  
  874. The  above  operations,  together with subprograms that have a parameter or
  875. result of the private type and that are declared in the visible part of the
  876. package, are the only  operations  from  the  package  that  are  available
  877. outside the package for the private type.
  878.  
  879. Within   the  package  that  declares  the  private  type,  the  additional
  880. operations implicitly declared  by  the  full  type  declaration  are  also
  881. available.    However,   the  redefinition  of  these  implicitly  declared
  882. operations is allowed within the same declarative region, including between
  883. the private type declaration and the corresponding  full  declaration.   An
  884. explicitly  declared subprogram hides an implicitly declared operation that
  885. has the same parameter and result type profile (this is  only  possible  if
  886. the  implicitly  declared operation is a derived subprogram or a predefined
  887. operator).
  888.  
  889. If a composite type has subcomponents of a private  type  and  is  declared
  890. outside  the  package  that  declares the private type, then the operations
  891. that are implicitly declared by  the  declaration  of  the  composite  type
  892. include  all operations that only depend on the characteristics that result
  893. from the private type declaration alone.  (For example the  operator  <  is
  894. not included for a one-dimensional array type.)
  895.  
  896. If  the  composite type is itself declared within the package that declares
  897. the private type (including within an inner package  or  generic  package),
  898. then  additional  operations that depend on the characteristics of the full
  899. type are implicitly declared, as required by the rules  applicable  to  the
  900. composite   type   (for   example   the   operator  <  is  declared  for  a
  901. one-dimensional array type if the full type is discrete).  These additional
  902. operations are  implicitly  declared  at  the  earliest  place  within  the
  903. immediate  scope of the composite type and after the full type declaration.
  904.  
  905. The same rules apply to the operations that are implicitly declared for  an
  906. access  type  whose designated type is a private type or a type declared by
  907. an incomplete type declaration.
  908.  
  909. For every private type or subtype T the following attribute is defined:
  910.  
  911. T'CONSTRAINED Yields  the  value  FALSE  if  T  denotes  an   unconstrained
  912.               nonformal  private  type with discriminants;  also yields the
  913.               value FALSE if T denotes a generic formal private  type,  and
  914.               the associated actual subtype is either an unconstrained type
  915.               with  discriminants  or  an unconstrained array type;  yields
  916.               the value TRUE otherwise.  The value of this attribute is  of
  917.               the predefined type BOOLEAN.
  918.  
  919.  
  920.  
  921.                                   7 - 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930. Note:
  931.  
  932. A  private  type  declaration  and  the corresponding full type declaration
  933. define two different views of one  and  the  same  type.   Outside  of  the
  934. defining  package  the characteristics of the type are those defined by the
  935. visible part.  Within these outside  program  units  the  type  is  just  a
  936. private  type  and  any language rule that applies only to another class of
  937. types does not apply.  The fact that the full declaration  might  implement
  938. the  private  type  with  a  type of a particular class (for example, as an
  939. array type) is only relevant within the package itself.
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                   7 - 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998. The  consequences  of  this  actual  implementation  are,  however,   valid
  999. everywhere.   For  example:  any default initialization of components takes
  1000. place;  the attribute SIZE provides  the  size  of  the  full  type;   task
  1001. dependence rules still apply to components that are task objects.
  1002.  
  1003. Example:
  1004.  
  1005.     package KEY_MANAGER is
  1006.        type KEY is private;
  1007.        NULL_KEY : constant KEY;
  1008.        procedure GET_KEY(K : out KEY);
  1009.        function "<" (X, Y : KEY) return BOOLEAN;
  1010.     private
  1011.        type KEY is new NATURAL;
  1012.        NULL_KEY : constant KEY := 0;
  1013.     end;
  1014.  
  1015.     package body KEY_MANAGER is
  1016.        LAST_KEY : KEY := 0;
  1017.        procedure GET_KEY(K : out KEY) is
  1018.        begin
  1019.           LAST_KEY := LAST_KEY + 1;
  1020.           K := LAST_KEY;
  1021.        end GET_KEY;
  1022.  
  1023.        function "<" (X, Y : KEY) return BOOLEAN is
  1024.        begin
  1025.           return INTEGER(X) < INTEGER(Y);
  1026.        end "<";
  1027.     end KEY_MANAGER;
  1028.  
  1029. Notes on the example:
  1030.  
  1031. Outside of the package KEY_MANAGER, the operations available for objects of
  1032. type KEY include assignment, the comparison for equality or inequality, the
  1033. procedure  GET_KEY  and  the  operator  "<";   they  do  not  include other
  1034. relational operators such as ">=", or arithmetic operators.
  1035.  
  1036. The explicitly declared operator "<"  hides  the  predefined  operator  "<"
  1037. implicitly  declared  by the full type declaration.  Within the body of the
  1038. function, an explicit conversion  of  X  and  Y  to  the  type  INTEGER  is
  1039. necessary  to  invoke  the  "<"  operator of this type.  Alternatively, the
  1040. result of the function could be written as not (X >= Y), since the operator
  1041. ">=" is not redefined.
  1042.  
  1043. The value of the variable LAST_KEY, declared in the package  body,  remains
  1044. unchanged  between  calls of the procedure GET_KEY.  (See also the Notes of
  1045. section 7.3.)
  1046.  
  1047. References:   assignment  5.2,  attribute  4.1.4,  basic  operation  3.3.3,
  1048. component  3.3,  composite  type  3.3,  conversion  4.6,  declaration  3.1,
  1049. declarative region 8.1, derived subprogram 3.4, derived type 3.4, dimension
  1050. 3.6,  discriminant  3.3,  equality  4.5.2,  full  type  7.4.1,  full   type
  1051.  
  1052.  
  1053.                                   7 - 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062. declaration  3.3.1,  hiding  8.3, immediate scope 8.2, implicit declaration
  1063. 3.1, incomplete type declaration 3.8.1, membership test 4.5, operation 3.3,
  1064. package  7,  parameter  of  a  subprogram  6.2,  predefined  function  8.6,
  1065. predefined  operator  4.5,  private type 7.4, private type declaration 7.4,
  1066. program unit  6,  qualification  4.7,  relational  operator  4.5,  selected
  1067. component 4.1.3, subprogram 6, task dependence 9.4, visible part 7.2
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                   7 - 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128. 7.4.3  Deferred Constants
  1129.  
  1130.  
  1131. If  a  deferred  constant  declaration  is  given  in the visible part of a
  1132. package then  a  constant  declaration  (that  is,  an  object  declaration
  1133. declaring a constant object, with an explicit initialization) with the same
  1134. identifier  must  appear  as  a declarative item of the private part of the
  1135. package.   This object declaration is called the full  declaration  of  the
  1136. deferred  constant.   The  type  mark  given  in  the full declaration must
  1137. conform to that given in the deferred  constant  declaration  (see  6.3.1).
  1138. Multiple  or  single declarations are allowed for the deferred and the full
  1139. declarations, provided that the equivalent single declarations conform.
  1140.  
  1141. Within the specification of the package that declares a  deferred  constant
  1142. and before the end of the corresponding full declaration, the use of a name
  1143. that  denotes  the  deferred  constant  is  only  allowed  in  the  default
  1144. expression for a record component or for a  formal  parameter  (not  for  a
  1145. generic formal parameter).
  1146.  
  1147. The elaboration of a deferred constant declaration has no other effect.
  1148.  
  1149. The  execution of a program is erroneous if it attempts to use the value of
  1150. a deferred constant  before  the  elaboration  of  the  corresponding  full
  1151. declaration.
  1152.  
  1153. Note:
  1154.  
  1155. The  full declaration for a deferred constant that has a given private type
  1156. must not appear before the corresponding full type declaration.  This is  a
  1157. consequence of the rules defining the allowed uses of a name that denotes a
  1158. private type (see 7.4.1).
  1159.  
  1160.  
  1161. References:   conform  6.3.1,  constant declaration 3.2.1, declarative item
  1162. 3.9, default expression for a discriminant 3.7.1,  deferred  constant  7.4,
  1163. deferred  constant  declaration  7.4,  elaboration has no other effect 3.1,
  1164. formal parameter 6.1, generic formal parameter 12.1 12.3,  identifier  2.3,
  1165. object  declaration  3.2.1,  package  7, package specification 7.1, private
  1166. part 7.2, record component 3.7, type mark 3.3.2, visible part 7.2
  1167.  
  1168.  
  1169.  
  1170.  
  1171. 7.4.4  Limited Types
  1172.  
  1173.  
  1174. A limited type is a type for which neither assignment  nor  the  predefined
  1175. comparison for equality and inequality is implicitly declared.
  1176.  
  1177. A private type declaration that includes the reserved word limited declares
  1178. a  limited  type.   A  task  type is a limited type.  A type derived from a
  1179. limited type is itself a  limited  type.   Finally,  a  composite  type  is
  1180. limited if the type of any of its subcomponents is limited.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                   7 - 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. The operations available for a private type that is limited are as given in
  1195. section 7.4.2 for private types except for the absence of assignment and of
  1196. a predefined comparison for equality and inequality.
  1197.  
  1198. For  a  formal parameter whose type is limited and whose declaration occurs
  1199. in an explicit subprogram declaration, the mode out is only allowed if this
  1200. type is private and the subprogram declaration occurs  within  the  visible
  1201. part  of  the  package  that declares the private type.  The same holds for
  1202. formal  parameters  of  entry  declarations  and   of   generic   procedure
  1203. declarations.   The corresponding full type must not be limited if the mode
  1204. out is used for any such formal parameter.   Otherwise,  the  corresponding
  1205. full  type  is  allowed  (but  not  required)  to  be  a  limited  type (in
  1206. particular,  it  is  allowed  to  be  a  task  type).   If  the  full  type
  1207. corresponding  to  a  limited  private  type  is  not  itself limited, then
  1208. assignment for the type is available within the package, but  not  outside.
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                   7 - 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. The following are consequences of the rules for limited types:
  1261.  
  1262.   -  An explicit initialization is not allowed in an object declaration  if
  1263.      the type of the object is limited.
  1264.  
  1265.   -  A default expression is not allowed in a component declaration if  the
  1266.      type of the record component is limited.
  1267.  
  1268.   -  An explicit initial value is  not  allowed  in  an  allocator  if  the
  1269.      designated type is limited.
  1270.  
  1271.   -  A generic formal parameter of mode in must not be of a  limited  type.
  1272.  
  1273. Notes:
  1274.  
  1275. The above rules do not exclude  a default expression for a formal parameter
  1276. of  a  limited  type;  they do not exclude a deferred constant of a limited
  1277. type if the full type is  not  limited.   An  explicit  declaration  of  an
  1278. equality operator is allowed for a limited type (see 6.7).
  1279.  
  1280. Aggregates  are  not  available for a limited composite type (see 3.6.2 and
  1281. 3.7.4).  Catenation is not available for a limited array type (see  3.6.2).
  1282.  
  1283. Example:
  1284.  
  1285.     package I_O_PACKAGE is
  1286.        type FILE_NAME is limited private;
  1287.  
  1288.        procedure OPEN (F : in out FILE_NAME);
  1289.        procedure CLOSE(F : in out FILE_NAME);
  1290.        procedure READ (F : in FILE_NAME; ITEM : out INTEGER);
  1291.        procedure WRITE(F : in FILE_NAME; ITEM : in  INTEGER);
  1292.     private
  1293.        type FILE_NAME is
  1294.           record
  1295.              INTERNAL_NAME : INTEGER := 0;
  1296.           end record;
  1297.     end I_O_PACKAGE;
  1298.  
  1299.     package body I_O_PACKAGE is
  1300.        LIMIT : constant := 200;
  1301.        type FILE_DESCRIPTOR is record  ...  end record;
  1302.        DIRECTORY : array (1 .. LIMIT) of FILE_DESCRIPTOR;
  1303.        ...
  1304.        procedure OPEN (F : in out FILE_NAME) is  ...  end;
  1305.        procedure CLOSE(F : in out FILE_NAME) is  ...  end;
  1306.        procedure READ (F : in FILE_NAME; ITEM : out INTEGER) is ... end;
  1307.        procedure WRITE(F : in FILE_NAME; ITEM : in  INTEGER) is ... end;
  1308.     begin
  1309.        ...
  1310.     end I_O_PACKAGE;
  1311.  
  1312. Notes on the example:
  1313.  
  1314.  
  1315.  
  1316.  
  1317.                                   7 - 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326. In  the  example above, an outside subprogram making use of I_O_PACKAGE may
  1327. obtain a file name by calling OPEN and later use it in calls  to  READ  and
  1328. WRITE.  Thus, outside the package, a file name obtained from OPEN acts as a
  1329. kind  of  password;   its internal properties (such as containing a numeric
  1330. value) are  not  known  and  no  other  operations  (such  as  addition  or
  1331. comparison of internal names) can be performed on a file name.
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                   7 - 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392. This  example is characteristic of any case where complete control over the
  1393. operations of a type is desired.  Such packages serve a dual purpose.  They
  1394. prevent a user from making use of the internal structure of the type.  They
  1395. also implement the notion of an  encapsulated  data  type  where  the  only
  1396. operations on the type are those given in the package specification.
  1397.  
  1398.  
  1399. References:   aggregate  4.3,  allocator  4.8,  assignment  5.2, catenation
  1400. operator 4.5, component declaration 3.7, component type 3.3, composite type
  1401. 3.3, default expression for a discriminant 3.7,  deferred  constant  7.4.3,
  1402. derived type 3.4, designate 3.8, discriminant specification 3.7.1, equality
  1403. 4.5.2,  formal parameter 6.1, full type 7.4.1, full type declaration 3.3.1,
  1404. generic formal parameter 12.1 12.3, implicit declaration 3.1, initial value
  1405. 3.2.1, mode 12.1.1,  object  3.2,  operation  3.3,  package  7,  predefined
  1406. operator  4.5,  private  type  7.4,  private  type  declaration 7.4, record
  1407. component 3.7, record type 3.7, relational operator 4.5, subcomponent  3.3,
  1408. subprogram 6, task type 9.1 9.2, type 3.3
  1409.  
  1410.  
  1411.  
  1412. 7.5  Example of a Table Management Package
  1413.  
  1414.  
  1415. The  following  example  illustrates  the use of packages in providing high
  1416. level procedures with a simple interface to the user.
  1417.  
  1418. The problem is to define a  table  management  package  for  inserting  and
  1419. retrieving  items.   The  items  are  inserted  into  the table as they are
  1420. supplied.  Each inserted item has an order number.  The items are retrieved
  1421. according to their order number, where  the  item  with  the  lowest  order
  1422. number is retrieved first.
  1423.  
  1424. From  the  user's  point  of view, the package is quite simple.  There is a
  1425. type called ITEM designating table items, a procedure INSERT for  inserting
  1426. items,  and  a  procedure  RETRIEVE  for obtaining the item with the lowest
  1427. order number.  There is a special item NULL_ITEM that is returned when  the
  1428. table  is  empty,  and an exception TABLE_FULL which is raised by INSERT if
  1429. the table is already full.
  1430.  
  1431. A sketch of such a package is given below.  Only the specification  of  the
  1432. package is exposed to the user.
  1433.  
  1434.     package TABLE_MANAGER is
  1435.  
  1436.        type ITEM is
  1437.           record
  1438.              ORDER_NUM : INTEGER;
  1439.              ITEM_CODE : INTEGER;
  1440.              QUANTITY  : INTEGER;
  1441.              ITEM_TYPE : CHARACTER;
  1442.           end record;
  1443.  
  1444.        NULL_ITEM : constant ITEM :=
  1445.           (ORDER_NUM | ITEM_CODE | QUANTITY => 0, ITEM_TYPE => ' ');
  1446.  
  1447.  
  1448.  
  1449.                                   7 - 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.        procedure INSERT  (NEW_ITEM   : in  ITEM);
  1459.        procedure RETRIEVE(FIRST_ITEM : out ITEM);
  1460.  
  1461.        TABLE_FULL : exception;  --  raised by INSERT when table full
  1462.     end;
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                   7 - 22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524. The  details  of  implementing such packages can be quite complex;  in this
  1525. case they involve a two-way  linked  table  of  internal  items.   A  local
  1526. housekeeping  procedure  EXCHANGE  is used to move an internal item between
  1527. the busy and the free lists.  The initial table linkages are established by
  1528. the initialization part.  The package body need not be shown to  the  users
  1529. of the package.
  1530.  
  1531.     package body TABLE_MANAGER is
  1532.        SIZE : constant := 2000;
  1533.        subtype INDEX is INTEGER range 0 .. SIZE;
  1534.  
  1535.        type INTERNAL_ITEM is
  1536.           record
  1537.              CONTENT : ITEM;
  1538.              SUCC    : INDEX;
  1539.              PRED    : INDEX;
  1540.           end record;
  1541.  
  1542.        TABLE : array (INDEX) of INTERNAL_ITEM;
  1543.        FIRST_BUSY_ITEM : INDEX := 0;
  1544.        FIRST_FREE_ITEM : INDEX := 1;
  1545.  
  1546.        function FREE_LIST_EMPTY return BOOLEAN is ... end;
  1547.        function BUSY_LIST_EMPTY return BOOLEAN is ... end;
  1548.        procedure EXCHANGE (FROM : in INDEX; TO : in INDEX) is ... end;
  1549.  
  1550.        procedure INSERT (NEW_ITEM : in ITEM) is
  1551.        begin
  1552.           if FREE_LIST_EMPTY then
  1553.              raise TABLE_FULL;
  1554.           end if;
  1555.           --  remaining code for INSERT
  1556.        end INSERT;
  1557.  
  1558.        procedure RETRIEVE (FIRST_ITEM : out ITEM) is ... end;
  1559.  
  1560.     begin
  1561.        --  initialization of the table linkages
  1562.     end TABLE_MANAGER;
  1563.  
  1564.  
  1565.  
  1566. 7.6  Example of a Text Handling Package
  1567.  
  1568.  
  1569. This  example  illustrates  a simple text handling package.  The users only
  1570. have access to the visible part;  the implementation is hidden from them in
  1571. the private part and the package body (not shown).
  1572.  
  1573. From a user's point of view, a TEXT is a variable-length string.  Each text
  1574. object has a maximum length,  which  must  be  given  when  the  object  is
  1575. declared,  and  a  current  value, which is a string of some length between
  1576. zero and the maximum.  The maximum possible length of a text object  is  an
  1577. implementation-defined constant.
  1578.  
  1579.  
  1580.  
  1581.                                   7 - 23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590. The  package  defines first the necessary types, then functions that return
  1591. some characteristics of objects of the type, then the conversion  functions
  1592. between  texts  and  the predefined CHARACTER and STRING types, and finally
  1593. some of the standard operations on varying strings.   Most  operations  are
  1594. overloaded  on strings and characters as well as on the type TEXT, in order
  1595. to minimize the number of explicit conversions the user has to write.
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                   7 - 24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.     package TEXT_HANDLER is
  1657.        MAXIMUM : constant := SOME_VALUE;  --  implementation-defined
  1658.        subtype INDEX is INTEGER range 0 .. MAXIMUM;
  1659.  
  1660.        type TEXT(MAXIMUM_LENGTH : INDEX) is limited private;
  1661.  
  1662.        function LENGTH (T : TEXT) return INDEX;
  1663.        function VALUE  (T : TEXT) return STRING;
  1664.        function EMPTY  (T : TEXT) return BOOLEAN;
  1665.  
  1666.        function TO_TEXT (S : STRING;    MAX : INDEX) return TEXT;  --  maximum length MAX
  1667.        function TO_TEXT (C : CHARACTER; MAX : INDEX) return TEXT;
  1668.        function TO_TEXT (S : STRING)    return TEXT;  --  maximum length S'LENGTH
  1669.        function TO_TEXT (C : CHARACTER) return TEXT;
  1670.  
  1671.        function "&" (LEFT : TEXT;      RIGHT : TEXT)      return TEXT;
  1672.        function "&" (LEFT : TEXT;      RIGHT : STRING)    return TEXT;
  1673.        function "&" (LEFT : STRING;    RIGHT : TEXT)      return TEXT;
  1674.        function "&" (LEFT : TEXT;      RIGHT : CHARACTER) return TEXT;
  1675.        function "&" (LEFT : CHARACTER; RIGHT : TEXT)      return TEXT;
  1676.  
  1677.        function "="  (LEFT : TEXT; RIGHT : TEXT) return BOOLEAN;
  1678.        function "<"  (LEFT : TEXT; RIGHT : TEXT) return BOOLEAN;
  1679.        function "<=" (LEFT : TEXT; RIGHT : TEXT) return BOOLEAN;
  1680.        function ">"  (LEFT : TEXT; RIGHT : TEXT) return BOOLEAN;
  1681.        function ">=" (LEFT : TEXT; RIGHT : TEXT) return BOOLEAN;
  1682.  
  1683.        procedure SET (OBJECT : in out TEXT; VALUE : in TEXT);
  1684.        procedure SET (OBJECT : in out TEXT; VALUE : in STRING);
  1685.        procedure SET (OBJECT : in out TEXT; VALUE : in CHARACTER);
  1686.  
  1687.        procedure APPEND (TAIL : in TEXT;      TO : in out TEXT);
  1688.        procedure APPEND (TAIL : in STRING;    TO : in out TEXT);
  1689.        procedure APPEND (TAIL : in CHARACTER; TO : in out TEXT);
  1690.  
  1691.        procedure AMEND (OBJECT : in out TEXT; BY : in TEXT;      POSITION : in INDEX);
  1692.        procedure AMEND (OBJECT : in out TEXT; BY : in STRING;    POSITION : in INDEX);
  1693.        procedure AMEND (OBJECT : in out TEXT; BY : in CHARACTER; POSITION : in INDEX);
  1694.  
  1695.        --  amend replaces part of the object by the given text, string, or character
  1696.        --  starting at the given position in the object
  1697.  
  1698.        function LOCATE (FRAGMENT : TEXT;      WITHIN : TEXT) return INDEX;
  1699.        function LOCATE (FRAGMENT : STRING;    WITHIN : TEXT) return INDEX;
  1700.        function LOCATE (FRAGMENT : CHARACTER; WITHIN : TEXT) return INDEX;
  1701.  
  1702.        --  all return 0 if the fragment is not located
  1703.  
  1704.     private
  1705.        type TEXT(MAXIMUM_LENGTH : INDEX) is
  1706.           record
  1707.              POS   : INDEX := 0;
  1708.              VALUE : STRING(1 .. MAXIMUM_LENGTH);
  1709.           end record;
  1710.     end TEXT_HANDLER;
  1711.  
  1712.  
  1713.                                   7 - 25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722. Example of use of the text handling package:
  1723.  
  1724. A program opens an output file, whose name is supplied by the string  NAME.
  1725. This string has the form
  1726.  
  1727.     [DEVICE :] [FILENAME [.EXTENSION]]
  1728.  
  1729. There  are  standard  defaults  for  device,  filename, and extension.  The
  1730. user-supplied name is passed to EXPAND_FILE_NAME as a  parameter,  and  the
  1731. result is the expanded version, with any necessary defaults added.
  1732.  
  1733.     function EXPAND_FILE_NAME (NAME : STRING) return STRING is
  1734.        use TEXT_HANDLER;
  1735.  
  1736.        DEFAULT_DEVICE    : constant STRING := "SY:";
  1737.        DEFAULT_FILE_NAME : constant STRING := "RESULTS";
  1738.        DEFAULT_EXTENSION : constant STRING := ".DAT";
  1739.  
  1740.        MAXIMUM_FILE_NAME_LENGTH : constant INDEX := SOME_APPROPRIATE_VALUE;
  1741.        FILE_NAME : TEXT(MAXIMUM_FILE_NAME_LENGTH);
  1742.  
  1743.     begin
  1744.  
  1745.        SET(FILE_NAME, NAME);
  1746.  
  1747.        if EMPTY(FILE_NAME) then
  1748.           SET(FILE_NAME, DEFAULT_FILE_NAME);
  1749.        end if;
  1750.  
  1751.        if LOCATE(':', FILE_NAME) = 0 then
  1752.           SET(FILE_NAME, DEFAULT_DEVICE & FILE_NAME);
  1753.        end if;
  1754.  
  1755.        if LOCATE('.', FILE_NAME) = 0 then
  1756.           APPEND(DEFAULT_EXTENSION, TO => FILE_NAME);
  1757.        end if;
  1758.  
  1759.        return VALUE(FILE_NAME);
  1760.  
  1761.     end EXPAND_FILE_NAME;
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                   7 - 26
  1780.  
  1781.  
  1782.  
  1783.  
  1784.