with Ada.Containers;

with Bookstore.Books;

package Bookstore.Cart_Items is
5
   type Quantity is new Natural;

   -----------------------------------------------------------------------
   -- Shopping_Cart_Item defines an item a client choose.               --
10   --                                                                   --
   -- In our example an item can only be of type Book. To get more      --
   --  choices (see comments in 'Bookstore.Books'), the 'Item' field    --
   --  (see the private part here) should be of the root type, and the  --
   --  list and hashed map should contain access to the root type.      --
15   -----------------------------------------------------------------------

   type Shopping_Cart_Item is tagged private;

   type Cart_Item_Array is array (Natural range <>) of Shopping_Cart_Item;
20
   function Create_Shopping_Cart_Item
     (Item : in Books.Book) return Shopping_Cart_Item;

   procedure Set_Quantity (Item         : in out Shopping_Cart_Item;
25                           New_Quantity : in     Quantity);

   procedure Increment_Quantity (Item : in out Shopping_Cart_Item);

   -- may raise Constraint_Error
30   procedure Decrement_Quantity (Item : in out Shopping_Cart_Item);

   function Get_Item (Item : in Shopping_Cart_Item) return Books.Book;

   function Get_Quantity (Item : in Shopping_Cart_Item) return Quantity;
35
   ----------------------------------------------------------------
   -- The following functions are needed for the hashed map. See --
   --  'Bookstore.Cart_Items.Hashed_Maps'                        --
   ----------------------------------------------------------------
40
   function Shop_Cart_Item_Hash
     (Key : in Books.Id_Str) return Ada.Containers.Hash_Type;

   function Equivalent_Keys (Left, Right : in Books.Id_Str) return Boolean;
45
private

   type Shopping_Cart_Item is tagged
      record
50         Item : Books.Book;
         Number_Of_Items : Quantity := 0;
      end record;

end Bookstore.Cart_Items;
55
top