Skip to content

Commit

Permalink
Replace base::lambda with shorter term.
Browse files Browse the repository at this point in the history
Partially backport dd81f5d
  • Loading branch information
Randl authored and leha-bot committed Jul 27, 2018
1 parent e7bace9 commit 38efa1b
Show file tree
Hide file tree
Showing 151 changed files with 517 additions and 582 deletions.
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/apiwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ApiWrap : private MTP::Sender, private base::Subscriber {
void start();
void applyUpdates(const MTPUpdates &updates, quint64 sentMessageRandomId = 0);

using RequestMessageDataCallback = base::lambda<void(ChannelData *, MsgId)>;
using RequestMessageDataCallback = Fn<void(ChannelData *, MsgId)>;
void requestMessageData(ChannelData *channel, MsgId msgId, RequestMessageDataCallback callback);

void requestFullPeer(PeerData *peer);
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) {
return i.value();
}

void enumerateUsers(base::lambda<void(UserData *)> action) {
void enumerateUsers(Fn<void(UserData *)> action) {
for_const (auto peer, peersData) {
if (auto user = peer->asUser()) {
action(user);
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ inline ChatData *chatLoaded(ChatId chatId) {
inline ChannelData *channelLoaded(ChannelId channelId) {
return channel(channelId, PeerData::FullLoaded);
}
void enumerateUsers(base::lambda<void(UserData *)> action);
void enumerateUsers(Fn<void(UserData *)> action);

UserData *self();
PeerData *peerByName(const QString &username);
Expand Down
4 changes: 0 additions & 4 deletions Telegram/SourceFiles/base/lambda.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org

namespace base {

template <typename Function> using lambda = std::function<Function>;

template <typename Function> using lambda_once = unique_function<Function>;

namespace lambda_internal {

template <typename Lambda> struct lambda_call_type { using type = decltype(&Lambda::operator()); };
Expand Down
9 changes: 3 additions & 6 deletions Telegram/SourceFiles/base/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#pragma once

#include "base/assertion.h"
#include "base/lambda.h"
#include "base/type_traits.h"
#include "core/utils.h"
#include <QSharedPointer>
Expand All @@ -31,16 +30,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace base {
namespace internal {

using ObservableCallHandlers = base::lambda<void()>;
using ObservableCallHandlers = Fn<void()>;
void RegisterPendingObservable(ObservableCallHandlers *handlers);
void UnregisterActiveObservable(ObservableCallHandlers *handlers);
void UnregisterObservable(ObservableCallHandlers *handlers);

template <typename EventType> struct SubscriptionHandlerHelper {
using type = base::lambda<void(parameter_type<EventType>)>;
};
template <typename EventType> struct SubscriptionHandlerHelper { using type = Fn<void(parameter_type<EventType>)>; };

template <> struct SubscriptionHandlerHelper<void> { using type = base::lambda<void()>; };
template <> struct SubscriptionHandlerHelper<void> { using type = Fn<void()>; };

template <typename EventType> using SubscriptionHandler = typename SubscriptionHandlerHelper<EventType>::type;

Expand Down
3 changes: 1 addition & 2 deletions Telegram/SourceFiles/base/task_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once

#include "base/lambda.h"
#include "base/timer.h"
#include <QMutex>
#include <deque>
#include <memory>

namespace base {

using Task = lambda_once<void()>;
using Task = FnMut<void()>;

// An attempt to create/use a TaskQueue or one of the default queues
// after the main() has returned leads to an undefined behaviour.
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/base/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ QObject *TimersAdjuster() {

} // namespace

Timer::Timer(base::lambda<void()> callback)
Timer::Timer(Fn<void()> callback)
: QObject(nullptr)
, _callback(std::move(callback))
, _type(Qt::PreciseTimer)
Expand Down Expand Up @@ -108,7 +108,7 @@ void Timer::timerEvent(QTimerEvent *e) {
}
}

int DelayedCallTimer::call(TimeMs timeout, lambda_once<void()> callback, Qt::TimerType type) {
int DelayedCallTimer::call(TimeMs timeout, FnMut<void()> callback, Qt::TimerType type) {
Expects(timeout >= 0);
if (!callback) {
return 0;
Expand Down
13 changes: 6 additions & 7 deletions Telegram/SourceFiles/base/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once

#include "base/lambda.h"
#include "base/observer.h"

using TimeMs = qint64;
Expand All @@ -29,14 +28,14 @@ namespace base {

class Timer final : private QObject {
public:
Timer(base::lambda<void()> callback = base::lambda<void()>());
Timer(Fn<void()> callback = Fn<void()>());

static Qt::TimerType DefaultType(TimeMs timeout) {
constexpr auto kThreshold = TimeMs(1000);
return (timeout > kThreshold) ? Qt::CoarseTimer : Qt::PreciseTimer;
}

void setCallback(base::lambda<void()> callback) {
void setCallback(Fn<void()> callback) {
_callback = std::move(callback);
}

Expand Down Expand Up @@ -86,7 +85,7 @@ class Timer final : private QObject {
return static_cast<Repeat>(_repeat);
}

base::lambda<void()> _callback;
Fn<void()> _callback;
TimeMs _next = 0;
int _timeout = 0;
int _timerId = 0;
Expand All @@ -98,18 +97,18 @@ class Timer final : private QObject {

class DelayedCallTimer final : private QObject {
public:
int call(TimeMs timeout, lambda_once<void()> callback) {
int call(TimeMs timeout, FnMut<void()> callback) {
return call(timeout, std::move(callback), Timer::DefaultType(timeout));
}

int call(TimeMs timeout, lambda_once<void()> callback, Qt::TimerType type);
int call(TimeMs timeout, FnMut<void()> callback, Qt::TimerType type);
void cancel(int callId);

protected:
void timerEvent(QTimerEvent *e) override;

private:
std::map<int, lambda_once<void()>> _callbacks; // Better to use flatmap.
std::map<int, FnMut<void()>> _callbacks; // Better to use flatmap.
};

} // namespace base
18 changes: 8 additions & 10 deletions Telegram/SourceFiles/boxes/abstract_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/widgets/labels.h"
#include "ui/widgets/scroll_area.h"

QPointer<Ui::RoundButton> BoxContent::addButton(base::lambda<QString()> textFactory,
base::lambda<void()> clickCallback) {
QPointer<Ui::RoundButton> BoxContent::addButton(Fn<QString()> textFactory, Fn<void()> clickCallback) {
return addButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton);
}

QPointer<Ui::RoundButton> BoxContent::addLeftButton(base::lambda<QString()> textFactory,
base::lambda<void()> clickCallback) {
QPointer<Ui::RoundButton> BoxContent::addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback) {
return getDelegate()->addLeftButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton);
}

Expand Down Expand Up @@ -279,7 +277,7 @@ void AbstractBox::parentResized() {
update();
}

void AbstractBox::setTitle(base::lambda<TextWithEntities()> titleFactory) {
void AbstractBox::setTitle(Fn<TextWithEntities()> titleFactory) {
_titleFactory = std::move(titleFactory);
refreshTitle();
}
Expand All @@ -300,7 +298,7 @@ void AbstractBox::refreshTitle() {
}
}

void AbstractBox::setAdditionalTitle(base::lambda<QString()> additionalFactory) {
void AbstractBox::setAdditionalTitle(Fn<QString()> additionalFactory) {
_additionalTitleFactory = std::move(additionalFactory);
refreshAdditionalTitle();
}
Expand Down Expand Up @@ -355,8 +353,8 @@ void AbstractBox::clearButtons() {
_leftButton.destroy();
}

QPointer<Ui::RoundButton> AbstractBox::addButton(base::lambda<QString()> textFactory,
base::lambda<void()> clickCallback, const style::RoundButton &st) {
QPointer<Ui::RoundButton> AbstractBox::addButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) {
_buttons.push_back(object_ptr<Ui::RoundButton>(this, std::move(textFactory), st));
auto result = QPointer<Ui::RoundButton>(_buttons.back());
result->setClickedCallback(std::move(clickCallback));
Expand All @@ -365,8 +363,8 @@ QPointer<Ui::RoundButton> AbstractBox::addButton(base::lambda<QString()> textFac
return result;
}

QPointer<Ui::RoundButton> AbstractBox::addLeftButton(base::lambda<QString()> textFactory,
base::lambda<void()> clickCallback, const style::RoundButton &st) {
QPointer<Ui::RoundButton> AbstractBox::addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) {
_leftButton = object_ptr<Ui::RoundButton>(this, std::move(textFactory), st);
auto result = QPointer<Ui::RoundButton>(_leftButton);
result->setClickedCallback(std::move(clickCallback));
Expand Down
36 changes: 17 additions & 19 deletions Telegram/SourceFiles/boxes/abstract_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once

#include "base/lambda.h"
#include "base/observer.h"
#include "layerwidget.h"
#include "ui/text/text_entity.h"
Expand All @@ -46,14 +45,13 @@ class BoxContentDelegate {
virtual Window::Controller *controller() const = 0;

virtual void setLayerType(bool layerType) = 0;
virtual void setTitle(base::lambda<TextWithEntities()> titleFactory) = 0;
virtual void setAdditionalTitle(base::lambda<QString()> additionalFactory) = 0;
virtual void setTitle(Fn<TextWithEntities()> titleFactory) = 0;
virtual void setAdditionalTitle(Fn<QString()> additionalFactory) = 0;

virtual void clearButtons() = 0;
virtual QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback,
virtual QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) = 0;
virtual QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory,
base::lambda<void()> clickCallback,
virtual QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) = 0;
virtual void updateButtonsPositions() = 0;

Expand All @@ -78,26 +76,26 @@ class BoxContent : public TWidget, protected base::Subscriber {
getDelegate()->closeBox();
}

void setTitle(base::lambda<QString()> titleFactory) {
void setTitle(Fn<QString()> titleFactory) {
if (titleFactory) {
getDelegate()->setTitle([titleFactory] { return TextWithEntities{titleFactory(), EntitiesInText()}; });
} else {
getDelegate()->setTitle(base::lambda<TextWithEntities()>());
getDelegate()->setTitle(Fn<TextWithEntities()>());
}
}
void setTitle(base::lambda<TextWithEntities()> titleFactory) {
void setTitle(Fn<TextWithEntities()> titleFactory) {
getDelegate()->setTitle(std::move(titleFactory));
}
void setAdditionalTitle(base::lambda<QString()> additional) {
void setAdditionalTitle(Fn<QString()> additional) {
getDelegate()->setAdditionalTitle(std::move(additional));
}

void clearButtons() {
getDelegate()->clearButtons();
}
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback);
QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback);
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback,
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback);
QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback);
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) {
return getDelegate()->addButton(std::move(textFactory), std::move(clickCallback), st);
}
Expand Down Expand Up @@ -214,13 +212,13 @@ class AbstractBox : public LayerWidget, public BoxContentDelegate, protected bas
void parentResized() override;

void setLayerType(bool layerType) override;
void setTitle(base::lambda<TextWithEntities()> titleFactory) override;
void setAdditionalTitle(base::lambda<QString()> additionalFactory) override;
void setTitle(Fn<TextWithEntities()> titleFactory) override;
void setAdditionalTitle(Fn<QString()> additionalFactory) override;

void clearButtons() override;
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback,
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) override;
QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback,
QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback,
const style::RoundButton &st) override;
void updateButtonsPositions() override;

Expand Down Expand Up @@ -276,9 +274,9 @@ class AbstractBox : public LayerWidget, public BoxContentDelegate, protected bas
object_ptr<BoxContent> _content;

object_ptr<Ui::FlatLabel> _title = {nullptr};
base::lambda<TextWithEntities()> _titleFactory;
Fn<TextWithEntities()> _titleFactory;
QString _additionalTitle;
base::lambda<QString()> _additionalTitleFactory;
Fn<QString()> _additionalTitleFactory;
int _titleLeft = 0;
int _titleTop = 0;
bool _layerType = false;
Expand Down
10 changes: 5 additions & 5 deletions Telegram/SourceFiles/boxes/add_contact_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ QString PeerFloodErrorText(PeerFloodType type) {

class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender {
public:
Inner(QWidget *parent, base::lambda<void()> revokeCallback);
Inner(QWidget *parent, Fn<void()> revokeCallback);

protected:
void mouseMoveEvent(QMouseEvent *e) override;
Expand Down Expand Up @@ -96,7 +96,7 @@ class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender {
int _rowHeight = 0;
int _revokeWidth = 0;

base::lambda<void()> _revokeCallback;
Fn<void()> _revokeCallback;
mtpRequestId _revokeRequestId = 0;
QPointer<ConfirmBox> _weakRevokeConfirmBox;
};
Expand Down Expand Up @@ -600,7 +600,7 @@ SetupChannelBox::SetupChannelBox(QWidget *, ChannelData *channel, bool existing)
, _aboutPrivate(st::defaultTextStyle,
lang(channel->isMegagroup() ? lng_create_private_group_about : lng_create_private_channel_about),
_defaultOptions, _aboutPublicWidth)
, _link(this, st::setupChannelLink, base::lambda<QString()>(), channel->username, true) {}
, _link(this, st::setupChannelLink, Fn<QString()>(), channel->username, true) {}

void SetupChannelBox::prepare() {
_aboutPublicHeight = _aboutPublic.countHeight(_aboutPublicWidth);
Expand Down Expand Up @@ -1479,7 +1479,7 @@ void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) {
closeBox();
}

RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda<void()> revokeCallback)
RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn<void()> revokeCallback)
: TWidget(parent)
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
, _revokeWidth(st::normalFont->width(lang(lng_channels_too_much_public_revoke)))
Expand Down Expand Up @@ -1513,7 +1513,7 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda<void()> revokeCa
.send();
}

RevokePublicLinkBox::RevokePublicLinkBox(QWidget *, base::lambda<void()> revokeCallback)
RevokePublicLinkBox::RevokePublicLinkBox(QWidget *, Fn<void()> revokeCallback)
: _aboutRevoke(this, lang(lng_channels_too_much_public_about), Ui::FlatLabel::InitType::Simple,
st::aboutRevokePublicLabel)
, _revokeCallback(std::move(revokeCallback)) {}
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/boxes/add_contact_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private slots:

class RevokePublicLinkBox : public BoxContent, public RPCSender {
public:
RevokePublicLinkBox(QWidget *, base::lambda<void()> revokeCallback);
RevokePublicLinkBox(QWidget *, Fn<void()> revokeCallback);

protected:
void prepare() override;
Expand All @@ -335,5 +335,5 @@ class RevokePublicLinkBox : public BoxContent, public RPCSender {
QPointer<Inner> _inner;

int _innerTop = 0;
base::lambda<void()> _revokeCallback;
Fn<void()> _revokeCallback;
};
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/boxes/background_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BackgroundBox::Inner : public TWidget, public RPCSender, private base::Sub
public:
Inner(QWidget *parent);

void setBackgroundChosenCallback(base::lambda<void(int index)> callback) {
void setBackgroundChosenCallback(Fn<void(int index)> callback) {
_backgroundChosenCallback = std::move(callback);
}

Expand All @@ -49,7 +49,7 @@ class BackgroundBox::Inner : public TWidget, public RPCSender, private base::Sub
void gotWallpapers(const MTPVector<MTPWallPaper> &result);
void updateWallpapers();

base::lambda<void(int index)> _backgroundChosenCallback;
Fn<void(int index)> _backgroundChosenCallback;

int _bgCount = 0;
int _rows = 0;
Expand Down
Loading

0 comments on commit 38efa1b

Please sign in to comment.