comp.lang.ada
 help / color / mirror / Atom feed
* Learning tagged types
@ 2008-02-22 23:23 mhamel_98
  2008-02-23  0:04 ` Adam Beneschan
  0 siblings, 1 reply; 3+ messages in thread
From: mhamel_98 @ 2008-02-22 23:23 UTC (permalink / raw)


Hello, this is a representative bit of code I use and, experimenting
with tagged types, want to know if/how this can be cleanly moved to a
more object oriented format.  I think I want proc and def to be
abstract procedures, that requires the "object" Proc_Def itself to be
abstract, that means declaring new packages everytime I have a new
Proc_Def?  Thanks for any pointers (no pun intended),

with Text_Io;
with Ada.Containers.Doubly_Linked_Lists;

procedure Tag_Test2 is

  type Proc_Def;

  type Proc_Ptr is access procedure (Def : Proc_Def;
                                     Val : Float);
  type Term_Ptr is access procedure (Def : Proc_Def);

  type Proc_Def is
    record
      Name : String (1 .. 4);
      Proc : Proc_Ptr;
      Term : Term_Ptr;
    end record;

  package DLL is new Ada.Containers.Doubly_Linked_Lists (Proc_Def);
  Proc_List : DLL.List;

  procedure Insert_Proc (Def : Proc_Def) is
  begin
    Proc_List.Append (Def);
  end Insert_Proc;

  function Retrieve_Proc return Proc_Def is
  begin
    return Proc_List.First_Element;
  end Retrieve_Proc;

  procedure Proc1 (Def : Proc_Def;
                   Val : Float) is
  begin
    Text_Io.Put_Line (Def.Name & ": processing - " & Val'Img);
  end Proc1;

  procedure Term1 (Def : Proc_Def) is
  begin
      Text_Io.Put_Line (Def.Name & ": shutting down");
  end Term1;

  Test_Proc : Proc_Def;

begin
  Insert_Proc (("test", Proc1'access, Term1'access));
  Test_Proc := Retrieve_Proc;
  Test_Proc.Proc (Test_Proc, 5.0);
  Test_Proc.Term (Test_Proc);
end Tag_Test2;



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

end of thread, other threads:[~2008-02-25 19:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-22 23:23 Learning tagged types mhamel_98
2008-02-23  0:04 ` Adam Beneschan
2008-02-25 19:48   ` mhamel_98

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