home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!mips!darwin.sura.net!jvnc.net!netnews.upenn.edu!uofs!guinness.cs.uofs.edu!beidler
- From: beidler@guinness.cs.uofs.edu (Jack Beidler)
- Newsgroups: comp.lang.ada
- Subject: Instanciation
- Message-ID: <10964@platypus.uofs.uofs.edu>
- Date: 21 Aug 92 18:26:04 GMT
- References: <1992Aug16.160339.27573@evb.com>
- Sender: news@uofs.uofs.edu
- Distribution: usa
- Organization: Department of Computing Sciences
- Lines: 58
- Nntp-Posting-Host: guinness.cs.uofs.edu
-
- With regard to :
-
- >I've got a package which I'm currently coding which uses a static data
- >structure (an array of records to be precise). Now, this package is an
- >ADT with a private data type.
- >
- >I want to be able to modify the size of this array from within a client
- >program at runtime.
- >
- >Can anyone suggest how I might be able to go about this?
- >
- >Thanks.
- >
- >Cheers,
- >%Ben%
-
- The obvious choice is make your structured object available as a
- private type with a discriminant, as in
-
- generic
- type Object_Type is private ;
- package Stack_Pt_Pt is
-
- type Stack_Type (Size : positive := 20) is private ;
-
- ....
-
- and use the discriminat to determine the size of the stack
-
- private
-
- type stack_array is array ( positive range <>) of Object_Type;
-
- type Stack_Type (Size : positive := 20) is
- record
- Top : natural := 0 ;
- Actual: Stack_Array (1 .. Size) ;
- end record ;
-
- Once the package is instantiated,
-
- Int_Stack is new Stack_Pt_Pt (integer) ;
- use Int_Stack ;
-
- stacks of various sizes may be declared,
-
- Short_Stack : Stack_Type (4) ;
- Big_Stack : Stack_Type (1000) ;
- -
- --
- +------------------------------------------------------------------+
- | John (Jack) Beidler |
- | Prof. of Computer Science Internet: BEIDLER@JAGUAR.UOFS.ED |
- | University of Scranton beidler@guinness.cs.uofs.edu|
- | Scranton, PA 18510 Bitnet : BEIDLER@SCRANTON |
- | |
- | Phone: (717) 941-7446 FAX: (717) 941-4250 |
- +------------------------------------------------------------------+
-