comp.lang.ada
 help / color / mirror / Atom feed
* Overriding the "lowest level" stream procedures
@ 2009-10-11 14:56 xorque
  2009-10-11 15:39 ` Samuel Tardieu
  0 siblings, 1 reply; 4+ messages in thread
From: xorque @ 2009-10-11 14:56 UTC (permalink / raw)


Hello.

I'd like to ensure that any piece of code in a program that executes:

  T'Output (Stream, S);
  S := T'Input (Stream);

(Where T is String or a type derived from String and S is an object of
any of those types)

... Has to go through my (overridden) Stream procedures. I'm
essentially trying to ensure that all textual data is written in a
strictly defined (not implementation defined) format so that the
program can communicate with other programs not written in
Ada. I also want to make it as hard as possible to, for example,
accidentally miss out a statement such as:

  for X'Output use Some_Output_Procedure;

...and end up using the default stream procedures again.

I think I probably need to define my own Stream type. Is this the
case?



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

* Re: Overriding the "lowest level" stream procedures
  2009-10-11 14:56 Overriding the "lowest level" stream procedures xorque
@ 2009-10-11 15:39 ` Samuel Tardieu
  2009-10-11 18:57   ` sjw
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Tardieu @ 2009-10-11 15:39 UTC (permalink / raw)


>>>>> "xorque" == xorque  <xorquewasp@googlemail.com> writes:

xorque> I think I probably need to define my own Stream type. Is this
xorque> the case?

You can plug your code at two different levels:

  - define your own stream type; you will manipulate byte arrays, but
    you will not have access to any type information;

  - define your own stream attributes: you will decide how typed values
    are transformed into/from byte arrays, but you cannot override this
    choice for predefined types as you have to define those attributes
    in the same declarative unit as the type definition itself.

You will likely want to use the second method, in which case you'll have
to refrain from using predefined types.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



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

* Re: Overriding the "lowest level" stream procedures
  2009-10-11 15:39 ` Samuel Tardieu
@ 2009-10-11 18:57   ` sjw
  2009-10-11 19:31     ` Samuel Tardieu
  0 siblings, 1 reply; 4+ messages in thread
From: sjw @ 2009-10-11 18:57 UTC (permalink / raw)


On Oct 11, 4:39 pm, Samuel Tardieu <s...@rfc1149.net> wrote:
> >>>>> "xorque" == xorque  <xorquew...@googlemail.com> writes:
>
> xorque> I think I probably need to define my own Stream type. Is this
> xorque> the case?
>
> You can plug your code at two different levels:
>
>   - define your own stream type; you will manipulate byte arrays, but
>     you will not have access to any type information;
>
>   - define your own stream attributes: you will decide how typed values
>     are transformed into/from byte arrays, but you cannot override this
>     choice for predefined types as you have to define those attributes
>     in the same declarative unit as the type definition itself.
>
> You will likely want to use the second method, in which case you'll have
> to refrain from using predefined types.

A third way, if you are using GNAT, is to provide your own body for
System.Stream_Attributes (s-stratt.adb) and compile using gnatmake -a
(not sure how to do this using gprbuild, though).

This gives you the ability to control how the individual elements of
the data are mapped to the bytes of the stream; but there is no
knowledge of what the elements mean at an application level (ie, no
visibility of the type that's being streamed, just that this element
is a Float).




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

* Re: Overriding the "lowest level" stream procedures
  2009-10-11 18:57   ` sjw
@ 2009-10-11 19:31     ` Samuel Tardieu
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Tardieu @ 2009-10-11 19:31 UTC (permalink / raw)


>>>>> "sjw" == sjw  <simon.j.wright@mac.com> writes:

sjw> A third way, if you are using GNAT, is to provide your own body for
sjw> System.Stream_Attributes (s-stratt.adb) and compile using gnatmake
sjw> -a (not sure how to do this using gprbuild, though).

With unfortunately no guarantee that it will work when you update GNAT.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



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

end of thread, other threads:[~2009-10-11 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-11 14:56 Overriding the "lowest level" stream procedures xorque
2009-10-11 15:39 ` Samuel Tardieu
2009-10-11 18:57   ` sjw
2009-10-11 19:31     ` Samuel Tardieu

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