-- $Date: 2004/03/04 05:04:57 $
-- $Revision: 1.5 $
-- $Author: jcrocholl $

with Real_Numbers; use Real_Numbers;
with Glyphs; use Glyphs;

with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;

package Choices is

   type Choice(Regular_Size, Special_Size : Natural) is limited private;
   type Choice_Access is access Choice;

   Default_Regular_Size : constant := 64;
   Default_Special_Size : constant := 16;

   -- Create a choice from scratch.
   function Create
     (Regular_Size : in Natural := Default_Regular_Size;
      Special_Size : in Natural := Default_Special_Size)
     return Choice_Access-- The newly created choice.

   --------------------------------
   -- Regular and special accessors
   --------------------------------

   -- Add a regular glyph to a choice.
   procedure Add_Regular
     (This : access Choice;    -- Add to this choice.
      Add  : in Glyph_Access); -- Add this glyph.

   -- Get a specific glyph from a choice.
   function Get_Regular
     (This  : access Choice-- Get from this choice.
      Index : in Positive)   -- Index of the glyph.
     return Glyph_Access;    -- The glyph that has been chosen.

   -- Add a special glyph to a choice.
   procedure Add_Special
     (This : access Choice;    -- Add to this choice.
      Add  : in Glyph_Access); -- Add this glyph.

   -- Get a specific glyph from a choice.
   function Get_Special
     (This  : access Choice-- Get from this choice.
      Index : in Positive)   -- Index of the glyph.
     return Glyph_Access;    -- The glyph that has been chosen.

   ------------------
   -- Random choosing
   ------------------

   subtype Percent is Real range 0.0 .. 100.0;

   No_Glyphs_To_Choose_From : exception;

   -- Randomly choose a glyph from a choice.
   -- Raises No_Glyphs_To_Choose_From if choice is empty.
   function Choose
     (This    : access Choice-- Choose from this choice.
      Special : in Percent)    -- How many special glyphs?
     return Glyph_Access;      -- The glyph that has been chosen.

private

   type Glyph_Array is array(Positive range <>) of Glyph_Access;

   type Choice(Regular_Size, Special_Size : Natural) is
      limited record
         -- Flexible size storage for glyphs.
         Regular : Glyph_Array(1 .. Regular_Size);
         Special : Glyph_Array(1 .. Special_Size);
         -- How many glyphs are actually available?
         Regular_Count : Natural := 0;
         Special_Count : Natural := 0;
         -- Random generator.
         Gen : Generator;
      end record;

end Choices;