Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ada Finalization Adjust procedure - What to put here?

Tags:

object

oop

ada

Given the following declarations :

   type Food_T is abstract tagged null record;
   type Food_Ptr is access all Food_T'Class;

   type Wrapper_T is new Ada.Finalization.Controlled with record
      Ptr : Food_Ptr;
   end record;

   procedure Adjust (Object : in out Wrapper_T) is
   begin
      null; -- what goes here ?
   end Adjust;

I am wondering how to allocate & assign (Deep Copy) the correct derivitive of food_t when i dont know what type Object.ptr will be pointing to (and where Source & Destination are!).

Any help would be appreciated.

Thanks,

NWS.


1 Answers

I think you mean:

procedure Adjust (Object : in out Wrapper_T) is
begin
   Object.Ptr := new Food_T'Class'(Object.Ptr.all);
end Adjust;

Then it's Object.Ptr.all's job to ensure that it is really a deep copy, of course. (To do this, Object.Ptr.all's type might want to derive Ada.Finalization.Controlled. To allow this, you might want to make Food_T an interface so that a Food_T-deriving type can also derive from Ada.Finalization.Controlled.)

like image 67
chs Avatar answered Jan 23 '26 19:01

chs