comp.lang.ada
 help / color / mirror / Atom feed
* Ada Streams representation
@ 2003-03-27 16:31 
  2003-03-27 18:51 ` Robert Spooner
  0 siblings, 1 reply; 5+ messages in thread
From:  @ 2003-03-27 16:31 UTC (permalink / raw)


Hi,

   Can a new type of Stream define its own representation? I am afraid 
the answer is no...(Stream_Element is implementation defined but it 
cannot be changed).

Rodrigo




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

* Re: Ada Streams representation
  2003-03-27 16:31 Ada Streams representation 
@ 2003-03-27 18:51 ` Robert Spooner
  2003-03-28  9:50   ` Ada Streams representation - XML 
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Spooner @ 2003-03-27 18:51 UTC (permalink / raw)


Rodrigo,

You can define your own stream representation for a _type_ by redefining 
'read and 'write for that type.

Bob

Rodrigo Garc�a wrote:
> Hi,
> 
>   Can a new type of Stream define its own representation? I am afraid 
> the answer is no...(Stream_Element is implementation defined but it 
> cannot be changed).
> 
> Rodrigo
> 


-- 
                             Robert L. Spooner
                      Registered Professional Engineer
                        Associate Research Engineer
                   Intelligent Control Systems Department

          Applied Research Laboratory        Phone: (814) 863-4120
          The Pennsylvania State University  FAX:   (814) 863-7841
          P. O. Box 30
          State College, PA 16804-0030       rls19@psu.edu




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

* Re: Ada Streams representation - XML
  2003-03-27 18:51 ` Robert Spooner
@ 2003-03-28  9:50   ` 
  2003-03-28 15:46     ` Robert Spooner
  0 siblings, 1 reply; 5+ messages in thread
From:  @ 2003-03-28  9:50 UTC (permalink / raw)


Robert Spooner wrote:
> Rodrigo,
> 
> You can define your own stream representation for a _type_ by redefining 
> 'read and 'write for that type.

   Yes, I know that (RM 13.13.2(40)). The problem with that solution is 
that you lose the default stream representation for that type. Besides, 
it does not let you override the 'Write or 'Read attributes for 
predefined non-limited types (e.g. "Integer") and the Stream_Element 
type is still fixed.

   I was thinking of a mechanism that would allow you, for instance, to 
serialize a type using XML while you could still use ordinary 
serialization. I am afraid that defining a new type of Stream (derived 
from Root_Stream_Type) is not the solution, since this is thought for 
specifying new back-ends and ways of reading/writing but not for stating 
a different representation...

Rodrigo

> 
> Bob
> 
> Rodrigo Garc�a wrote:
> 
>> Hi,
>>
>>   Can a new type of Stream define its own representation? I am afraid 
>> the answer is no...(Stream_Element is implementation defined but it 
>> cannot be changed).
>>
>> Rodrigo
>>
> 
> 





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

* Re: Ada Streams representation - XML
  2003-03-28  9:50   ` Ada Streams representation - XML 
@ 2003-03-28 15:46     ` Robert Spooner
  2003-03-28 18:45       ` 
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Spooner @ 2003-03-28 15:46 UTC (permalink / raw)


Rodrigo,

Rodrigo Garc�a wrote:
> Robert Spooner wrote:
> 
>> Rodrigo,
>>
>> You can define your own stream representation for a _type_ by 
>> redefining 'read and 'write for that type.
> 
> 
>   Yes, I know that (RM 13.13.2(40)). The problem with that solution is 
> that you lose the default stream representation for that type. Besides, 
> it does not let you override the 'Write or 'Read attributes for 
> predefined non-limited types (e.g. "Integer") and the Stream_Element 
> type is still fixed.

I don't know any way of changing the Stream_Element type, but for types 
for which you want to keep the default 'Read and 'Write, you can derive 
a new type from them (with no changes if you don't need any) and 
redefine 'Read and 'Write for the derived types. Then just do explicit 
conversions where necessary. You can also derive a new composite type 
composed of the new types from a composite type comprised of the 
original types, and explicit conversions between the composite types 
will work as well.

> 
>   I was thinking of a mechanism that would allow you, for instance, to 
> serialize a type using XML while you could still use ordinary 
> serialization. I am afraid that defining a new type of Stream (derived 
> from Root_Stream_Type) is not the solution, since this is thought for 
> specifying new back-ends and ways of reading/writing but not for stating 
> a different representation...

Well, since type Root_Stream_Type is abstract, you have to derive a non 
abstract type from it to use streams, but the stream representation is 
provided through the 'Read and 'Write attributes of the types you are 
using. You then can use those attributes to read and write information 
to a Stream_Element_Array in memory (or to a file) using any 
representation scheme you choose (by implementing it in the overridden 
attributes,) including an XML representation. You then can manipulate 
the Stream_Element_Array as necessary. I have used streams to read and 
write to serial ports and TCP/IP circuits using non default 
representations of types this way. It's very useful, and once you have 
defined the representation by overriding the attributes for the 
elementary types you are using, it works automatically for composite types.

The important thing to remember is that the stream representation (which 
can be whatever you want so long as it can be represented in an array of 
Stream_Element) is associated with the type, not the stream itself.

Bob

-- 
                             Robert L. Spooner
                      Registered Professional Engineer
                        Associate Research Engineer
                   Intelligent Control Systems Department

          Applied Research Laboratory        Phone: (814) 863-4120
          The Pennsylvania State University  FAX:   (814) 863-7841
          P. O. Box 30
          State College, PA 16804-0030       rls19@psu.edu




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

* Re: Ada Streams representation - XML
  2003-03-28 15:46     ` Robert Spooner
@ 2003-03-28 18:45       ` 
  0 siblings, 0 replies; 5+ messages in thread
From:  @ 2003-03-28 18:45 UTC (permalink / raw)


Robert Spooner wrote:

> The important thing to remember is that the stream representation (which 
> can be whatever you want so long as it can be represented in an array of 
> Stream_Element) is associated with the type, not the stream itself.

   Yes, we agree, that is one of the limitations I was talking about: 
you cannot serialize an object of a specific type using different 
representations (i.e. you cannot have two different 'Write procedures 
for the same type).

   Thank you for your ideas and experiences,

Rodrigo





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

end of thread, other threads:[~2003-03-28 18:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-27 16:31 Ada Streams representation 
2003-03-27 18:51 ` Robert Spooner
2003-03-28  9:50   ` Ada Streams representation - XML 
2003-03-28 15:46     ` Robert Spooner
2003-03-28 18:45       ` 

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