comp.lang.ada
 help / color / mirror / Atom feed
* Qs re 'Write & 'Read
@ 2003-06-10  6:11 tmoran
  2003-06-10 12:53 ` Rodrigo Garcia
  2003-06-10 17:55 ` David C. Hoos
  0 siblings, 2 replies; 9+ messages in thread
From: tmoran @ 2003-06-10  6:11 UTC (permalink / raw)


Is the default 'Write on a non null access type supposed to write the .all
and a 'Read supposed to do an allocate and read in the .all value?
Same questions for generall access types.



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

* Re: Qs re 'Write & 'Read
  2003-06-10  6:11 Qs re 'Write & 'Read tmoran
@ 2003-06-10 12:53 ` Rodrigo Garcia
  2003-06-10 17:55 ` David C. Hoos
  1 sibling, 0 replies; 9+ messages in thread
From: Rodrigo Garcia @ 2003-06-10 12:53 UTC (permalink / raw)


<tmoran@acm.org> wrote in message news:YDeFa.929408$Zo.212966@sccrnsc03...
> Is the default 'Write on a non null access type supposed to write the .all
> and a 'Read supposed to do an allocate and read in the .all value?
> Same questions for generall access types.

The answer in any case is, unfortunately, no. It is the value of the access
type itself wich is written.

Rodrigo





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

* Re: Qs re 'Write & 'Read
  2003-06-10  6:11 Qs re 'Write & 'Read tmoran
  2003-06-10 12:53 ` Rodrigo Garcia
@ 2003-06-10 17:55 ` David C. Hoos
  2003-06-10 19:09   ` tmoran
  1 sibling, 1 reply; 9+ messages in thread
From: David C. Hoos @ 2003-06-10 17:55 UTC (permalink / raw)



<tmoran@acm.org> wrote in message news:YDeFa.929408$Zo.212966@sccrnsc03...
> Is the default 'Write on a non null access type supposed to write the .all
> and a 'Read supposed to do an allocate and read in the .all value?
> Same questions for generall access types.
No.  The actual access value is written to the stream -- not very useful.

However, I have been using stream attribute override procedures like these
for years:

   -----------------------------
   -- Translation_Access_Read --
   -----------------------------

   procedure Translation_Access_Read
     (The_Stream_Access : access Ada.Streams.Root_Stream_Type'Class;
      The_Translation_Access : out Translation_Access)
   is
      Is_Non_Null : Boolean;
   begin
      Boolean'Read (The_Stream_Access, Is_Non_Null);
      if Is_Non_Null then
         The_Translation_Access := new Translation'
           (Translation'Input (The_Stream_Access));
      else
         The_Translation_Access := null;
      end if;
   end Translation_Access_Read;

   ------------------------------
   -- Translation_Access_Write --
   ------------------------------

   procedure Translation_Access_Write
     (The_Stream_Access : access Ada.Streams.Root_Stream_Type'Class;
      The_Translation_Access : Translation_Access)
   is
   begin
      if The_Translation_Access /= null then
         Boolean'Write (The_Stream_Access, True);
         Translation'Output
           (The_Stream_Access, The_Translation_Access.all);
      else
         Boolean'Write (The_Stream_Access, False);
      end if;
   end Translation_Access_Write;

The idea is that in a similar fashion to the way that for unconstrained
string types
the string itself is preceded by its contstraint, access types are written
to the
stream with a boolean value preceding the data (if any).

It surely seemed to me like the language standard could have defined
something
like this as the default for access types, but alas, it did not.

I'm not sure why i didn't make these procedures as part of a generic package
to
be instantiated with two parameters -- the data type and its access type,
but
this is what I've been using, lo these several years.


> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>





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

* Re: Qs re 'Write & 'Read
  2003-06-10 17:55 ` David C. Hoos
@ 2003-06-10 19:09   ` tmoran
  2003-06-10 21:30     ` David C. Hoos
  0 siblings, 1 reply; 9+ messages in thread
From: tmoran @ 2003-06-10 19:09 UTC (permalink / raw)


>the string itself is preceded by its contstraint, access types are written
>to the stream with a boolean value preceding the data (if any).
  Sounds right.

>It surely seemed to me like the language standard could have defined
>something like this as the default for access types, but alas, it did not.
  I can see there would be difficulties for general access types, but
heap access types seem easy enough.  Unless storage pools cause
difficulties.



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

* Re: Qs re 'Write & 'Read
  2003-06-10 19:09   ` tmoran
@ 2003-06-10 21:30     ` David C. Hoos
  2003-06-10 23:26       ` tmoran
  2003-06-11 19:19       ` Thomas Wolf
  0 siblings, 2 replies; 9+ messages in thread
From: David C. Hoos @ 2003-06-10 21:30 UTC (permalink / raw)



<tmoran@acm.org> wrote in message news:02qFa.1186062$F1.140501@sccrnsc04...
> >the string itself is preceded by its contstraint, access types are
written
> >to the stream with a boolean value preceding the data (if any).
>   Sounds right.
>
> >It surely seemed to me like the language standard could have defined
> >something like this as the default for access types, but alas, it did
not.
>   I can see there would be difficulties for general access types, but
> heap access types seem easy enough.  Unless storage pools cause
> difficulties.
Maybe my mind's just in a fog today, but please explain why there'd be
a problem with any kind of access type -- general, or not, using my
approach.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>





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

* Re: Qs re 'Write & 'Read
  2003-06-10 21:30     ` David C. Hoos
@ 2003-06-10 23:26       ` tmoran
  2003-06-11  1:31         ` David C. Hoos
  2003-06-11 19:19       ` Thomas Wolf
  1 sibling, 1 reply; 9+ messages in thread
From: tmoran @ 2003-06-10 23:26 UTC (permalink / raw)


>Maybe my mind's just in a fog today, but please explain why there'd be
>a problem with any kind of access type -- general, or not, using my
>approach.
  Aliasing.
  type phs is access integer;
  type pgs is access all integer;
  type r is record
    i : aliased integer;
    ph : phs;
    pg : pgs;
  end record;
  x : r;
begin
  x.ph := new integer;
  x.pg := x.i'access;
but on reading it back in, you can tell both x.ph and x.pg are non-null,
but you don't know whether x.pg should allocate from the heap or point
to some existing (stack) object.



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

* Re: Qs re 'Write & 'Read
  2003-06-10 23:26       ` tmoran
@ 2003-06-11  1:31         ` David C. Hoos
  0 siblings, 0 replies; 9+ messages in thread
From: David C. Hoos @ 2003-06-11  1:31 UTC (permalink / raw)



<tmoran@acm.org> wrote in message news:nOtFa.1188350$F1.139910@sccrnsc04...
> >Maybe my mind's just in a fog today, but please explain why there'd be
> >a problem with any kind of access type -- general, or not, using my
> >approach.
>   Aliasing.
>   type phs is access integer;
>   type pgs is access all integer;
>   type r is record
>     i : aliased integer;
>     ph : phs;
>     pg : pgs;
>   end record;
>   x : r;
> begin
>   x.ph := new integer;
>   x.pg := x.i'access;
> but on reading it back in, you can tell both x.ph and x.pg are non-null,
> but you don't know whether x.pg should allocate from the heap or point
> to some existing (stack) object.

Well, for the life of me, I can't see why anyone would need to do what
your example does.  If, indeed, an access component of a record designates
an aliased component, then it seems to me that one would need an overridden
set of stream attributes for the whole record.  Writing r.pg to the stream
would be meaningless, since it designates data already written to the
stream.

The read attribute would simply make the assignment r.pg = r.i'access, after
having read r.i from the stream.

> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





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

* Re: Qs re 'Write & 'Read
  2003-06-10 21:30     ` David C. Hoos
  2003-06-10 23:26       ` tmoran
@ 2003-06-11 19:19       ` Thomas Wolf
  2003-06-12 10:12         ` 
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Wolf @ 2003-06-11 19:19 UTC (permalink / raw)


david.c.hoos.sr@ada95.com wrote:
> 
> <tmoran@acm.org> wrote in message news:02qFa.1186062$F1.140501@sccrnsc04...
> > >the string itself is preceded by its contstraint, access types are
> written
> > >to the stream with a boolean value preceding the data (if any).
> >   Sounds right.
> >
> > >It surely seemed to me like the language standard could have defined
> > >something like this as the default for access types, but alas, it did
> not.
> >   I can see there would be difficulties for general access types, but
> > heap access types seem easy enough.  Unless storage pools cause
> > difficulties.
> Maybe my mind's just in a fog today, but please explain why there'd be
> a problem with any kind of access type -- general, or not, using my
> approach.

Cyclic self-referential data structures. It's clearly out of the
standard's business; it's up to your application to define how
a graph (cyclic or not, tree-shaped or not) is to be written to
and read from a stream.

-- 
-----------------------------------------------------------------
Thomas Wolf                          e-mail: t_wolf@angelfire.com




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

* Re: Qs re 'Write & 'Read
  2003-06-11 19:19       ` Thomas Wolf
@ 2003-06-12 10:12         ` 
  0 siblings, 0 replies; 9+ messages in thread
From:  @ 2003-06-12 10:12 UTC (permalink / raw)


Thomas Wolf wrote:
> david.c.hoos.sr@ada95.com wrote:
> 
>><tmoran@acm.org> wrote in message news:02qFa.1186062$F1.140501@sccrnsc04...
>>
>>>>the string itself is preceded by its contstraint, access types are
>>>
>>written
>>
>>>>to the stream with a boolean value preceding the data (if any).
>>>
>>>  Sounds right.
>>>
>>>
>>>>It surely seemed to me like the language standard could have defined
>>>>something like this as the default for access types, but alas, it did
>>>
>>not.
>>
>>>  I can see there would be difficulties for general access types, but
>>>heap access types seem easy enough.  Unless storage pools cause
>>>difficulties.
>>
>>Maybe my mind's just in a fog today, but please explain why there'd be
>>a problem with any kind of access type -- general, or not, using my
>>approach.
> 
> 
> Cyclic self-referential data structures. It's clearly out of the
> standard's business; it's up to your application to define how
> a graph (cyclic or not, tree-shaped or not) is to be written to
> and read from a stream.

   I would not say that it is totally outside standard's business... It 
clearly adds complexity to the compiler/run-time, but Java does that 
automatically (and it detects circularities).

Rodrigo




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

end of thread, other threads:[~2003-06-12 10:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-10  6:11 Qs re 'Write & 'Read tmoran
2003-06-10 12:53 ` Rodrigo Garcia
2003-06-10 17:55 ` David C. Hoos
2003-06-10 19:09   ` tmoran
2003-06-10 21:30     ` David C. Hoos
2003-06-10 23:26       ` tmoran
2003-06-11  1:31         ` David C. Hoos
2003-06-11 19:19       ` Thomas Wolf
2003-06-12 10:12         ` 

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