[Click] dynamic_cast ?
Eddie Kohler
kohler at cs.ucla.edu
Thu Nov 5 11:12:08 EST 2009
Hi Harald,
Click already provides a cast() method on Element that should do what
you want.
http://www.read.cs.ucla.edu/click/doxygen/classElement.html#e19904c6060f3d4411e32cba0dd2e3c1
So something like
Foo *foo = (Foo *) output(0).element()->cast("Foo");
Eddie
Harald Schiöberg wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Michael Neufeld wrote:
>> Last time I looked Linux kernel mode Click disables RTTI (as well as
>> exceptions), so I wouldn't expect dynamic_cast to work in the Linux kernel.
>>
>> -Mike
>
> Thanks, that's what I almost anticipated. Is there any other solution
> that does the same thing in click, some method of Element that one can
> use? Basically I need to find out at initialization time whether my
> neighbor elements are derived from a special subclass of element.
>
> The "dirty" way would be to implement a "i_am_foo" handler and check for
> it's existence....
>
> harald
>
>> Harald Schiöberg wrote:
>> does anyone know whether this is safe to do in click ?
>>
>> class Foo : public Element { ... }
>> class FooBar : public Foo { ... }
>>
>> Foo::some_method() {
>> Element downstream;
>> downstream = output[0].element();
>>
>> if ( dynamic_cast<Foo>(e) ) {
>> ... e is a foo ...
>> } else {
>> .... e is not a foo ...
>> }
>> }
>>
>> I currently have no linuxkernel installation, so I can't check for this
>> case, but I see potential breakage, since this requires a bit of
>> compiler magic.
>>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>
> - --
> Harald Schiöberg
> Technische Universität Berlin | T-Laboratories | FG INET
> www: http://www.net.t-labs.tu-berlin.de
> Phone: +49-(0)30-8353-58476 | Fax: +49-(0)391 534 783 47
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFK8uV/y8wrZ9OvkU0RAlQKAJ455Y1L/Dpjg6rJGsMdQjBNU/H+QQCgy68X
> KNaJEw1BRaQ1y27PPzaaR5o=
> =pIrY
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
More information about the click
mailing list