
Quoting Kees Cook <inkscape@...62...>:
I found SPCSSAttr, but it doesn't seem to have anything in common with SPRepr. Am I blind? (repr-css.cpp) It's an Inkscape::XML::SimpleNode, which does have an attributeList. Maybe this is just the wrong cast?
Well, yes and no. XML::SimpleNode implements the abstract class SPRepr.
[ SPCSSAttr isa XML::SimpleNode isa SPRepr ]
HOWEVER, XML::SimpleNode is an implementation class. It should ****NOT**** be exposed to any code outside src/xml/, so please don't do this...
if (dynamic_cast<Inkscape::XML::SimpleNode *>(css)->attributeList() ==
NULL)
SPRepr is the public interface; use that. The general idea behind the original code was correct ... you want to do SPRepr things with a SPCSSAttr, which (indirectly) isa SPRepr. It was just the methedology that was fragile...
Ideally the way this should work is that SPCSSAttr would also be an abstract class that extends SPRepr (see SPReprDoc for an example of this). We could then make enough information available for the compiler to see that SPCSSAttr isa SPRepr without exposing the actual class implementing SPCSSAttr, so no cast would be required at all.
There would be some implementation class behind it (SimpleNode-derived or not), but nobody outside repr-css.cpp would need to know about that.
desktop-style.cpp: In function `SPCSSAttr* sp_desktop_get_style(SPDesktop*, bool)': desktop-style.cpp:167: error: cannot dynamic_cast `css' (of type `struct SPCSSAttr*') to type `class Inkscape::XML::SimpleNode*' (source is a pointer to incomplete type)
"incomplete type" means that the full definition of the type (SPCSSAttr in this case) is not visible to the compiler at that location (in this case because it is located in src/xml/repr-css.cpp).
What can I try next?
The quickest thing would simply be to rework the sp_repr_css_* functions to take and return SPRepr * rather than SPCSSAttr * (i.e. typedef SPRepr SPCSSAttr, and rename the class in repr-css.cpp). You'd need to get rid of some unused forward declarations of SPCSSAttr too.
I'm going to go ahead and do it right tonight though.
-mental