comp.lang.ada
 help / color / mirror / Atom feed
* How do you instantiate a private package?
@ 2002-02-26 20:58 Joshua Shriver
  2002-02-26 21:33 ` Dale Stanbrough
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Shriver @ 2002-02-26 20:58 UTC (permalink / raw)


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?

Sincerely,
Joshua Shriver
jshriver@mix.wvu.edu



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do you instantiate a private package?
  2002-02-26 20:58 How do you instantiate a private package? Joshua Shriver
@ 2002-02-26 21:33 ` Dale Stanbrough
  2002-02-27  9:13   ` Joshua Shriver
  0 siblings, 1 reply; 3+ messages in thread
From: Dale Stanbrough @ 2002-02-26 21:33 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do you instantiate a private package?
  2002-02-26 21:33 ` Dale Stanbrough
@ 2002-02-27  9:13   ` Joshua Shriver
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Shriver @ 2002-02-27  9:13 UTC (permalink / raw)


package my_dfs is new dfs(item);

I get an error because the type I need/use is type item is private, which is
declared in my package spec. How do I use type item? in that?




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-27  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-26 20:58 How do you instantiate a private package? Joshua Shriver
2002-02-26 21:33 ` Dale Stanbrough
2002-02-27  9:13   ` Joshua Shriver

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