-----Original Message----- From: Nicolas Dufour [mailto:nicoduf@...48...] Sent: Wednesday, December 01, 2010 11:29 To: Engelen, J.B.C. (Johan); inkscape-devel@lists.sourceforge.net Subject: [Inkscape-devel] Re : Notebooks in internal extensions
Hi Johan,
Thanks for your answer!
De : "J.B.C.Engelen@...1578..." <J.B.C.Engelen@...1578...> Perhaps I can have a look at it this evening. I think
the fix would
be to have the get_param functions do something like a notebookparam->get_param if the extension's parameter is a ParamNotebook. (right?)
It was my first guess, but how do you find the parameter's type from its name (there's no "get_param_type" function or public "type" var in parameter.cpp and notebook.cpp)?
From the top of my head I can think up two solutions:
- Make a virtual get_sub_param function in Extension::Parameter that does nothing. And override that method in Extension::ParamNotebook. - Or (ugly) do dynamic type cast to check for param type ("dynamic_cast<>")
I'd go for the first option, and rewrite Extension::param_shared (and rename to get_param). I find the method somewhat strange. Seems better to me, to rewrite it without using recursion: (not my best piece of code, but I hope the idea is clear)
Parameter * Extension::get_param (const gchar * name) { if (name == NULL) { throw Extension::param_not_exist(); } if (this->parameters == NULL) { // the list of parameters is empty throw Extension::param_not_exist(); }
for (GSList * list = this->parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = static_cast<Parameter*>(list->data); if (!strcmp(param->name(), name)) { return param; } else { Parameter * subparam = param->get_param(name); if (subparam) { return subparam; } } }
// if execution reaches here, no parameter matching 'name' was found throw Extension::param_not_exist(); }
Then for example get_param_string would become: const gchar * Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param;
param = get_param(name); return param->get_string(doc, node); }
Extension::Parameter::get_param(const gchar * /*name*/) { return NULL; }
Extension::ParamNotebook::get_param(const gchar * /*name*/) { here a loop similar to Extension::get_param }
Hope these pieces of (pseudo)code help, Johan