with Type_Definitions;
use Type_Definitions;
with String_Pkg;
use String_Pkg;
with Text_Io;
use Text_Io;


package Rtm_List_Package is

    --| Overview
    --|      The RTM_List_Package is a subset of the Lists package from Inter-
    --| metrics in Cambridge.  It is tailored explicitly for the Run_Time_Monitor.
    --| The type of the list objects is Program_Unit_Unique_Identifier, which is
    --| declared in Type_Definitions.
    --| The procedures and functions allow the RTM to create a list, add to a
    --| list, delete an item from the list, read and replace an item after
    --| incrementing the Task_Type_Activation_Number, and check for an empty
    --| list.

    --| N/A: Effects, Requires, Modifies, Raises


    --  Mary Koppes  Intermetrics Inc, Huntington Beach,Ca  11-June-85


    --   TYPES


    type List is private;



    ------------------------------------------------------------------------------

    function Create --| Return an empty list

                return List;


    -------------------------------------------------------------------------------


    procedure Add ( --| Add an element to the list

                   Element : in Program_Unit_Unique_Identifier;
                   --| The Unit_ID being added to the list

                   To_List : in out List --| List being added to

                   );

    --| Effects
    --| Adds  an element onto to the end of the list, To_List.  If
    --| To_List is empty then this may change the value of Element.

    --| Modifies
    --| The "NEXT" field of To_List;


    -------------------------------------------------------------------------------


    procedure Delete_Head ( --|  Remove the Head element

                           The_List : in out
                           List --|  The list whose head is being removed

                           );

    --| Raises
    --| Empty_List

    --| Effects
    --| This will return the space occupied by the first element in the list
    --| to the heap.  If sharing exists between lists, this procedure could
    --| leave a dangling reference.  If The_List is empty, EmptyList is
    --| raised.


    -------------------------------------------------------------------------------



    procedure Delete ( --| Delete an element from the list

                      Element : in
                      Program_Unit_Unique_Identifier;     --| Elt to be deleted

                      From_List : in out List --| List to delete from

                      );

    --| Raises
    --| Item_Not_Present

    --| Effects
    --| This procedure walks down the list, From_List, and removes the first
    --| element equal to Element.  If there is not an element equal to
    --| Element, ItemNotPresent is raised.

    --| Modifies
    --| Returns the storage being occupied by the deleted element.


    -------------------------------------------------------------------------------


    procedure Replace_Value
                 ( --| Finds element and increments the Task number

                  New_Element : in out Program_Unit_Unique_Identifier;

                  New_List : in out List);


    --| Effects
    --| Replace_Value walks through New_List searching for New_Element.
    --| If New_Element is found, the Task_Type_Activation_Number is incremented
    --| in the list element and New_Element is assigned this number too.
    --| The Element is replaced in the list.

    --| Modifies
    --| The specified element.Task_Type_Activation_Number is incremented

    -------------------------------------------------------------------------------



    function Is_In_List ( --| Checks for the presence of Element in The_List.

                         The_List : in List;

                         Element : in Program_Unit_Unique_Identifier

                         ) return Boolean;


    --| Effects
    --| Walks down the list The_List looking for an element whose value is
    --| Element.


    -------------------------------------------------------------------------------


    function Is_Empty ( --| Checks for an empty list

                       The_List : in List) return Boolean;



    ------------------------------------------------------------------------------


    function Equal ( --| Compares X to Y and returns TRUE if they are equal

                    X, Y : in Program_Unit_Unique_Identifier) return Boolean;


    -------------------------------------------------------------------------------


private
    type List_Element;
    type List is access List_Element;
    type List_Element is
        record
            Info : Program_Unit_Unique_Identifier;
            Next_Element : List;
        end record;


end Rtm_List_Package;
