diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-23 07:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-23 11:30:02 (GMT) |
commit | e405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch) | |
tree | 9118ef838ebfaec1df90ec24761944b5d833774c /Swift/Controllers/Roster/TableRoster.cpp | |
parent | 8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff) | |
download | swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2 |
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information:
Build on macOS 10.12.1 and all tests pass.
Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Swift/Controllers/Roster/TableRoster.cpp')
-rw-r--r-- | Swift/Controllers/Roster/TableRoster.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp index f164a4d..713f390 100644 --- a/Swift/Controllers/Roster/TableRoster.cpp +++ b/Swift/Controllers/Roster/TableRoster.cpp @@ -1,45 +1,44 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/Roster/TableRoster.h> #include <algorithm> #include <cassert> #include <boost/cast.hpp> #include <boost/numeric/conversion/cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/Timer.h> #include <Swiften/Network/TimerFactory.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> #include <Swift/Controllers/Roster/LeastCommonSubsequence.h> #include <Swift/Controllers/Roster/Roster.h> namespace Swift { struct SectionNameEquals { bool operator()(const TableRoster::Section& s1, const TableRoster::Section& s2) const { return s1.name == s2.name; } }; template<typename T> struct True { bool operator()(const T&, const T&) const { return true; } }; struct ItemEquals { bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const { return i1.jid == i2.jid; } }; struct ItemNeedsUpdate { bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const { @@ -77,65 +76,65 @@ TableRoster::~TableRoster() { if (model) { model->onDataChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); model->onGroupAdded.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); model->onChildrenChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); } } size_t TableRoster::getNumberOfSections() const { return sections.size(); } const std::string& TableRoster::getSectionTitle(size_t section) { return sections[section].name; } size_t TableRoster::getNumberOfRowsInSection(size_t section) const { return sections[section].items.size(); } const TableRoster::Item& TableRoster::getItem(const Index& index) const { return sections[index.section].items[index.row]; } void TableRoster::handleUpdateTimerTick() { updateTimer->stop(); updatePending = false; // Get a model for the new roster std::vector<Section> newSections; if (model) { - foreach(RosterItem* item, model->getRoot()->getDisplayedChildren()) { + for (auto item : model->getRoot()->getDisplayedChildren()) { if (GroupRosterItem* groupItem = boost::polymorphic_downcast<GroupRosterItem*>(item)) { //std::cerr << "* " << groupItem->getDisplayName() << std::endl; Section section(groupItem->getDisplayName()); - foreach(RosterItem* groupChildItem, groupItem->getDisplayedChildren()) { + for (auto groupChildItem : groupItem->getDisplayedChildren()) { if (ContactRosterItem* contact = boost::polymorphic_downcast<ContactRosterItem*>(groupChildItem)) { //std::cerr << " - " << contact->getDisplayJID() << std::endl; section.items.push_back(Item(contact->getDisplayName(), contact->getStatusText(), contact->getDisplayJID(), contact->getStatusShow(), contact->getAvatarPath())); } } newSections.push_back(section); } } } // Do a diff with the previous roster Update update; std::vector<size_t> sectionUpdates; std::vector<size_t> sectionPostUpdates; computeIndexDiff<Section,SectionNameEquals,True<Section> >(sections, newSections, sectionUpdates, sectionPostUpdates, update.deletedSections, update.insertedSections); assert(sectionUpdates.size() == sectionPostUpdates.size()); for (size_t i = 0; i < sectionUpdates.size(); ++i) { assert(sectionUpdates[i] < sections.size()); assert(sectionPostUpdates[i] < newSections.size()); std::vector<size_t> itemUpdates; std::vector<size_t> itemPostUpdates; std::vector<size_t> itemRemoves; std::vector<size_t> itemInserts; computeIndexDiff<Item, ItemEquals, ItemNeedsUpdate >(sections[sectionUpdates[i]].items, newSections[sectionPostUpdates[i]].items, itemUpdates, itemPostUpdates, itemRemoves, itemInserts); size_t end = update.insertedRows.size(); update.insertedRows.resize(update.insertedRows.size() + itemInserts.size()); std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i])); end = update.deletedRows.size(); update.deletedRows.resize(update.deletedRows.size() + itemRemoves.size()); std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i])); |