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,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,48fa8e3cfaec41af X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-23 11:40:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!unlnews.unl.edu!newsreader.wustl.edu!gumby.it.wmich.edu!aanews.merit.edu!msunews!not-for-mail From: "Chad R. Meiners" Newsgroups: comp.lang.ada Subject: Perhaps we keep lists elements private and adjust the elements to fit? Date: Tue, 23 Jul 2002 14:34:01 -0400 Organization: Michigan State University Message-ID: References: Reply-To: "Chad R. Meiners" NNTP-Posting-Host: arctic.cse.msu.edu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: archiver1.google.com comp.lang.ada:27341 Date: 2002-07-23T14:34:01-04:00 List-Id: "Stephen Leake" wrote in message news:uheirlk4z.fsf@gsfc.nasa.gov... > "chris.danx" writes: > > > > > > Is this a worth while tradeoff? I guess the question "how often are limited > > types used?" would serve better, as it would give a measure on which to base > > a decision. > > This was discussed extensively back in December 2001 during the Grace > Lists requirements development. You could search on Google for that > discussion. > > My own opinion is that supporting limited types is a requirement for > any general-purpose container. Perhaps what we need to do is write the container libraries to accept private types and provide a generic package that converts limited privates to private types. Let's assume that we have a limited type as follows package Mylim is type Mine is limited private; procedure Copy(Item : in Mine; Object : out Mine); private type Mine is new Integer; end Mylim; package body Mylim is procedure Copy(Item : in Mine; Object : out Mine) is begin Object := Item; end Copy; end Mylim; We want to use this type in a container package(that only accepts private types), but we don't want to convert the package to use a private type. Instead ,we can use a generic wrapper to convert the type for use with our favorite container package. I very simple wrapper (in other words untested but it does compile) would look like with Ada.Finalization; generic type Limited_Type is limited private; with procedure Copy(Item : in Limited_Type; Object : out Limited_Type); package Promote is type Storage is private; function To (Item : in Limited_Type) return Storage; procedure From (Item : in Storage; Becomes : out Limited_Type); private Default_Limited_Type : Limited_Type; type Limited_Access is access Limited_Type; type Storage is new Ada.Finalization.Controlled with record Item : Limited_Access; end record; procedure Initialize(Object : in out Storage); procedure Adjust (Object : in out Storage); procedure Finalize (Object : in out Storage); end Promote; with Ada.Unchecked_Deallocation; package body Promote is ------------ -- Adjust -- ------------ procedure Adjust (Object : in out Storage) is begin if Object.Item /= null then declare Temp : Limited_Access := new Limited_Type; begin Copy (Object.Item.all,Temp.all); Object.Item := Temp; end; end if; end Adjust; -------------- -- Finalize -- -------------- procedure Finalize (Object : in out Storage) is procedure Free is new Ada.Unchecked_Deallocation(Limited_Type, Limited_Access ); begin Free (Object.Item); end Finalize; ---------- -- From -- ---------- procedure From (Item : in Storage; Becomes : out Limited_Type) is begin if Item.Item = null then Copy (Default_Limited_Type, Becomes); else Copy (Item.Item.all, Becomes); end if; end From; ---------------- -- Initialize -- ---------------- procedure Initialize (Object : in out Storage) is begin null; end Initialize; -------- -- To -- -------- function To (Item : in Limited_Type) return Storage is Temp : Storage; begin Temp.Item := new Limited_Type; Copy (Item, Temp.Item.all); return Temp; end To; end Promote; so we can then promote Mylim.Mine to the status of private type with the following package. with Promote; package Mylim.Storage is new Promote(Mylim.Mine,MyLim.Copy); This schema has the advantage that container libraries can be written to take private types which simplifies their use to the newbie since they can easily instantiate linked lists of integers without having to write a copy procedure for them. Once someone has become conformable with using limited types they should also be comfortable with performing a type promotion. Comments, anyone? -Chad R. Meiners