comp.lang.ada
 help / color / mirror / Atom feed
* Q: How to declare object with known tag?
@ 1996-06-04  0:00 John Woodruff
  1996-06-05  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: John Woodruff @ 1996-06-04  0:00 UTC (permalink / raw)



I hope one of the Ada experts will advise me how to write the following
code fragment.

I would like to declare an object of a particular type, where the type
is a tagged record, and I can specify which tag at run-time.  Here is
the fragment I would like to build:


declare 
   Trial_Tag : Ada.Tags.Tag ;
   type Trial_Type is access all Some_Tag.Base'Class ;
   Trial : Trial_Type ;
begin

   Trial_Tag := Ada.Tags.Internal_Tag ("SOME_TAG.EXTEND21") ; 
-- Let user input specify the string argument to Internal_Tag --

   Trial := new SOMETHING -- I dont know what ; 
-- Trial.all is to be an instance of some_tag.extend21

end ;

The goal: 

I will declare a "heterogenous list" composed of various sub-types of
the type declared in some_tag.  I wish to append a newly-created member
onto the list.

I want to read a user's input to decide which subtype is to be
appended. If I have my way, I'll be able to write the procedure for
recognizing the user's selection *before* all the subtypes have been
declared, because I want to defer the definition of "the last" legitimate
subtype until after the code to accept user selection has been written and
tested.  Of course if the argument to Tags.Internal_Tag is wrong, I'll
remonstrate with my user.

I recognize that the user will need to create the object of (the new
extension) of some_tag.extend21.  But to my thinking, after I have
successfully declared Trial.all in the example, THEN I can dispatch to
the newly extended type to receive the user's input.

Is this a legitimate wish?  If it is not (ie it's illegal to declare a
class-wide access to an object in a code written before the specific
subtype has been declared) -- then what is my alternative?  It would be
inconvenient to declare an enumeration naming all the (future)
extensions that can be appended onto the heterogenious list.

-- 
John Woodruff	                                          N I F   \ ^ /
Lawrence Livermore National Lab                         =====---- < 0 >
510 422 4661                                                      / v \




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-06-05  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-04  0:00 Q: How to declare object with known tag? John Woodruff
1996-06-05  0:00 ` Tucker Taft

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