[GiNaC-list] new tinfo method makes is_a less efficient
Diego Conti
diego.conti at unimib.it
Mon Sep 10 16:26:49 CEST 2007
Hi,
I'm a mathematician and I find GiNaC very useful for doing calculations.
Unfortunately, the new tinfo mechanism in version 1.4.0 breaks my code,
and I am not sure how to fix that. Basically, what I need is an
efficient version of is_a (actually, is_a<ncmul>) that does not rely on
dynamic_cast.
With the old tinfo method, I could simply redefine:
template<> inline bool is_a<ncmul>(const basic & obj)
{
return (obj.tinfo()&TINFO_MASK)==TINFO_ncmul;
}
where TINFO_MASK is the constant 0x001fffffU, and the classes I derived
from ncmul had appropriate tinfo constants.
With the new method, where the tinfo_key is a pointer, the above code
does not work. One obvious alternative is the following:
struct tinfo_static_t
<http://www.ginac.de/reference/structGiNaC_1_1tinfo__static__t.html>
{
const tinfo_static_t* derives_from; //NULL if derived from void,
otherwise points to tinfo_static member in superclass
<http://www.ginac.de/reference/structGiNaC_1_1tinfo__static__t.html>
};
typedef const tinfo_static_t * tinfo_t;
and then
template <class T>
inline bool is_a(const basic &obj)
{
const tinfo_static_t* tinfo=obj.tinfo();
do
{
if (tinfo==&T::tinfo_static) return true;
tinfo = tinfo->derives_from
<http://www.ginac.de/reference/structGiNaC_1_1tinfo__static__t.html>;
} while (tinfo!=NULL);
return false;
}
This appears reasonably efficient, but it will not work because, for
instance, add::return_type_tinfo
<http://www.ginac.de/reference/classGiNaC_1_1add.html#b2>() can return
this, which can be converted to a pointer to void but not to a pointer
to tinfo_static_t. I really do not understand the meaning of this
choice. Can someone explain? What would I need to change in order to
make the above code work?
Thanks in advance
Diego Conti
More information about the GiNaC-list
mailing list