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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,36a29c2860aff686 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 29 Nov 2010 17:54:51 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Properties References: <3b84c8e7-1a51-4a7c-9646-119f1fc51478@s4g2000yql.googlegroups.com> <4cf24d13$0$6985$9b4e6d93@newsspool4.arcor-online.net> <3e9dfa01-6975-401d-999d-7cf87e926fb3@z9g2000yqz.googlegroups.com> In-Reply-To: <3e9dfa01-6975-401d-999d-7cf87e926fb3@z9g2000yqz.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4cf3dadc$0$6883$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Nov 2010 17:54:52 CET NNTP-Posting-Host: e29f28b5.newsspool2.arcor-online.net X-Trace: DXC=ii:Lh>_cHTX3j=:=mjNDDVUV: X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:16672 Date: 2010-11-29T17:54:52+01:00 List-Id: On 28.11.10 22:22, Shark8 wrote: > It probably would > have looked something like this: > > Type String_Data_Object( String_Data : Access String ) is > Limited Tagged; --Forward declared. > > Type PS_String( Data_Object : Access String_Data_Object ) is > New PostScript_Object with record > Start, Stop : Positive; -- String'First/'Last equiv. > The_String : Separate String; > end record; > For PS_String.The_String.Read Use > Data_Object.String_Data.All( Start..Stop ); > For PS_String.The_String.Write Use > Data_Object.String_Data.All( Start..Stop ); To the extend I have understood the approach, you can do this with current Ada. Just make The_String aware of its surroundings (not sure I got the String_Data_Object involved as should): type PS_String; type PostScript_String (Referred : access PS_String; Capacity : Positive) is record Data : String (1 .. Capacity); end record; type PS_String( Data_Object : access String_Data_Object; Capacity : Positive) is limited new PostScript_Object with record Start, Stop : Positive; -- String'First/'Last equiv. The_String : PostScript_String (PS_String'Access, Capacity); end record; Then you can define a user defined 'Write attribute for PostScript_String that does use Start and Stop from PS_String to select a range from the string's data: procedure Write_PostScript_String (Stream : access Ada.Streams.Root_Stream_Type'Class; Object : PostScript_String) is Link : PS_String renames Object.Referred.all; -- the surroundings begin String'Write(Stream, Object.Data (Link.Start .. Link.Stop)); end Write_PostScript_String; >> 2 - What if a property of an object needs to refer to two or more >> of its components? >> >> Say, a property's public view perhaps being much better presented >> as a Point rather than as forcing two Coordinate properties (even >> though Coordinates may have been chosen for internal representation >> in a record). > > That's kinda easy: > -- for referring to multiple fields. I think I meant the other way around, as in the Get_XY example: > Type Point is Record > X, Y : Integer > End Record; > > Type Point_3D is > X, Y, Z : Integer; > Parallel_Projected : Separate Point; For Parallel_Projected'Read Use ???; > end record; Suppose clients of your private Point_3D should be able to see a property whose computation (result is Point) involves both components X and Y under the hood. Call it the Shadow property, maybe. More generally, I might have type R is private; function Spatial_Needs (Item : R) return Area_N; private type R is record X1, X2, ..., Xm : Distance; Y1, Y2, ..., Yn : Something; ... end record; Spatial_Needs is computed from X1, X2, X5, X12, and Z3 to Z6. Will standardized properties help provide for this? >> 3 - Is there anything in properties that helps with order of >> component access? (Just an idea.) > > I'm not sure I know what you mean by this... do you mean the order as > in how Ada automatically orders the internals of a record when piping > them to a stream? Something new, and probably not simple: the type's operations can be called in a specific order only. For example, do not call property p3 before both p1 and p2 have been set. >> As an alternative, I'd suggest an option to remove definitions >> of full views of types from the specs. > > Hm, I'm not sure I see what use that would be. Somewhat like the pointer-to-implementation approach. The full type definition is in the body of a package (or in some representation part of a package which is separate from both the spec and the body), for example. Every read/write of one or more components is done through some primitive operation. A user of the type has no idea what the component parts of an object might be.