--
-- @filename dict_tda.ads
-- @author Julien Burdy & Vincent Decorges
-- @date 22.4.02
-- @brief A dictionary abstract data type implemantation
--
-- History  :
-- Date     Modification               Author
--
with Ada.Text_IO; use Ada.Text_IO;

package Dict_TDA is

   type Dict_Type is private;

   --An empty dictionary
   Empty_Dict : constant Dict_Type;

   --
   -- Name    : Insert
   -- Purpose : Insert an entry in the dictonary
   --
   -- in out  : L : A dictionary
   -- in      : Key : Name of a key
   -- in      : Value : Value asociate with the key
   --
   procedure Insert (L : in out Dict_Type; Key, Value : in String);

   --
   -- Name    : Delete
   -- Purpose : Delete a key and its value of the dictionary
   --           Raise Key_Error, if the key does not exist
   --
   -- in  out : L : A dictionary
   -- in      : Key : Name of a key
   --
   procedure Delete (L : in out Dict_Type; Key : in String);

   --
   -- Name    : Update
   -- Purpose : Update the value of a key
   --           if the key does not exist, insert the key
   --           in the dictionary
   --
   -- in out  : L : A dictionary
   -- in      : Key : Name of a key
   -- in      : Value : A value
   --
   procedure Update (L : in out Dict_Type; Key, Value : in String);

   --
   -- Name    : Empty
   -- Purpose : Empty the dictionary
   --
   -- in out  : L : A dictionary
   -- return  : Dict_Type
   --
   procedure Empty (L : in out Dict_Type);

   --
   -- Name    : Is_Empty
   -- Purpose : Return true if the dictionary is empty
   --
   -- in out  : L : A dictionary
   -- return  : Boolean
   --
   function Is_Empty (L : in Dict_Type) return Boolean;

   --
   -- Name    : Exist
   -- Purpose : Return true if a key exist in the dictionary
   --
   -- in      : L : A dictionary
   -- in      : Key : Name of a key
   -- return  : Boolean
   --
   function Exist (L : Dict_Type; Key : String) return Boolean;

   --
   -- Name    : Exist
   -- Purpose : Return the value of a key
   --           If the key don't exist return a null string ("")
   --
   -- in      : L : A dictionary
   -- in      : Key : Name of a key
   -- return  : String
   --
   function Value_Of (L : Dict_Type; Key : String) return String;

   --
   -- Name    : Copy_Of
   -- Purpose : Return a copy of L
   --
   -- in      : L : A dictionary
   -- return  : Dict_Type
   --
   function Copy_Of (L : Dict_Type) return Dict_Type;

   --
   -- Name    : Put
   -- Purpose : Put the dictionary
   --
   -- in      : L : A dictionary
   --
   procedure Put (L : in Dict_Type; Target : in File_Type := Standard_Output);

   --The key doesn't exist
   Key_Error : exception;

   generic
      --Operation to do for each key
      with procedure Treat ( Key : in String; Value : in String);

   --
   -- Name    : Run_Through
   -- Purpose : Run through the dict and call treat for each Key
   --
   -- in      : L : A dictionary
   --
   procedure Run_Through ( L : in Dict_Type);

private
   type String_Access is access String;

   type Attribut_Type;
   type Dict_Type is access Attribut_Type;
   type Attribut_Type is
      record
         Key   : String_Access;
         Value : String_Access;
         Next  : Dict_Type;
      end record;

   Empty_Dict : constant Dict_Type := Null;
end Dict_TDA;
