From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1e0472f55fc12a52 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-20 07:38:23 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: julius_bip@yahoo.com (Julio Cano) Newsgroups: comp.lang.ada Subject: Re: How do I create an object instance from a tag? Date: 20 Feb 2003 07:38:21 -0800 Organization: http://groups.google.com/ Message-ID: <8fe0b883.0302200738.35e427f9@posting.google.com> References: NNTP-Posting-Host: 80.58.5.107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1045755501 7084 127.0.0.1 (20 Feb 2003 15:38:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 20 Feb 2003 15:38:21 GMT Xref: archiver1.google.com comp.lang.ada:34279 Date: 2003-02-20T15:38:21+00:00 List-Id: "Steve" wrote in message news:... > 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)