From 5fd00cab14d48beaf2279a2b8f3ad5b02b76c87b Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 19 Feb 2015 04:25:21 +0100 Subject: Put a few std::vector (bzr r13922.1.5) --- src/path-chemistry.cpp | 73 +++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'src/path-chemistry.cpp') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index a5e71b720..ae1e0064f 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -51,13 +51,19 @@ inline bool less_than_objects(SPObject const *first, SPObject const *second) second->getRepr())<0; } +inline bool less_than_items(SPItem const *first, SPItem const *second) +{ + return sp_repr_compare_position(first->getRepr(), + second->getRepr())<0; +} + void sp_selected_path_combine(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to combine.")); @@ -70,23 +76,22 @@ sp_selected_path_combine(SPDesktop *desktop) items = sp_degroup_list (items); // descend into any groups in selection - SelContainer to_paths; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + std::vector to_paths; + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++) { SPItem *item = (SPItem *) (*i); if (!dynamic_cast(item) && !dynamic_cast(item)) { - to_paths.push_front(item); + to_paths.push_back(item); } } - SelContainer converted; + std::vector converted; bool did = sp_item_list_to_curves(to_paths, items, converted); to_paths.clear(); - for (SelContainer::const_iterator i=converted.begin();i!=converted.end();i++) - items.push_front(doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); + for (std::vector::const_iterator i=converted.begin();i!=converted.end();i++) + items.push_back((SPItem*)doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - items.sort(less_than_objects); - items.reverse(); + sort(items.begin(),items.end(),less_than_objects); assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one @@ -104,7 +109,7 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ SPItem *item = (SPItem *) (*i); SPPath *path = dynamic_cast(item); @@ -206,8 +211,8 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; - SelContainer itemlist(selection->itemList()); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist(selection->itemList()); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = (SPItem *) (*i); @@ -246,7 +251,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) curve->unref(); - SelContainer reprs; + std::vector reprs; for (GSList *l = list; l != NULL; l = l->next) { curve = (SPCurve *) l->data; @@ -272,14 +277,13 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs.push_front(dynamic_cast(repr)); + reprs.push_back(repr); Inkscape::GC::release(repr); } - + //reverse selection->setReprList(reprs); - reprs.clear(); g_slist_free(list); g_free(style); g_free(path_effect); @@ -312,10 +316,10 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - SelContainer selected(selection->itemList()); - SelContainer to_select; + std::vector selected(selection->itemList()); + std::vector to_select; selection->clear(); - SelContainer items(selected); + std::vector items(selected); did = sp_item_list_to_curves(items, selected, to_select); @@ -346,27 +350,24 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - SelContainer selected(selection->itemList()); - SelContainer to_select; + std::vector selected(selection->itemList()); + std::vector to_select; selection->clear(); - SelContainer items(selected); + std::vector items(selected); sp_item_list_to_curves(items, selected, to_select, true); - items.clear(); selection->setReprList(to_select); selection->addList(selected); - to_select.clear(); - selected.clear(); } bool -sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelContainer &to_select, bool skip_all_lpeitems) +sp_item_list_to_curves(const std::vector &items, std::vector& selected, std::vector &to_select, bool skip_all_lpeitems) { bool did = false; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); @@ -399,9 +400,9 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - to_select.push_front(dynamic_cast(repr)); + to_select.push_back(repr); did = true; - selected.remove(item); + selected.erase(find(selected.begin(),selected.end(),item)); } continue; @@ -409,10 +410,10 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon if (group) { group->removeAllPathEffects(true); - SelContainer item_list = sp_item_group_item_list(group); + std::vector item_list = sp_item_group_item_list(group); - SelContainer item_to_select; - SelContainer item_selected; + std::vector item_to_select; + std::vector item_selected; if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; @@ -429,7 +430,7 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon continue; did = true; - selected.remove(item); + selected.erase(find(selected.begin(),selected.end(),item)); // remember the position of the item gint pos = item->getRepr()->position(); @@ -471,7 +472,7 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - to_select.push_front(dynamic_cast(repr)); + to_select.push_back(repr); Inkscape::GC::release(repr); } @@ -613,7 +614,7 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items = selection->itemList(); + std::vector items = selection->itemList(); if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select path(s) to reverse.")); @@ -627,7 +628,7 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPPath *path = dynamic_cast(static_cast(*i)); if (!path) { -- cgit v1.2.3