comp.lang.ada
 help / color / mirror / Atom feed
* Both Ada.Finalization.Limited_Controlled and Ada.Finalization.Controlled
@ 2014-07-25 18:09 Victor Porton
  2014-07-25 19:25 ` Victor Porton
  2014-07-25 19:52 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 3+ messages in thread
From: Victor Porton @ 2014-07-25 18:09 UTC (permalink / raw)


I have implemented the following package to wrap pointers to C records:

with Ada.Finalization;

generic
   type Record_Type; -- It should be an untagged record for C compatibility
package RDF.Auxilary.Handled_Record is

   type Access_Type is access Record_Type
      with Convention=>C;

   -- It is logically abstract, but not exactly abstract in Ada sense.
   -- It can't be abstract because the function From_Handle returns this type.
   type Base_Object is new Ada.Finalization.Limited_Controlled with private;

   overriding procedure Initialize(Object: in out Base_Object);

   overriding procedure Finalize(Object: in out Base_Object);

   not overriding function Get_Handle(Object: Base_Object) return Access_Type with Inline;

   not overriding function From_Handle(Handle: Access_Type) return Base_Object with Inline;

   not overriding function Default_Handle(Object: Base_Object) return Access_Type;

   not overriding procedure Finalize_Handle(Object: Base_Object; Handle: Access_Type) is null;

private

   type Base_Object is new Ada.Finalization.Limited_Controlled with
      record
         Handle: Access_Type;
      end record;

end RDF.Auxilary.Handled_Record;

I think you guess what the body is, but if you don't look into
https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-auxilary-handled_record.ads
https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-auxilary-handled_record.adb

Now I want to create a similar generic package with

type Base_Object is new Ada.Finalization.Controlled with private;

and a function to create a copy handle:

function Copy(Handle: Access_Type) return Access_Type is null;

and

procedure Adjust(Object : in out Base_Object) is
begin
   if Object.Handle /= null
      Object.Handle = Copy (Object.Handle);
   end if;
end;

My question: Is it possible to implement without duplicating code for both
Ada.Finalization.Limited_Controlled and Ada.Finalization.Controlled?

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-25 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-25 18:09 Both Ada.Finalization.Limited_Controlled and Ada.Finalization.Controlled Victor Porton
2014-07-25 19:25 ` Victor Porton
2014-07-25 19:52 ` Dmitry A. Kazakov

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