From: woodruff@tanana.llnl.gov (John Woodruff)
Subject: Q: How to declare object with known tag?
Date: 1996/06/04
Date: 1996-06-04T00:00:00+00:00 [thread overview]
Message-ID: <WOODRUFF.96Jun4091215@tanana.llnl.gov> (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 \
next reply other threads:[~1996-06-04 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-06-04 0:00 John Woodruff [this message]
1996-06-05 0:00 ` Q: How to declare object with known tag? Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox