1. -- 
  2. -- Uwe R. Zimmer, Australia 2015 
  3. -- 
  4.  
  5. package body Id_Dispenser is 
  6.  
  7.    protected Dispenser is 
  8.  
  9.       procedure Draw_Id (Id : out Element); 
  10.  
  11.    private 
  12.  
  13.       Next_Id       : Element := Element'First; 
  14.       IDs_exhausted : Boolean := False; 
  15.  
  16.    end Dispenser; 
  17.  
  18.    protected body Dispenser is 
  19.  
  20.       procedure Draw_Id (Id : out Element) is 
  21.  
  22.       begin 
  23.          if IDs_exhausted then 
  24.             raise Out_Of_Ids; 
  25.          else 
  26.             Id := Next_Id; 
  27.             if Next_Id = Element'Last then 
  28.                IDs_exhausted := True; 
  29.             else 
  30.                Next_Id := Element'Succ (Next_Id); 
  31.             end if; 
  32.          end if; 
  33.       end Draw_Id; 
  34.  
  35.    end Dispenser; 
  36.  
  37.    function Draw_Id return Element is 
  38.  
  39.       Unique_Id : Element := Element'Invalid_Value; 
  40.  
  41.    begin 
  42.       Dispenser.Draw_Id (Id => Unique_Id); 
  43.       return Unique_Id; 
  44.    end Draw_Id; 
  45.  
  46. end Id_Dispenser;