From: julius_bip@yahoo.com (Julio Cano)
Subject: Re: How do I create an object instance from a tag?
Date: 20 Feb 2003 07:38:21 -0800
Date: 2003-02-20T15:38:21+00:00 [thread overview]
Message-ID: <8fe0b883.0302200738.35e427f9@posting.google.com> (raw)
In-Reply-To: yyb4a.155282$vm2.110486@rwcrnsc54
"Steve" <nospam_steved94@attbi.com> wrote in message news:<yyb4a.155282$vm2.110486@rwcrnsc54>...
> I would like to create a function that returns a reference to a class wide
> object based on the external name. Something along the lines of:
>
> function Create_Object( external_name : String ) return objAcc is
> returnTag : Ada.Tags.Tag;
> begin
> returnTag := Ada.Tags.Internal_Tag( external_name );
> return ??? some function of returnTag ???
> end Create_Object;
>
> Can this be done?
>
It depends on what you actually want. You can have "some function of
returnTag" if you have already registered the tagged type constructor
with its tag.
You can do this with a tagged type hierarchy. Just define the
constructor like this:
function create return obj_class_acc
being
type obj_class_acc is access obj'class
Defining all subtypes constructors like this:
function create return obj_class_acc is
begin
return new derived_obj'class;
end;
Note return type is obj_class_acc (base type).
Now you can "register" all the constructors in a package:
type constr_func is access function return obj_class_acc;
procedure register_constructor (type_name: string;
constructor: constr_func);
and look for the constructor like this:
function objectforname(type_name: string) return constr_func;
Register somewhere (i.e: in the package of the type)
register_constructor("this_class_name", constructor'access);
And create object based in its name:
my_obj : obj_class_acc := objectforname("this_class_name").all;
do_something(my_obj.all);
This solution is obviously restricted to a hierarchy, and
obj_class_acc most be the base type.
I think that one of the problems here is the lack of a generic base
type like (Object in Java, Id in Objective-C, ...). That kind of base
type or generic access type would help to implement a more generic
(and may be more dangerous) solution.
> I've perused the rationale and the RM and haven't run across anything.
>
> Steve
> (The Duck)
next prev parent reply other threads:[~2003-02-20 15:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-17 20:25 How do I create an object instance from a tag? Steve
2003-02-18 8:29 ` Dmitry A. Kazakov
2003-02-18 18:14 ` Randy Brukardt
2003-02-19 2:27 ` Steve
2003-02-19 9:18 ` Dmitry A. Kazakov
2003-02-20 15:38 ` Julio Cano [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-02-19 9:39 Grein, Christoph
2003-02-19 13:26 ` Dmitry A. Kazakov
2003-02-19 18:36 ` Randy Brukardt
2003-02-20 9:15 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox