comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <dstanbro@bigpond.net.au>
Subject: Re: How do you instantiate a private package?
Date: Tue, 26 Feb 2002 21:33:20 GMT
Date: 2002-02-26T21:33:20+00:00	[thread overview]
Message-ID: <dstanbro-0260B7.08290327022002@mec2.bigpond.net.au> (raw)
In-Reply-To: 20020226155831.07840.00000639@mb-mn.aol.com

Joshua Shriver wrote:

> I've created a package called direct_file_stuff in my ads and adb and
> instantiate a direct_io package called dfs_pkg.
> 
> Now that I have this package created, how do I use it in an application?
> 
> Here is my .ads
> 
> with direct_io;
> 
> generic 
>         type item is private;
> 
> package dfs is
>         package dfs_pkg is new direct_io(item);
>         use dfs_pkg;
> 
> procedure switch_file_lines(source_file: in string; line1: integer; line2:
> integer);
> 
> procedure swap_head_tail(source_file: in string; lines: integer);
> 
> procedure get_middle(source_file: in string; found: out item);
> 
> end dfs;
> 
> I've implemented this functions in dfs.adb but now I can't figure out how to
> use this procedure in a main application. How is this done?


with dfs;

procedure main is

   package my_dfs is new dfs (integer); -- or whatever type

   file : mydfs.dfs_pkg.file_type;
       -- note that the use clause inside the dfs generic only 
       -- extends to the end of the generic spec (or body, i can't
       -- remember). Anyway it doesn't extend outside.
       -- You could have another use clause here...


   use mydfs.dfs_pkg;
       -- replicates the use clause in the generic spec, but in 
       -- the current scope

begin

   open (file, mydfs.dfs_pkg.in_file, "wow");

end;


Mind you I think a better organisation is to have most generic
instantiations in a separate compilation unit (at the library level).


   with dfs;
   with My_Package_With_Type_Defs; use My_Package_With_Type_Defs;
 
   package mydfs is new dfs (My_Special_Type);



Dale



  reply	other threads:[~2002-02-26 21:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-26 20:58 How do you instantiate a private package? Joshua Shriver
2002-02-26 21:33 ` Dale Stanbrough [this message]
2002-02-27  9:13   ` Joshua Shriver
replies disabled

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