From e0957537cd0938313803c290a2f3922a3889e6f1 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 1 Oct 2017 17:49:26 +0200 Subject: Removed all GSList occurences in .h files --- src/extension/param/enum.cpp | 32 ++------- src/extension/param/enum.h | 18 +++++- src/extension/param/notebook.cpp | 125 ++++++++++++------------------------ src/extension/param/notebook.h | 29 ++++++++- src/extension/param/radiobutton.cpp | 36 +++-------- src/extension/param/radiobutton.h | 20 +++++- 6 files changed, 119 insertions(+), 141 deletions(-) (limited to 'src/extension/param') diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 7cd860465..db34a6ef9 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -32,20 +32,6 @@ namespace Inkscape { namespace Extension { -/* For internal use only. - Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class enumentry { -public: - enumentry (Glib::ustring &val, Glib::ustring &text) : - value(val), - text(text) - {} - - Glib::ustring value; - Glib::ustring text; -}; - - ParamComboBox::ParamComboBox(const gchar * name, const gchar * text, const gchar * description, @@ -55,7 +41,6 @@ ParamComboBox::ParamComboBox(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) , _value(NULL) - , choices(NULL) { const char *xmlval = NULL; // the value stored in XML @@ -93,7 +78,7 @@ ParamComboBox::ParamComboBox(const gchar * name, } if ( (!newtext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here - choices = g_slist_append( choices, new enumentry(newvalue, newtext) ); + choices.push_back(new enumentry(newvalue, newtext) ); } } } @@ -120,11 +105,9 @@ ParamComboBox::ParamComboBox(const gchar * name, ParamComboBox::~ParamComboBox (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast(list->data)); + for (auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -151,8 +134,7 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape } Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast(list->data); + for (auto entr:choices) { if ( !entr->text.compare(in) ) { settext = entr->value; break; // break out of for loop @@ -181,8 +163,7 @@ bool ParamComboBox::contains(const gchar * text, SPDocument const * /*doc*/, Ink return false; /* Can't have NULL string */ } - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast(list->data); + for (auto entr:choices) { if ( !entr->text.compare(text) ) return true; } @@ -256,8 +237,7 @@ Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * n ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast(list->data); + for (auto entr:choices) { Glib::ustring text = entr->text; combo->append(text); diff --git a/src/extension/param/enum.h b/src/extension/param/enum.h index 143a648d7..d34c0dcaa 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -34,7 +34,23 @@ private: been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + * Note that value and text MUST be non-NULL. + * This is ensured by newing only at one location in the code where non-NULL checks are made. + */ + class enumentry { + public: + enumentry (Glib::ustring &val, Glib::ustring &text) : + value(val), + text(text) + {} + + Glib::ustring value; + Glib::ustring text; + }; + + std::vector choices; /**< A table to store the choice strings */ public: ParamComboBox(const gchar * name, diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 4e94b5216..220d6eb32 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -42,34 +42,7 @@ namespace Inkscape { namespace Extension { -/** - * A class to represent the pages of a notebookparameter of an extension. - */ -class ParamNotebookPage : public Parameter { -private: - GSList * parameters; /**< A table to store the parameters for this page. - This only gets created if there are parameters on this - page */ - -public: - static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - ParamNotebookPage(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamNotebookPage(void); - - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - void paramString (std::list &list); - gchar * get_text (void) {return _text;}; - Parameter * get_param (const gchar * name); -}; /* class ParamNotebookPage */ - - -ParamNotebookPage::ParamNotebookPage(const gchar * name, +ParamNotebook::ParamNotebookPage::ParamNotebookPage(const gchar * name, const gchar * text, const gchar * description, bool hidden, @@ -77,7 +50,6 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, /*indent*/ 0, ext) { - parameters = NULL; // Read XML to build page if (xml != NULL) { @@ -92,28 +64,25 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { Parameter * param; param = Parameter::make(child_repr, ext); - if (param != NULL) parameters = g_slist_append(parameters, param); + if (param != NULL) parameters.push_back(param); } child_repr = child_repr->next(); } } } -ParamNotebookPage::~ParamNotebookPage (void) +ParamNotebook::ParamNotebookPage::~ParamNotebookPage (void) { //destroy parameters - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast(list->data); + for (auto param:parameters) { delete param; } - g_slist_free(parameters); } /** Return the value as a string. */ -void ParamNotebookPage::paramString(std::list &list) +void ParamNotebook::ParamNotebookPage::paramString(std::list &list) { - for (GSList * plist = parameters; plist != NULL; plist = g_slist_next(plist)) { - Parameter * param = reinterpret_cast(plist->data); + for (auto param:parameters) { param->string(list); } } @@ -143,8 +112,8 @@ void ParamNotebookPage::paramString(std::list &list) straight forward. In all cases the value is set to the default value from the XML and the type is set to the interpreted type. */ -ParamNotebookPage * -ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) +ParamNotebook::ParamNotebookPage * +ParamNotebook::ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) { const char * name; const char * text; @@ -186,7 +155,7 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: * * Builds a notebook page (a vbox) and puts parameters on it. */ -Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) { if (_hidden) { return NULL; @@ -197,8 +166,7 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod vbox->set_spacing(Parameter::GUI_BOX_SPACING); // add parameters onto page (if any) - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast(list->data); + for (auto param:parameters) { Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); if (widg) { int indent = param->get_indent(); @@ -224,6 +192,28 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod return dynamic_cast(vbox); } +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +{ + if (name == NULL) { + throw Extension::param_not_exist(); + } + if (this->parameters.empty()) { + // the list of parameters is empty + throw Extension::param_not_exist(); + } + + for (auto param:parameters) { + if (!strcmp(param->name(), name)) { + return param; + } + } + + return NULL; +} + +/** End ParamNotebookPage **/ +/** ParamNotebook **/ ParamNotebook::ParamNotebook(const gchar * name, const gchar * text, @@ -234,8 +224,6 @@ ParamNotebook::ParamNotebook(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) { - pages = NULL; - // Read XML tree to add pages: if (xml != NULL) { Inkscape::XML::Node *child_repr = xml->firstChild(); @@ -249,7 +237,7 @@ ParamNotebook::ParamNotebook(const gchar * name, if (!strcmp(chname, "page")) { ParamNotebookPage * page; page = ParamNotebookPage::makepage(child_repr, ext); - if (page != NULL) pages = g_slist_append(pages, page); + if (page != NULL) pages.push_back(page); } child_repr = child_repr->next(); } @@ -258,9 +246,8 @@ ParamNotebook::ParamNotebook(const gchar * name, // Initialize _value with the current page const char * defaultval = NULL; // set first page as default - if (pages != NULL) { - ParamNotebookPage * defpage = reinterpret_cast(pages->data); - defaultval = defpage->name(); + if (!pages.empty()) { + defaultval = pages[0]->name(); } gchar * pref_name = this->pref_name(); @@ -277,12 +264,9 @@ ParamNotebook::ParamNotebook(const gchar * name, ParamNotebook::~ParamNotebook (void) { //destroy pages - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { - ParamNotebookPage * page = reinterpret_cast(list->data); + for (auto page:pages) { delete page; } - g_slist_free(pages); - g_free(_value); } @@ -304,12 +288,8 @@ ParamNotebook::~ParamNotebook (void) */ const gchar *ParamNotebook::set(const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { - ParamNotebookPage * page = NULL; - int i = 0; - for (GSList * list = pages; (list != NULL) && (i <= in); list = g_slist_next(list)) { - page = reinterpret_cast(list->data); - i++; - } + int i = in < pages.size() ? in : pages.size()-1; + ParamNotebookPage * page = pages[i]; if (page == NULL) return _value; @@ -336,8 +316,7 @@ void ParamNotebook::string(std::list &list) const param_string += "\""; list.insert(list.end(), param_string); - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast(pglist->data); + for (auto page:pages) { page->paramString(list); } } @@ -384,8 +363,7 @@ Parameter *ParamNotebook::get_param(const gchar * name) if (name == NULL) { throw Extension::param_not_exist(); } - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast(pglist->data); + for (auto page:pages) { Parameter * subparam = page->get_param(name); if (subparam) { return subparam; @@ -395,26 +373,6 @@ Parameter *ParamNotebook::get_param(const gchar * name) return NULL; } -/** Search the parameter's name in the page content. */ -Parameter *ParamNotebookPage::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(list->data); - if (!strcmp(param->name(), name)) { - return param; - } - } - - return NULL; -} /** * Creates a Notebook widget for a notebook parameter. @@ -432,9 +390,8 @@ Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * // add pages (if any) int i = -1; int pagenr = i; - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { + for (auto page:pages) { i++; - ParamNotebookPage * page = reinterpret_cast(list->data); Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); nb->append_page(*widg, _(page->get_text())); if (!strcmp(_value, page->name())) { diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h index 8475de61d..f1bebd372 100644 --- a/src/extension/param/notebook.h +++ b/src/extension/param/notebook.h @@ -37,7 +37,34 @@ private: */ gchar * _value; - GSList * pages; /**< A table to store the pages with parameters for this notebook. + /** + * A class to represent the pages of a notebookparameter of an extension. + */ + class ParamNotebookPage : public Parameter { + private: + std::vector parameters; /**< A table to store the parameters for this page. + This only gets created if there are parameters on this + page */ + + public: + static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); + + ParamNotebookPage(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~ParamNotebookPage(void); + + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + void paramString (std::list &list); + gchar * get_text (void) {return _text;}; + Parameter * get_param (const gchar * name); + }; /* class ParamNotebookPage */ + + + std::vector pages; /**< A table to store the pages with parameters for this notebook. This only gets created if there are pages in this notebook */ public: diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index a08ba6860..ca6dbb31d 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -42,20 +42,6 @@ namespace Extension { /* For internal use only. Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class optionentry { -public: - optionentry (Glib::ustring * val, Glib::ustring * txt) { - value = val; - text = txt; - } - ~optionentry() { - delete value; - delete text; - } - - Glib::ustring * value; - Glib::ustring * text; -}; ParamRadioButton::ParamRadioButton(const gchar * name, const gchar * text, @@ -68,7 +54,6 @@ ParamRadioButton::ParamRadioButton(const gchar * name, : Parameter(name, text, description, hidden, indent, ext) , _value(0) , _mode(mode) - , choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); @@ -105,7 +90,7 @@ ParamRadioButton::ParamRadioButton(const gchar * name, } if ( (newtext) && (newvalue) ) { // logical error if this is not true here - choices = g_slist_append( choices, new optionentry(newvalue, newtext) ); + choices.push_back(new optionentry(newvalue, newtext)); } } child_repr = child_repr->next(); @@ -115,8 +100,8 @@ ParamRadioButton::ParamRadioButton(const gchar * name, // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (choices) { - defaultval = (static_cast (choices->data))->value->c_str(); + if (!choices.empty()) { + defaultval = (static_cast (choices[0]))->value->c_str(); } gchar * pref_name = this->pref_name(); @@ -135,11 +120,9 @@ ParamRadioButton::ParamRadioButton(const gchar * name, ParamRadioButton::~ParamRadioButton (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast(list->data)); + for(auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -166,8 +149,7 @@ const gchar *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inksc } Glib::ustring * settext = NULL; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast(list->data); + for (auto entr:choices) { if ( !entr->value->compare(in) ) { settext = entr->value; break; // break out of for loop @@ -278,8 +260,7 @@ Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) { Glib::ustring value = ""; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast(list->data); + for ( auto entr:choices) { if ( !entr->text->compare(label) ) { value = *(entr->value); break; @@ -319,8 +300,7 @@ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node // add choice strings as radiobuttons // and select last selected option (_value) Gtk::RadioButtonGroup group; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast(list->data); + for (auto entr:choices) { Glib::ustring * text = entr->text; switch ( _mode ) { case MINIMAL: diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index b91b11ea3..e3ced8eb8 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -27,6 +27,7 @@ namespace Extension { class Extension; + // \brief A class to represent a radiobutton parameter of an extension class ParamRadioButton : public Parameter { public: @@ -63,7 +64,24 @@ private: It is the value of the current selected string */ gchar * _value; AppearanceMode _mode; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ + class optionentry { + public: + optionentry (Glib::ustring * val, Glib::ustring * txt) { + value = val; + text = txt; + } + ~optionentry() { + delete value; + delete text; + } + Glib::ustring * value; + Glib::ustring * text; + }; + + std::vector choices; /**< A table to store the choice strings */ }; /* class ParamRadioButton */ -- cgit v1.2.3