From: Robert Spooner <rls19@psu.edu>
Subject: Re: Ada Streams representation - XML
Date: Fri, 28 Mar 2003 10:46:32 -0500
Date: 2003-03-28T10:46:32-05:00 [thread overview]
Message-ID: <3E846E58.3080905@psu.edu> (raw)
In-Reply-To: 3e841acf$1@epflnews.epfl.ch
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
next prev parent reply other threads:[~2003-03-28 15:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2003-03-28 18:45 `
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox