international_standard_book_numbers.ads


------------------------------------------------------------------------------
--
--  package International_Standard_Book_Numbers (spec)
--
--  International Standard Book Numbers.
--
--  Source: "Find fem fejl", Kjeld Bagger Laursen, in Hovedområdet 1/1998,
--          Københavns Universitets Naturvidenskabelige Fakultet.
--
------------------------------------------------------------------------------
--  Update information:
--
--  1998.02.06 (Jacob Sparre Andersen)
--    Written.
--
--  (Insert additional update information above this line.)
------------------------------------------------------------------------------

package International_Standard_Book_Numbers is

   ---------------------------------------------------------------------------
   --  type ISBN:

   type ISBN is private;

   ---------------------------------------------------------------------------
   --  function Valid:
   --
   --  Checks if an object of type ISBN has a valid value.
   --
   --  Exceptions:
   --    (none)

   function Valid (Item : in ISBN) return Boolean;

   ---------------------------------------------------------------------------
   --  function Image:
   --
   --  Converts an object of type ISBN to a string.
   --
   --  Exceptions:
   --    (none)

   function Image (Item : in ISBN) return String;

   ---------------------------------------------------------------------------
   --  function Value:
   --
   --  Converts a string to an object of type ISBN.
   --
   --  Exceptions:
   --    Constraint_Error - if the string does not represent a valid ISBN.

   function Value (Item : in String) return ISBN;

   ---------------------------------------------------------------------------
   --  function To_ISBN:
   --
   --  Composes an ISBN based on country, publisher, and book index.
   --
   --  Exceptions:
   --    Constraint_Error - if one of the indices are longer than there is
   --                       space for.

   function To_ISBN (Country, Publisher, Book         : in Natural;
                     Country_Length, Publisher_Length : in Positive)
     return ISBN;

   ---------------------------------------------------------------------------
   --  procedure Split:
   --
   --  Extracts country, publisher, and book index from an ISBN.
   --
   --  Exceptions:
   --    (none)

   procedure Split (Item      : in     ISBN;
                    Country   :    out Natural;
                    Publisher :    out Natural;
                    Book      :    out Natural);

   ---------------------------------------------------------------------------

private

   ---------------------------------------------------------------------------
   --  type Base_11_Digits:

   type Base_11_Digits is mod 11;

   ---------------------------------------------------------------------------
   --  Base_11_Digit_Image:

   Base_11_Digit_Image : constant array (Base_11_Digits) of Character :=
     ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'X');

   ---------------------------------------------------------------------------
   --  Base_11_Digit_Value:

   Base_11_Digit_Value : constant array (Character) of Base_11_Digits :=
                           ('0'    => 0,
                            '1'    => 1,
                            '2'    => 2,
                            '3'    =>  3,
                            '4'    =>  4,
                            '5'    =>  5,
                            '6'    =>  6,
                            '7'    =>  7,
                            '8'    =>  8,
                            '9'    =>  9,
                            'X'    => 10,
                            others => 10); --  Error!

   ---------------------------------------------------------------------------
   --  type Digit_Array:

   type Digit_Array is array (Base_11_Digits range 1 .. 10) of Base_11_Digits;

   ---------------------------------------------------------------------------
   --  subtype Separator_Positions:

   subtype Separator_Positions is Positive range 1 .. 8;

   ---------------------------------------------------------------------------
   --  type ISBN:

   type ISBN is
      record
         Number    : Digit_Array;
         Country   : Separator_Positions;
         Publisher : Separator_Positions;
      end record;

   ---------------------------------------------------------------------------

end International_Standard_Book_Numbers;

Typeset with Ada_To_HTML (Jacob and Jesper)