comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus+rm.tsoh@maps.futureapps.de>
Subject: Re: Universal type
Date: Sat, 04 Aug 2007 01:03:08 +0200
Date: 2007-08-04T01:03:09+02:00	[thread overview]
Message-ID: <1186182188.11376.17.camel@sonnenregen> (raw)
In-Reply-To: <1186165731.373877.257550@i13g2000prf.googlegroups.com>

On Fri, 2007-08-03 at 11:28 -0700, shaunpatterson@gmail.com wrote:
> I'm looking to store different kinds of objects into a vector, queue,
> etc
> 
> In Java, everything is derived from Object.  Is there something
> similar
> in Ada?  I'd like to be able to store Integers, booleans, etc, as
> well
> as custom defined objects.

While I agree with Dmitry and Maciej (that there must be
a reason that Java now has generic containers), if you still
wanted containers to hold objects of types derived from Object,
you could do just the same thing that Java does, and define
an all-emcompassing parent type.

In fact, two Ada compilers do exactly this for running Ada
programs in a JVM. The "Object" type in the RTL of one of
these compilers is

    type Object is tagged limited null record;
    type Object_Ptr is access all Object'Class;

    function hashCode(Obj : access Object) return Integer;

    -- see java.lang.Object_ops package for rest of
    -- "Object" abstraction

Package Object_ops starts

    function getClass(Obj : access Object'Class) return Class_Ptr;

    function toString(Obj : access Object'Class) return String_Ptr;
    function "="(Left: Object'Class; Right : Object'Class) return
Boolean;

    procedure notify(Obj : access Object'Class);

    ...

Since Java objects stored in containers are really references to
heap allocated objects, you would be doing the same using
access values in Ada.





  parent reply	other threads:[~2007-08-03 23:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-03 18:28 Universal type shaunpatterson
2007-08-03 18:31 ` shaunpatterson
2007-08-03 19:10   ` Dmitry A. Kazakov
2007-08-03 20:35     ` Maciej Sobczak
2007-08-03 21:54       ` shaunpatterson
2007-08-04  1:10         ` Jeffrey R. Carter
2007-08-04  7:21       ` Dmitry A. Kazakov
2007-08-03 23:03 ` Georg Bauhaus [this message]
2007-08-05 13:46 ` Martin Krischik
replies disabled

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