comp.lang.ada
 help / color / mirror / Atom feed
From: mhamel_98@yahoo.com
Subject: Learning tagged types
Date: Fri, 22 Feb 2008 15:23:37 -0800 (PST)
Date: 2008-02-22T15:23:37-08:00	[thread overview]
Message-ID: <31ec7e11-3cd0-4f3c-ad11-c06e7edfb9cb@e10g2000prf.googlegroups.com> (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;



             reply	other threads:[~2008-02-22 23:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-22 23:23 mhamel_98 [this message]
2008-02-23  0:04 ` Learning tagged types Adam Beneschan
2008-02-25 19:48   ` mhamel_98
replies disabled

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