comp.lang.ada
 help / color / mirror / Atom feed
From: "Bertrand Augereau" <baugereau@ifrance.kom>
Subject: Re: Construction/Destruction and copy semantics
Date: Sun, 22 Jul 2001 20:16:06 +0200
Date: 2001-07-22T18:10:49+00:00	[thread overview]
Message-ID: <9jf4v9$njv$1@wanadoo.fr> (raw)
In-Reply-To: 3B5B138A.3E38FBE@worldnet.att.net

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





      reply	other threads:[~2001-07-22 18:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-22 16:33 Construction/Destruction and copy semantics Bertrand Augereau
2001-07-22 17:42 ` Ehud Lamm
2001-07-22 17:52 ` James Rogers
2001-07-22 18:16   ` Bertrand Augereau [this message]
replies disabled

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