comp.lang.ada
 help / color / mirror / Atom feed
* Assignment of limited private types...
@ 1995-01-26 16:37 Steve McGowan
  1995-01-30 18:50 ` Theodore E. Dennison
  0 siblings, 1 reply; 6+ messages in thread
From: Steve McGowan @ 1995-01-26 16:37 UTC (permalink / raw)


I'd like to pass in a 'file_type' identifier into a task, make a local
copy of this identifier within the task, and then write text to this
file stream inside the task.

But I cannot do this since 'file_type' is limited private.

Any ideas how I can pass in this identifier, and to write to it
locally?

I want to do something like..

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

task body Run_Full_Experiment_TASK is
.
local_summary_stream : file_type;
.
begin

    accept start(summary_stream : in file_type) do
	local_summary_stream:=summary_stream;
    end start;

    -- ...then use 'local_summary_stream' to write my output.
    --
end Run_Full_Experiment_TASK;

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


Thanks.

--Steve.



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

		I think we're in for a bad spell of wether.

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



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

* Re: Assignment of limited private types...
  1995-01-26 16:37 Assignment of limited private types Steve McGowan
@ 1995-01-30 18:50 ` Theodore E. Dennison
  1995-01-31  1:05   ` Henry Baker
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Theodore E. Dennison @ 1995-01-30 18:50 UTC (permalink / raw)


stevem@dcs.gla.ac.uk (Steve McGowan) wrote:
>
> I'd like to pass in a 'file_type' identifier into a task, make a local
> copy of this identifier within the task, and then write text to this
> file stream inside the task.
> 
> But I cannot do this since 'file_type' is limited private.
> 
> Any ideas how I can pass in this identifier, and to write to it
> locally?
> 

The reason people make types "limited private" is so users CAN'T 
make local copies of the objects. If the designer wanted you to
be able to make copies of file_type objects, she would have made
the type "private".

If for some reason you HAVE to make a copy, you could use an 
unchecked_conversion, but DO NOT DO THIS! Odds are very high that 
you will not get the results you desire. Try something else.

T.E.D.



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

* Re: Assignment of limited private types...
  1995-01-30 18:50 ` Theodore E. Dennison
@ 1995-01-31  1:05   ` Henry Baker
  1995-02-01 12:29   ` Robert Dewar
  1995-02-07  2:23   ` Adam Beneschan
  2 siblings, 0 replies; 6+ messages in thread
From: Henry Baker @ 1995-01-31  1:05 UTC (permalink / raw)


In article <3gjce1$1he@theopolis.orl.mmc.com>, "Theodore E. Dennison"
<dennison@escmail.mmc.orl.com> wrote:

> stevem@dcs.gla.ac.uk (Steve McGowan) wrote:
> >
> > I'd like to pass in a 'file_type' identifier into a task, make a local
> > copy of this identifier within the task, and then write text to this
> > file stream inside the task.
> > But I cannot do this since 'file_type' is limited private.
> > Any ideas how I can pass in this identifier, and to write to it
> > locally?
> 
> The reason people make types "limited private" is so users CAN'T 
> make local copies of the objects. If the designer wanted you to
> be able to make copies of file_type objects, she would have made
> the type "private".

That may have been the original intent, but that isn't what Ada ended
up with.  What you describe requires a _read_ barrier, but Ada only
gives you a _write_ barrier.  Limited private types can't be assigned
to, but can easily be read from, and 'copies' made.

Put your WWW browser onto the following URL's for more background on limited
private types:

ftp://ftp.netcom.com/pub/hb/hbaker/LimitedRoots.html (or .ps.Z)
ftp://ftp.netcom.com/pub/hb/hbaker/LimitedRobbery.html (or .ps.Z)
ftp://ftp.netcom.com/pub/hb/hbaker/LPprogram.html (or .ps.Z)



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

* Re: Assignment of limited private types...
@ 1995-01-31  2:35 tmoran
  0 siblings, 0 replies; 6+ messages in thread
From: tmoran @ 1995-01-31  2:35 UTC (permalink / raw)


stevem@dcs.gla.ac.uk (Steve McGowan) wrote:
>
> I'd like to pass in a 'file_type' identifier into a task, make a local
> copy of this identifier within the task, and then write text to this
> file stream inside the task.
  If you did make local copies, what behavior would you expect when two
different tasks, using two copies of the file handle, simultaneously
wrote to the file?
  If you don't really want multiple copies of the file handle, how
about passing in the file name and letting the task open the file
locally, instead of passing in the file handle.
  If you do want multiple tasks to write to the file, but don't want
the bits randomly intermingled, you need to synchronize your tasks.
In that case, how about having a third task do all the IO on the
file, using Accepts to accept (one at a time) requests for IO from
the other tasks.
  In general, Ada rules are not arbitrary, and not there for the
convenience of the compiler writer, or to make your life hard.  If
you can't do something straightforwardly in Ada, it's usually
productive to think twice about whether the approach you're
taking is really the best one.



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

* Re: Assignment of limited private types...
  1995-01-30 18:50 ` Theodore E. Dennison
  1995-01-31  1:05   ` Henry Baker
@ 1995-02-01 12:29   ` Robert Dewar
  1995-02-07  2:23   ` Adam Beneschan
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1995-02-01 12:29 UTC (permalink / raw)


WIth regard to the question of how to pass file types to a task, you can
always use a level of indirection and use a type

   type Access_File_Type is access File_Type;

In Ada 83, this requires that you allocate your File_Type variables on
the heap, which is a bit annoying, but in Ada 95, you could use aliased
File_Type variables, and then get the necessary access values using 'Access:

   My_File : aliased File_Type;

   Open (My_File ....)

   Initialize_Task (My_File'Access);




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

* Re: Assignment of limited private types...
  1995-01-30 18:50 ` Theodore E. Dennison
  1995-01-31  1:05   ` Henry Baker
  1995-02-01 12:29   ` Robert Dewar
@ 1995-02-07  2:23   ` Adam Beneschan
  2 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 1995-02-07  2:23 UTC (permalink / raw)


"Theodore E. Dennison" <dennison@escmail.mmc.orl.com> writes:
>stevem@dcs.gla.ac.uk (Steve McGowan) wrote:
> >
> > I'd like to pass in a 'file_type' identifier into a task, make a local
> > copy of this identifier within the task, and then write text to this
> > file stream inside the task.
> > 
> > But I cannot do this since 'file_type' is limited private.
> > 
> > Any ideas how I can pass in this identifier, and to write to it
> > locally?
> > 
> 
> The reason people make types "limited private" is so users CAN'T 
> make local copies of the objects. If the designer wanted you to
> be able to make copies of file_type objects, she would have made
> the type "private".
> 
> If for some reason you HAVE to make a copy, you could use an 
> unchecked_conversion, but DO NOT DO THIS! Odds are very high that 
> you will not get the results you desire. Try something else.

I usually solve problems of this type by using pointers.  E.g.

        type file_type_p is access file_type;

Now, when you want to open and access a file:

        my_file := new file_type_p;
        text_io.open (my_file.all, ...);
        text_io.get_line (my_file.all, ...);
        etc.
        text_io.close (my_file.all);

and you can assign file_type_p objects and pass them as parameters to
your heart's content.

Hope this helps,
                                -- Adam



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

end of thread, other threads:[~1995-02-07  2:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-01-26 16:37 Assignment of limited private types Steve McGowan
1995-01-30 18:50 ` Theodore E. Dennison
1995-01-31  1:05   ` Henry Baker
1995-02-01 12:29   ` Robert Dewar
1995-02-07  2:23   ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
1995-01-31  2:35 tmoran

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