From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7936408ed8296efa X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-16 07:45:46 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!newsfeed.berkeley.edu!ucberkeley!logbridge.uoregon.edu!titan03.ksc.nasa.gov!niven.ksc.nasa.gov!usenet From: "Samuel T. Harris" Newsgroups: comp.lang.ada Subject: Re: User define attributes Date: Mon, 16 Apr 2001 09:35:38 -0500 Organization: Raytheon Aerospace Engineering Services Message-ID: <3ADB033A.F10344A9@gsde.hou.us.ray.com> References: <9b9g7c$cp6$1@taliesin.netcom.net.uk> <3ada9cf5$1@pull.gecm.com> <9behk1$ik9$1@taliesin.netcom.net.uk> <3adad7ab$1@pull.gecm.com> Reply-To: samuel_t_harris@raytheon.com NNTP-Posting-Host: sstf-fw.jsc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (X11; U; IRIX64 6.2 IP19) X-Accept-Language: en Xref: supernews.google.com comp.lang.ada:6914 Date: 2001-04-16T09:35:38-05:00 List-Id: 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!"