comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: generic type identification
Date: Sat, 04 Jan 2003 16:13:18 GMT
Date: 2003-01-04T16:13:18+00:00	[thread overview]
Message-ID: <yKDR9.27314$p_6.2274825@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: _BAR9.4055$FF4.251139@newsb.telia.net

"David Holm" <david@realityrift.com> wrote in message
news:_BAR9.4055$FF4.251139@newsb.telia.net...
> tmoran@acm.org wrote:
> It is a thick binding to OpenGL. In case you have never seen the OpenGL
API
> it has one procedure for every type you can access it with.
> For instance, glVertex has 24 different declarations depending on whether
> you use (C) floats, doubles, integers, shorts etc and whether your send it
> an array of 2, 3 or 4 coordinates with any of these types.
> I was hoping to be able to create one interface for this in Ada (possibly
by
> using generic instead of overloading every procedure). But then I would
> need to be able to identify which type is used in a call to say
> AdaGL.Primitives.Vertex(some array) so that I know which binding to the C
> library I should convert the parameters to and then call.
>
> Perhaps I could go with something like this?
>
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=8903101703.
AA04518%40ti.com
>

Another possibility is to create an abstract tagged type with one function
and
one procedure. The function will take a primitive (float, integer, etc.) and
convert it to the corresponding tagged type. The procedure will take an
instance of the tagged type and call the appropriate OpenGL binding.

type GL_Binding is abstract tagged null record;
procedure Access_GL(Item : GL_Binding) is abstract;


Each package creating a concrete instance of the tagged type GL_Binding
would also define a function (basically a constructor) creating an instance
of that concrete tagged type from the appropriate scalar type.

type GL_Integer_Binding is new GL_Binding with record
   Value : Integer;
end record;

procedure Access_GL(Item : GL_Integer_Binding);
function Create(Item : Integer) return GL_Integer_Binding;

Do this for each numeric type you need to bind.
Calling the appropriate binding is then very simple.

Pixel_Location :  Integer;
Access_GL(Create(Pixel_Location));

Jim Rogers





  reply	other threads:[~2003-01-04 16:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-04  1:50 generic type identification David Holm
2003-01-04  2:04 ` chris.danx
2003-01-04  5:39 ` tmoran
2003-01-04 12:39   ` David Holm
2003-01-04 16:13     ` James S. Rogers [this message]
2003-01-05  3:28       ` David Holm
2003-01-05 10:03         ` Gautier
2003-01-04 19:27     ` tmoran
2003-01-05  3:25       ` David Holm
2003-01-05  5:42         ` tmoran
2003-01-06 17:56     ` Stephen Leake
replies disabled

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