comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <u61783@gsde.hou.us.ray.com>
Subject: Re: User define attributes
Date: Mon, 16 Apr 2001 09:35:38 -0500
Date: 2001-04-16T09:35:38-05:00	[thread overview]
Message-ID: <3ADB033A.F10344A9@gsde.hou.us.ray.com> (raw)
In-Reply-To: 3adad7ab$1@pull.gecm.com

Martin Dowie wrote:
> 
> well, if you mean someting like
> 
> type My_Type ...;
> for My_Type'Image use ...;
> 
> you can't (that's for stream read/write only... I think), but as
> attributes are defined as functions anyway (check annex L) you can
> force your generic to require an Image function and even do nifty
> instantiations like...
> 
> generic
>   type My_Type is private;
>   with function Image (X : My_Type) return String;
> package Test is
>   procedure Call (X : My_Type);
> end Test;
> 
> with Test;
> package Tester is new test (Integer, Integer'Image);
> 
> For composite types you have to "roll your own" Image routine that
> would probably just call up the scalar 'Image routines in turn
> or other rolled composite IMage routines.
> 

It is trivial to build a generic which implements the a
width, value, and image function for arrays. All it needs
are the width, value, and image functions for the indexes
and composite types.

It is somewhat harder to build a generic for records
since the "index" are the field names and the composite
function depend upon which field is in use. But it
can be done.

I routinely write width, value, and image functions
for all my important types. Having these generics
in place, I get these routines with some simple
handler code and a generic instantiations. With them
I get the following advantages ...

1. I can easily insert put_line kinds of debug code.
2. If supported, I can call them within my debugger.
3. I can defer aggregrate initialization of variables
   to file_io during elaboration, and vice-versa.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"



  reply	other threads:[~2001-04-16 14:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-14 13:33 User define attributes Ayende Rahien
2001-04-16  7:27 ` Martin Dowie
2001-04-16 11:23   ` Ayende Rahien
2001-04-16 11:37     ` Martin Dowie
2001-04-16 14:35       ` Samuel T. Harris [this message]
2001-04-16 15:20         ` Martin Dowie
2001-04-16 15:37           ` Brian Rogoff
2001-04-16 16:19           ` Samuel T. Harris
2001-04-16 17:08             ` Marin David Condic
2001-04-16 22:00               ` Samuel T. Harris
2001-04-17 12:34                 ` Georg Bauhaus
2001-04-17 20:35                   ` Samuel T. Harris
2001-04-24 21:00                   ` Samuel T. Harris
2001-04-16 17:37             ` Martin Dowie
     [not found]           ` <0tEC6.7646$FY5.638172@www.newsranger.com>
2001-04-16 17:34             ` Martin Dowie
2001-04-18 12:14         ` Marius Amado Alves
2001-04-18 20:50           ` Samuel T. Harris
2001-04-19  1:35             ` Jeffrey Carter
2001-04-19 12:50               ` Samuel T. Harris
2001-04-20 19:08             ` Marius Amado Alves
replies disabled

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