Redefining 'Class'Output 
Author Message
 Redefining 'Class'Output

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
--



Tue, 25 Dec 2001 03:00:00 GMT  
 Redefining 'Class'Output

Quote:

> 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).

Quote:
> 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...

Quote:
> ...
> Any assistance would be great.

> Thanks,

>   matt

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

--

Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA


Tue, 25 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Access to T'Class vs T'Class as parameter to subprogram

2. 'split' creates extra output

3. Outputting 'Raw' printer data

4. Undetermined Output in 'X' state

5. capture 'system' output

6. Grab output from 'tail'

7. Redefining class that does not inherit with class that does

8. repeated class redefinition and update-instance-for-redefined-class

9. Bug in the class 'File'???

10. 'SOOP' Class system

11. Maritz: Why Microsoft won't ship Sun's Java Class Libraries

12. 'parse source' in class file

 

 
Powered by phpBB® Forum Software