
Ideally we can get to the situation where we don't need dynamic_cast<> at
all, and code will just work directly with standard C++ inheritance. Be careful, Johan's gonna laugh at you ;) . I said exactly that some time ago... look for "Code style question".
-----Ursprüngliche Nachricht----- Von: Jon Cruz [mailto:jon@...18...] Gesendet: Freitag, 28. Februar 2014 01:18 An: Markus Engel; Johan Engelen Cc: Inkscape Devel List Betreff: Re: [Inkscape-devel] Casting-macro replacement
On Feb 27, 2014, at 3:21 PM, Markus Engel wrote:
I think this custom cast is only necessary as long as there are any GLists
present. After that we may just use dynamic_cast directly.
If the source pointers are correctly typed, the compiler will throw an
error on any of the cases the two static_asserts handle.
Currently, they are only there to guard against mistakes in the
static_cast to ToolBase*. Thats why I directly added it there.
Ideally we can get to the situation where we don't need dynamic_cast<> at all, and code will just work directly with standard C++ inheritance.
In the immediate term, one would like to perhaps just have
PenTool *pc = dynammic_cast<PenTool *>(desktop->event_context); if (pc) { ... } (note that the 'if' and check are dropped, and inspecting the returned pointer for validity then suffices).
Then we should look at cleaning things up so that random down-casting is no longer needed. Much of that is from a C approach to coding, and is not the most efficient for C++.