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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f428ff2031155951,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!e9g2000vbi.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Equivalent of dynamic_cast (downcast) for tagged types Date: Thu, 27 Jan 2011 07:46:33 -0800 (PST) Organization: http://groups.google.com Message-ID: <375fb596-ab12-4cb0-a190-53d62b94b2e4@e9g2000vbi.googlegroups.com> NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1296143194 11395 127.0.0.1 (27 Jan 2011 15:46:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 27 Jan 2011 15:46:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e9g2000vbi.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17708 Date: 2011-01-27T07:46:33-08:00 List-Id: Hi, Unfortunately I need to HACK some equivalent of dynamic_cast in Ada. There is a limited tagged type T deriving from Limited_Controlled and Some_Interface as well. There is also a procedure like this: procedure Foo (X : in Some_Interface'Class); Inside Foo I would like to check if X is indeed T and if so, I would like to dynamic_cast to it and execute some operation on T. That operation is in fact declared in Some_Interface anyway, but I would like to avoid the dispatching call. I would also like to avoid any potential data copying, so access types are welcome. In C++ it would look like this: void foo(some_interface & x) { T * p = dynamic_cast(&x); if (p != NULL) { // indeed x is of type T p->do_something_for_me(); } } If you say that I should not do this because it is not good practice, then I will quickly answer that GNAT should not randomly call Adjust on my limited (!) objects. Thank you for your help. -- Maciej Sobczak * http://www.inspirel.com