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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d56e8cd008b09d8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-22 11:10:50 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!193.251.151.101!opentransit.net!wanadoo.fr!not-for-mail From: "Bertrand Augereau" Newsgroups: comp.lang.ada Subject: Re: Construction/Destruction and copy semantics Date: Sun, 22 Jul 2001 20:16:06 +0200 Organization: Wanadoo, l'internet avec France Telecom Message-ID: <9jf4v9$njv$1@wanadoo.fr> References: <9jeuvb$not$1@wanadoo.fr> <3B5B138A.3E38FBE@worldnet.att.net> NNTP-Posting-Host: afontenayssb-103-1-1-240.abo.wanadoo.fr X-Trace: wanadoo.fr 995825449 24191 217.128.72.240 (22 Jul 2001 18:10:49 GMT) X-Complaints-To: abuse@wanadoo.fr NNTP-Posting-Date: 22 Jul 2001 18:10:49 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Xref: archiver1.google.com comp.lang.ada:10426 Date: 2001-07-22T18:10:49+00:00 List-Id: Thanks, I had forgotten this (it's been 3 years since I last looked at Ada code, at school, and I'm getting back to it for writing a program which relies heavily on concurrency). It solves the problems in an elegant way, except you have to work around the different construction schemes with a discriminant All this (controlled types) seems a bit syntactically "out of the language", but I guess it is because it was an addition of Ada95, isn't it? > The Ada approach to both of these questions is to create your tagged > types as extensions of either Ada.Finalization.Controlled or > Ada.Finalization.Limited_Controlled for the first question, and > Ada.Finalization.Controled for the second question. > > The Ada.Finalization package defines two abstract tagged types. > Ada.Finalization.Controlled is for use when you want to create > non-limited types. Ada.Finalization.Limited_Controlled is used when > you want to create limited types. > > The Ada.Finalization.Controlled type has three primitive procedures: > Initialze, Adjust, and Finalize. Initialize is similar to a C++ > default constructor. Initialize is invoked immediately after the > normal initialization of a controlled object. Finalize is invoked > immediately before finalization of any of the components of a > controlled object. Adjust is invoked as the last step of an > assignment to a non-limited controlled object. > > The Ada.Finalization package is described in section 7.6 of the > Ada Reference Manual. > > I am sure you have noticed that the Initialization procedure does > not correspond to all forms of C++ constructors, but only the > default constructor. Ada allows you to handle this problem in > several ways. The manner which is IMHO most similar to a non-default > C++ constructor is to provide the tagged type with a discriminant. > This allows you to parameterize the creation of an object of > that type. Combining type discriminants with the Initialize > procedure will give you all the flexibility of a C++ constructor. > > The adjust procedure can be used to customize the assignment of > a type. Note that Ada, by default, performs deep copies. Of course > one reason for that is that Ada code generally uses fewer access > types than C++ (compared with C++ pointers and references). > Shallow copying only makes sense for access types. If you > define an Ada record (tagged or not) containing fields which are > instances of access types, then copying an object of the record > will automatically result in shallow copies of the accessed > values. The "deep" copy operation for an access type is to copy > the value from the corresponding access type. > > Jim Rogers > Colorado Springs, Colorado USA