comp.lang.ada
 help / color / mirror / Atom feed
* Redefining 'Class'Output
@ 1999-07-09  0:00 Matt Brennan
  1999-07-09  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Brennan @ 1999-07-09  0:00 UTC (permalink / raw)


Hiya,
     I am trying to stream objects of various tagged types between two
boxes. 

There are different compilers at each end with differing
Ada.Tags.External_Tags. One compiler (GNAT) has an external
representation the same as the Ada.Tags.Expanded_Name (defined by the
language to be all capitals) and the other compiler uses the same string
but all lower case.

In order to guarantee compatibility at each end, i wish to redefine the
'Class'Output (and 'Class'Input) for my base type to use the (language
defined) Expanded_Name in the stream rather than the external tag...
like so:

 type Abstract_Command_Type is abstract tagged null record;

 procedure Abstract_Command_Type_Output (
     Stream : access Ada.Streams.Root_Stream_Type'Class;
     Item   : in     Abstract_Command_Type'Class);

 for Abstract_Command_Type'Class'Output use
Abstract_Command_Type_Output;


My problem is in completing the body of Abstract_Command_Type_Output.

 procedure Abstract_Command_Type_Output (
    Stream : access Ada.Streams.Root_Stream_Type'Class;
    Item   : in     Abstract_Command_Type'Class) is
               
 begin
       
    String'Output (
       Stream, Ada.Tags.Expanded_Name(Item'Tag)));

    -- How do I now 'Output the rest of the object... the formal
    -- Item only gives me its class...
    --
    -- This won't work... ideas???
    --
    Abstract_Command_Type'Output (Stream, Item);
               
 end Abstract_Command_Type_Output;

Perhaps you could suggest how I can complete this Output procedure to
'Output the rest of the object? Or comment on the sanity of overriding
'Class'Ouput and 'Class'Input.

Beyond the problem of actually outputting the rest of the object, one
issue I came across is that, if I extend the Abstract_Command_Type and
do not further override 'Class'Output for the extension, I expect that I
will inherit procedure Abstract_Command_Type_Output for my extension.

Unfortunately, this does not seem to occur. For example:

   type Clock_Command_Type is new Abstract_Command_Type with
      record
         Data        : Integer;
      end record;

   Command : Clock_Command_Type := (
      Data       => 4);

   Clock_Command_Type'Class'Output(<some_stream>, Command);

This does not use Abstract_Command_Type_Output but rather the exisitng,
compiler defined 'Class'Output generated for the extension
Clock_Command_Type without reference to the redefinition for to use
Abstract_Command_Type_Output.

Any assistance would be great.

Thanks, 

  matt

--
-- Matt Brennan || Vision Systems Ltd || +61 8 8300 4686
--




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

* Re: Redefining 'Class'Output
  1999-07-09  0:00 Redefining 'Class'Output Matt Brennan
@ 1999-07-09  0:00 ` Tucker Taft
  0 siblings, 0 replies; 2+ messages in thread
From: Tucker Taft @ 1999-07-09  0:00 UTC (permalink / raw)


Matt Brennan wrote:
> 
> Hiya,
>      I am trying to stream objects of various tagged types between two
> boxes.
> 
> There are different compilers at each end with differing
> Ada.Tags.External_Tags. One compiler (GNAT) has an external
> representation the same as the Ada.Tags.Expanded_Name (defined by the
> language to be all capitals) and the other compiler uses the same string
> but all lower case.

One solution is to specify the value of External_Tag for
each type.  External_Tag is a specifiable attribute.  E.g.:

    for Tagged_Type_T'External_Tag use "P.TAGGED_TYPE_T";

See RM 95 13.3(75).

> In order to guarantee compatibility at each end, i wish to redefine the
> 'Class'Output (and 'Class'Input) for my base type to use the (language
> defined) Expanded_Name in the stream rather than the external tag...
> like so:

This is definitely the hard way, and I wouldn't recommend it...

> ...
> Any assistance would be great.
> 
> Thanks,
> 
>   matt
> 
> --
> -- Matt Brennan || Vision Systems Ltd || +61 8 8300 4686
> --

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

end of thread, other threads:[~1999-07-09  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-09  0:00 Redefining 'Class'Output Matt Brennan
1999-07-09  0:00 ` Tucker Taft

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