ROOT7 TDirectory::Find upcast fix

UPDATE
Ok, I’ve had old clone of ROOT repository and this patch is relative to this version of TDirectoryEntry.h. Now developers added TClass* member to track original type. So, my more general solution is redundant now. But I’ll leave original message for the history.

ORIGINAL MESSAGE
Inspired by drdobbs.com/cpp/twisting-the … /229401004, propose I this patch.

TDirectory uses different type erasure scheme than KeyValue (the first link), but I managed to fit that method into it. I intentionally didn’t touch TDirectory::Get, which also cries “FIXME: implement upcast!”, because currently it seem to me that it might require bit more changes, which I’ll left to the original author.

I didn’t test this code in ROOT (even whether it compiles or not, lol).
But I’ve created excerpt with shortened TDirectoryEntryPtr[Base] implementation and some testing code, which is attached here and uploaded to ideone. Despite the fact that excerpt’s tests coverage is not exhaustive, for me it seem to prove the idea. Feel free to write your own tests!

Hope it’ll be helpful.
excerpt.cpp (5.53 KB)
tdirectory_find_upcast.diff (1.58 KB)

For the record, that’s github.com/root-mirror/root/pull/200

Thanks!

Axel.