File : generic_list_implementation.ads



with Matchs;

generic
   type Base (<>) is abstract tagged limited private;
   type S    (<>) is abstract new Base with private;
   type T    (<>) is abstract new S with private;
   type T_Class   is access all T'Class;
   type List (<>) is limited private;
   type Iterator  is private;
   with function  Is_Empty     (Head : in     List)     return Boolean;
   with procedure Add_Front    (Head : in out List; Elem : in T_Class);
   with procedure Add_After_Element (Iter : in    Iterator;
                                     Elem : in    T_Class);
   with procedure Delete_Front (Head : in out List);
   with procedure Delete_After_Element (Iter : in    Iterator);
   with function  Get_Iterator (Head : in     List)     return Iterator;
   with function  Is_Done      (Iter : in     Iterator) return Boolean;
   with function  Get          (Iter : in     Iterator) return T_Class;
   with procedure Advance      (Iter : in out Iterator);
   with procedure Set_Done     (Iter : in out Iterator);
package Generic_List_Implementation is
   --  Adds before the element with matches the condition.
   --  If no match occurs the element is added at the end.
   generic
      with function Is_Match (Elem : in Base) return Boolean;
   procedure Add_Before (Head : in out List;
                         Elem : in     T_Class);
   
   --  Adds after the element with matches the condition.
   --  If no match occurs the element is added at the end.
   generic
      with function Is_Match (Elem : in Base) return Boolean;
   procedure Add_After (Head : in out List;
                        Elem : in     T_Class);
   
   --  Find a specific element -- null if nothing found.
   generic
      with function Is_Match (Curr : in Iterator) return Matchs.Match_Type;
   function Find_First (Head : in List) return Iterator;
   
   --  Find the next specific element -- null if nothing found.
   generic
      with function Is_Match (Curr : in Iterator) return Matchs.Match_Type;
   function Find_Next (Iter : in Iterator) return Iterator;
   
   --  Basic generic internal iterator
   generic
      with function Is_Match (Elem : in     Base) return Matchs.Match_Type;
      with procedure On_Item (Elem : in out Base;
                              Done :    out Boolean);
   procedure For_Matches (Head : in     List);
   
   --  More efficient implementation if matching is not necessary.
   generic
      with procedure On_Item (Elem : in out Base;
                              Done :    out Boolean);
   procedure For_Each (Head : in     List);
   
   --  Delete all matching elements from the list
   --  (not the elements themselfs!)
   generic
      with function Is_Match (Elem : in Base) return Matchs.Match_Type;
   procedure Delete_Matches (Head : in out List);
   
   --  Delete the first element from the list
   --  (not the elements themself!)
   generic
      with function Is_Match (Elem : in Base) return Boolean;
   procedure Delete_Match (Head : in out List);
end Generic_List_Implementation;