comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Generic Package
Date: Wed, 03 Dec 2003 10:31:38 +0100
Date: 2003-12-03T10:31:38+01:00	[thread overview]
Message-ID: <o0arsvk5jp93s54j6b19gdpup7afim5m7h@4ax.com> (raw)
In-Reply-To: fc116fae.0312021515.7078181a@posting.google.com

On 2 Dec 2003 15:15:45 -0800, ratsonjaniv@hotmail.com (Mr. J.) wrote:

>Hi,
>I have this code :
>
>*********************************************************************
>generic
>    type Language is array (Positive range<>) of Character;
>    type States is array (Positive range <>) of Integer;
>
>    package Automat_Producer is
>
>    type StatesFunctions is array(Character,Integer) of Integer;
>
>    procedure Init(Q0:Integer);
>    procedure Change_State(C:Character);
>    function Is_Final_State return Boolean;
>
>private
>
>    Statesarr: Statesfunctions;
>    Currentstate : Integer;
>    FinalStates : States;
>
>end Automat_Producer;
>*********************************************************************
>
>I have few Questions:
>
>How and when do I set the sizes of the generic types arrays?

Upon instantiation.

>The compiler need to know the size of the FinalStates:States member, I
>will know it only during run-time, How do I do it?
>I think I need somthing similiar to C++'s Constructor.

Not necessariliy. You have to constrain the variable States. There are
many ways to do what you need.

For example

1. you can pass the array bounds as the parameters:

generic
   Number_Of_Final_States : Positive;
   type States is array (Positive range <>) of Integer;
   ... -- Other generic formal parameters
package Automat_Producer is
   ... -- Public interface
private
   FinalStates : States (1..Number_Of_Final_States);
   ... -- Other private things
end Automat_Producer;

So you could instantiate Automat_Producer with a desired number of
states:

package My_Producer is
   new Automat_Producer (Number_Of_Final_States => 10, ...);

2. you can pass the set of final states as a parameter:

generic
   type States is array (Positive range <>) of Integer;
   FinalStates : States;
   ... -- Other generic formal parameters
package Automat_Producer is
   ... -- Public interface
private
   -- Do not need a list of final states it is a parameter now
   ... -- Other private things
end Automat_Producer;

3. you could make the states an enumeration type with a domain set
separated into final and non-final states:

generic   
   type State is (<>);
   First_Final_State : State;
   Last_Final_State : State;
   ... -- Other generic formal parameters
package Automat_Producer is
   ... -- Public interface
private
   -- Do not need a list of final states, a state is tested
   -- as if X in First_Final_State..Last_Final_State then
   --
   ... -- Other private things
end Automat_Producer;

4. you could provide a tester:

generic   
   type State is (<>);
   with function Is_Final (This : State) return Boolean;
   ... -- Other generic formal parameters
package Automat_Producer is
   ... -- Public interface
private
   -- Do not need a list of final states, a state is tested
   -- using Is_Final.
   ... -- Other private things
end Automat_Producer;

--
Regards,
Dmitry Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2003-12-03  9:31 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-02 23:15 Generic Package Mr. J.
2003-12-03  9:31 ` Dmitry A. Kazakov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-04-25 22:15 andrew.carroll
2007-04-26  0:07 ` Jeffrey R. Carter
2007-04-26  7:46   ` Markus E Leypold
2007-04-26  6:02 ` Martin Krischik
2007-04-26  7:57 ` Dmitry A. Kazakov
2007-04-26 15:31 ` andrew.carroll
2007-04-26 16:07   ` Georg Bauhaus
2007-04-26 19:40     ` andrew.carroll
2007-04-26 20:01       ` Georg Bauhaus
2007-04-26 18:54   ` Dmitry A. Kazakov
2007-04-26 21:52     ` Simon Wright
2007-04-27  9:00       ` Dmitry A. Kazakov
2007-04-27 11:11         ` Georg Bauhaus
2007-04-27 12:06           ` Dmitry A. Kazakov
2007-04-27 12:52             ` Markus E Leypold
2007-04-27 14:10             ` Georg Bauhaus
2007-04-27 14:16               ` Dmitry A. Kazakov
2007-04-27 21:44                 ` Georg Bauhaus
2007-04-28  7:38                   ` Dmitry A. Kazakov
2007-04-28 17:50                     ` Simon Wright
2007-04-28 21:04                     ` Ray Blaak
2007-04-29 16:33                       ` Markus E Leypold
2007-04-27 19:44             ` Simon Wright
2007-04-27 20:34               ` Dmitry A. Kazakov
2007-04-27 21:16                 ` Simon Wright
2007-04-28  7:36                   ` Dmitry A. Kazakov
2007-04-27 11:43         ` Markus E Leypold
2007-04-28 17:35           ` Dmitry A. Kazakov
2007-04-28 23:06             ` Georg Bauhaus
2007-04-29  8:19               ` Dmitry A. Kazakov
2007-04-29 15:10                 ` (see below)
2007-04-29 17:48                   ` Dmitry A. Kazakov
2007-04-29 22:36                     ` (see below)
2007-04-30  6:58                       ` Dmitry A. Kazakov
2007-04-30  9:59                         ` Markus E Leypold
2007-04-30 10:01                         ` Markus E Leypold
2007-04-30 10:36                         ` Georg Bauhaus
2007-04-30 10:40                           ` Georg Bauhaus
2007-04-30 12:14                           ` Dmitry A. Kazakov
2007-04-30 14:57                         ` (see below)
2007-04-30 10:30                 ` Georg Bauhaus
2007-04-30 12:16                   ` Dmitry A. Kazakov
2007-04-30 14:48                     ` Georg Bauhaus
2007-04-30 16:29                       ` Dmitry A. Kazakov
2007-04-30 17:24                         ` Georg Bauhaus
2007-04-30 18:54                           ` Dmitry A. Kazakov
2007-04-30 19:29                         ` Simon Wright
2007-04-30 20:04                           ` Dmitry A. Kazakov
2007-05-01  0:11                             ` Markus E Leypold
2007-05-01  9:02                             ` Georg Bauhaus
2007-05-01 10:19                               ` Dmitry A. Kazakov
2007-05-01 13:42                                 ` Georg Bauhaus
2007-05-01 17:16                                   ` Dmitry A. Kazakov
2007-05-01 19:14                                     ` Randy Brukardt
2007-05-01 20:14                                       ` Dmitry A. Kazakov
2007-05-02  7:52                                         ` Markus E Leypold
2007-05-02  8:06                                       ` Markus E Leypold
2007-05-03  0:37                                         ` Randy Brukardt
2007-05-03  8:36                                           ` Markus E Leypold
2007-05-03 23:16                                             ` Randy Brukardt
2007-05-04  0:15                                               ` Markus E Leypold
2007-05-01 21:41                                     ` Georg Bauhaus
2007-05-02  6:57                                       ` Ray Blaak
2007-05-02  8:22                                         ` Markus E Leypold
2007-05-02  8:07                                       ` Markus E Leypold
2007-05-02 10:29                                       ` Dmitry A. Kazakov
2007-05-02 11:48                                         ` Georg Bauhaus
2007-05-02 11:50                                           ` Georg Bauhaus
2007-05-02 13:12                                           ` Dmitry A. Kazakov
2007-05-02 14:21                                             ` Markus E Leypold
2007-05-03 18:27                                             ` Georg Bauhaus
2007-05-03 19:07                                               ` Dmitry A. Kazakov
2007-05-03 19:49                                                 ` Markus E Leypold
2007-04-29 16:26             ` Markus E Leypold
2007-04-26 21:50   ` Simon Wright
2007-04-27  4:45   ` Jeffrey R. Carter
2007-04-27  7:45     ` Martin Krischik
2007-04-27 22:54       ` Georg Bauhaus
2007-04-30 20:13         ` Matthew Heaney
2007-04-26 20:48 ` andrew.carroll
2003-12-02 23:13 generic package Ratson Janiv
2003-12-03 17:39 ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox