From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: Q: How to declare object with known tag?
Date: 1996/06/05
Date: 1996-06-05T00:00:00+00:00 [thread overview]
Message-ID: <DsICI9.Cxx.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: WOODRUFF.96Jun4091215@tanana.llnl.gov
John Woodruff (woodruff@tanana.llnl.gov) wrote:
: 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?
Yes, and you can do this approximately by using some_tag.base'Class'Input.
This will read an external tag from a stream, convert it to the
internal tag, and then dispatch to the appropriate some_tag.extendXX'Read
to read the remainder of the data. It will raise Constraint_Error if
the external tag is not recognized.
You can override 'Read for the various type extensions if you want
to recognize a special input format, rather than the normal input format
used by 'Write/'Read.
See "Stream-Oriented Attributes" in RM95 13.13.
: John Woodruff N I F \ ^ /
: Lawrence Livermore National Lab =====---- < 0 >
: 510 422 4661 / v \
--
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Cambridge, MA USA
prev parent reply other threads:[~1996-06-05 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-06-04 0:00 Q: How to declare object with known tag? John Woodruff
1996-06-05 0:00 ` Tucker Taft [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox