summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-12-23 16:01:45 (GMT)
committerSwift Review <review@swift.im>2012-12-23 16:48:15 (GMT)
commit5ccbd7fc3de7afed6c06deb93be3967a7eb5fac2 (patch)
treed57334bf18662d6753a2cb14bff3b192ff3e7a76 /Swift
parentfe5b5e25eadbfe9f8bdaa152b987273ab77d4711 (diff)
downloadswift-5ccbd7fc3de7afed6c06deb93be3967a7eb5fac2.zip
swift-5ccbd7fc3de7afed6c06deb93be3967a7eb5fac2.tar.bz2
Replace functors and for loops by boost::lambdas.
Change-Id: I6d2364dc85464f238d95978793f35953a2947799
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/StatusCache.cpp13
-rw-r--r--Swift/QtUI/QtStatusWidget.cpp15
2 files changed, 13 insertions, 15 deletions
diff --git a/Swift/Controllers/StatusCache.cpp b/Swift/Controllers/StatusCache.cpp
index e77bd55..1569e26 100644
--- a/Swift/Controllers/StatusCache.cpp
+++ b/Swift/Controllers/StatusCache.cpp
@@ -9,11 +9,15 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/fstream.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/ByteArray.h>
#include <SwifTools/Application/ApplicationPathProvider.h>
+namespace lambda = boost::lambda;
+
namespace Swift {
static const size_t MAX_ENTRIES = 200;
@@ -45,14 +49,7 @@ void StatusCache::addRecent(const std::string& text, StatusShow::Type type) {
if (text.empty()) {
return;
}
- for (std::list<PreviousStatus>::iterator i = previousStatuses_.begin(); i != previousStatuses_.end(); ) {
- if ((*i).first == text && (*i).second == type) {
- previousStatuses_.erase(i++);
- }
- else {
- ++i;
- }
- }
+ previousStatuses_.remove_if(lambda::bind(&PreviousStatus::first, lambda::_1) == text && lambda::bind(&PreviousStatus::second, lambda::_1) == type);
previousStatuses_.push_front(PreviousStatus(text, type));
for (size_t i = previousStatuses_.size(); i > MAX_ENTRIES; i--) {
previousStatuses_.pop_back();
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index 1899b71..8cc366a 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -6,6 +6,10 @@
#include "QtStatusWidget.h"
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+
#include <QBoxLayout>
#include <QComboBox>
#include <QLabel>
@@ -25,6 +29,8 @@
#include <Swift/Controllers/StatusUtil.h>
#include <Swift/Controllers/StatusCache.h>
+namespace lambda = boost::lambda;
+
namespace Swift {
QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWidget(parent), statusCache_(statusCache), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) {
@@ -144,13 +150,8 @@ void QtStatusWidget::generateList() {
}
std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
- bool breakEarly = false;
- foreach (StatusShow::Type type, allTypes_) {
- if (savedStatus.first.empty() || (savedStatus.second == type && savedStatus.first == statusShowTypeToFriendlyName(type))) {
- breakEarly = true;
- }
- }
- if (breakEarly) {
+ if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(),
+ savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) {
continue;
}
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);