Hello! First of all, it would be nice to see the actual code which proves $subject. On Mon, Sep 10, 2007 at 04:26:49PM +0200, Diego Conti wrote:
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; }
I think such a redifinition might break some GiNaC classes...
where TINFO_MASK is the constant 0x001fffffU, and the classes I derived from ncmul had appropriate tinfo constants.
... but anyway, is it really faster?
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> };
Ugh, now every object (even a symbol) carries information about relationship between _all_ GiNaC classes. Not so nice.
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,
Yes, but I doubt it will be any better than dynamic_cast. It uses very similar technique (see e.g. <cxxabi.h> from GNU libstdc++). Best regards, Alexei. -- All science is either physics or stamp collecting.