comp.lang.ada
 help / color / mirror / Atom feed
* Equivalent of dynamic_cast (downcast) for tagged types
@ 2011-01-27 15:46 Maciej Sobczak
  2011-01-27 16:18 ` Dmitry A. Kazakov
  2011-01-27 19:33 ` Equivalent of dynamic_cast (downcast) for tagged types Adam Beneschan
  0 siblings, 2 replies; 25+ messages in thread
From: Maciej Sobczak @ 2011-01-27 15:46 UTC (permalink / raw)


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<T*>(&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



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

end of thread, other threads:[~2011-01-31 10:42 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-27 15:46 Equivalent of dynamic_cast (downcast) for tagged types Maciej Sobczak
2011-01-27 16:18 ` Dmitry A. Kazakov
2011-01-27 17:10   ` J-P. Rosen
2011-01-27 17:35     ` Dmitry A. Kazakov
2011-01-27 22:49     ` Maciej Sobczak
2011-01-27 17:50   ` Georg Bauhaus
2011-01-27 22:35   ` Maciej Sobczak
2011-01-28  5:07     ` Yannick Duchêne (Hibou57)
2011-01-28  9:16     ` Dmitry A. Kazakov
2011-01-28 13:11       ` AdaMagica
2011-01-28 14:13         ` Dmitry A. Kazakov
2011-01-28 23:51           ` Randy Brukardt
2011-01-29  0:55             ` Adam Beneschan
2011-01-28 16:44       ` Adam Beneschan
2011-01-28 17:21         ` Dmitry A. Kazakov
2011-01-29  0:12           ` Randy Brukardt
2011-01-29  8:47             ` Dmitry A. Kazakov
2011-01-28 17:33         ` Adam Beneschan
2011-01-28 15:13     ` Maciej Sobczak
2011-01-28 17:47       ` Robert A Duff
2011-01-28 22:04         ` Maciej Sobczak
2011-01-30 20:22           ` Stephen Leake
2011-01-31  9:04             ` AdaCore, user community and communication channels Maciej Sobczak
2011-01-31 10:42               ` Georg Bauhaus
2011-01-27 19:33 ` Equivalent of dynamic_cast (downcast) for tagged types Adam Beneschan

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