UniquePointer > std_::unique_ptr, MakeUnique > std_::make_unique.

This commit is contained in:
John Preston 2016-04-10 23:20:48 +04:00
parent dd1d04e9b0
commit 460e2ec0ac
29 changed files with 214 additions and 177 deletions

View file

@ -315,6 +315,98 @@ constexpr add_const_t<T> &as_const(T& t) noexcept {
template <typename T>
void as_const(const T&&) = delete;
// This is not full unique_ptr, but at least with std interface.
template <typename T>
class unique_ptr {
public:
constexpr unique_ptr() noexcept = default;
unique_ptr(const unique_ptr<T> &) = delete;
unique_ptr<T> &operator=(const unique_ptr<T> &) = delete;
constexpr unique_ptr(nullptr_t) {
}
unique_ptr<T> &operator=(nullptr_t) noexcept {
reset();
return (*this);
}
explicit unique_ptr(T *p) noexcept : _p(p) {
}
template <typename U>
unique_ptr(unique_ptr<U> &&other) noexcept : _p(other.release()) {
}
template <typename U>
unique_ptr<T> &operator=(unique_ptr<U> &&other) noexcept {
reset(other.release());
return (*this);
}
unique_ptr<T> &operator=(unique_ptr<T> &&other) noexcept {
if (this != &other) {
reset(other.release());
}
return (*this);
}
void swap(unique_ptr<T> &other) noexcept {
std::swap(_p, other._p);
}
~unique_ptr() noexcept {
delete _p;
}
T &operator*() const {
return (*get());
}
T *operator->() const noexcept {
return get();
}
T *get() const noexcept {
return _p;
}
explicit operator bool() const noexcept {
return get() != nullptr;
}
T *release() noexcept {
return getPointerAndReset(_p);
}
void reset(T *p = nullptr) noexcept {
T *old = _p;
_p = p;
if (old) {
delete old;
}
}
private:
T *_p = nullptr;
};
template <typename T, typename... Args>
inline unique_ptr<T> make_unique(Args&&... args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template <typename T>
inline bool operator==(const unique_ptr<T> &a, nullptr_t) noexcept {
return !a;
}
template <typename T>
inline bool operator==(nullptr_t, const unique_ptr<T> &b) noexcept {
return !b;
}
template <typename T>
inline bool operator!=(const unique_ptr<T> &a, nullptr_t b) noexcept {
return !(a == b);
}
template <typename T>
inline bool operator!=(nullptr_t a, const unique_ptr<T> &b) noexcept {
return !(a == b);
}
} // namespace std_
#include "logs.h"
@ -747,61 +839,6 @@ inline RefPairImplementation<T1, T2> RefPairCreator(T1 &first, T2 &second) {
#define RefPair(Type1, Name1, Type2, Name2) Type1 Name1; Type2 Name2; RefPairCreator(Name1, Name2)
template <typename T>
class UniquePointer {
public:
explicit UniquePointer(T *p = nullptr) : _p(p) {
}
UniquePointer(const UniquePointer<T> &other) = delete;
UniquePointer &operator=(const UniquePointer<T> &other) = delete;
UniquePointer(UniquePointer<T> &&other) : _p(other.release()) {
}
UniquePointer &operator=(UniquePointer<T> &&other) {
std::swap(_p, other._p);
return *this;
}
template <typename U>
UniquePointer(UniquePointer<U> &&other) : _p(other.release()) {
}
T *data() const {
return _p;
}
T *release() {
return getPointerAndReset(_p);
}
void reset(T *p = nullptr) {
*this = UniquePointer<T>(p);
}
bool isNull() const {
return data() == nullptr;
}
void clear() {
reset();
}
T *operator->() const {
return data();
}
T &operator*() const {
t_assert(!isNull());
return *data();
}
explicit operator bool() const {
return !isNull();
}
~UniquePointer() {
delete data();
}
private:
T *_p;
};
template <typename T, typename... Args>
inline UniquePointer<T> MakeUnique(Args&&... args) {
return UniquePointer<T>(new T(std_::forward<Args>(args)...));
}
template <typename T, typename... Args>
inline QSharedPointer<T> MakeShared(Args&&... args) {
return QSharedPointer<T>(new T(std_::forward<Args>(args)...));

View file

@ -72,8 +72,8 @@ ContactsInner::ContactsInner(ChatData *chat, MembersFilter membersFilter) : TWid
, _aboutWidth(st::boxWideWidth - st::contactsPadding.left() - st::contactsPadding.right() - st::contactsCheckPosition.x() * 2 - st::contactsCheckIcon.pxWidth())
, _aboutAllAdmins(st::boxTextFont, lang(lng_chat_about_all_admins), _defaultOptions, _aboutWidth)
, _aboutAdmins(st::boxTextFont, lang(lng_chat_about_admins), _defaultOptions, _aboutWidth)
, _customList((membersFilter == MembersFilterRecent) ? UniquePointer<Dialogs::IndexedList>() : MakeUnique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _contacts((membersFilter == MembersFilterRecent) ? App::main()->contactsList() : _customList.data())
, _customList((membersFilter == MembersFilterRecent) ? std_::unique_ptr<Dialogs::IndexedList>() : std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _contacts((membersFilter == MembersFilterRecent) ? App::main()->contactsList() : _customList.get())
, _addContactLnk(this, lang(lng_add_contact_button)) {
initList();
if (membersFilter == MembersFilterAdmins) {
@ -89,8 +89,8 @@ ContactsInner::ContactsInner(UserData *bot) : TWidget()
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
, _bot(bot)
, _allAdmins(this, lang(lng_chat_all_members_admins), false, st::contactsAdminCheckbox)
, _customList(MakeUnique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _contacts(_customList.data())
, _customList(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _contacts(_customList.get())
, _addContactLnk(this, lang(lng_add_contact_button)) {
auto v = App::main()->dialogsList();
for_const (auto row, *v) {

View file

@ -147,7 +147,7 @@ private:
int32 _time;
UniquePointer<Dialogs::IndexedList> _customList;
std_::unique_ptr<Dialogs::IndexedList> _customList;
Dialogs::IndexedList *_contacts = nullptr;
Dialogs::Row *_sel = nullptr;
QString _filter;

View file

@ -27,11 +27,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
namespace Dialogs {
List::List(SortMode sortMode)
: _last(MakeUnique<Row>(nullptr, nullptr, nullptr, 0))
, _begin(_last.data())
, _end(_last.data())
: _last(std_::make_unique<Row>(nullptr, nullptr, nullptr, 0))
, _begin(_last.get())
, _end(_last.get())
, _sortMode(sortMode)
, _current(_last.data()) {
, _current(_last.get()) {
}
void List::adjustCurrent(int32 y, int32 h) const {

View file

@ -121,7 +121,7 @@ private:
return row->_prev;
}
UniquePointer<Row> _last;
std_::unique_ptr<Row> _last;
Row *_begin;
Row *_end;
SortMode _sortMode;

View file

@ -35,9 +35,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "localstorage.h"
DialogsInner::DialogsInner(QWidget *parent, MainWidget *main) : SplittedWidget(parent)
, dialogs(MakeUnique<Dialogs::IndexedList>(Dialogs::SortMode::Date))
, contactsNoDialogs(MakeUnique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
, contacts(MakeUnique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
, dialogs(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Date))
, contactsNoDialogs(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
, contacts(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
, _addContactLnk(this, lang(lng_add_contact_button))
, _cancelSearchInPeer(this, st::btnCancelSearch) {
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
@ -419,10 +419,10 @@ void DialogsInner::onDialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRo
void DialogsInner::createDialog(History *history) {
bool creating = !history->inChatList();
if (creating) {
Dialogs::Row *mainRow = history->addToChatList(dialogs.data());
Dialogs::Row *mainRow = history->addToChatList(dialogs.get());
contactsNoDialogs->del(history->peer, mainRow);
}
RefPair(int32, movedFrom, int32, movedTo) = history->adjustByPosInChatsList(dialogs.data());
RefPair(int32, movedFrom, int32, movedTo) = history->adjustByPosInChatsList(dialogs.get());
emit dialogMoved(movedFrom, movedTo);
@ -441,7 +441,7 @@ void DialogsInner::removeDialog(History *history) {
if (sel && sel->history() == history) {
sel = nullptr;
}
history->removeFromChatList(dialogs.data());
history->removeFromChatList(dialogs.get());
history->clearNotifications();
if (App::wnd()) App::wnd()->notifyClear(history);
if (contacts->contains(history->peer->id)) {
@ -1450,9 +1450,9 @@ void DialogsInner::destroyData() {
_filter.clear();
_searchedSel = _peopleSel = -1;
clearSearchResults();
contacts.clear();
contactsNoDialogs.clear();
dialogs.clear();
contacts = nullptr;
contactsNoDialogs = nullptr;
dialogs = nullptr;
}
void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
@ -1593,11 +1593,11 @@ void DialogsInner::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&out
}
Dialogs::IndexedList *DialogsInner::contactsList() {
return contacts.data();
return contacts.get();
}
Dialogs::IndexedList *DialogsInner::dialogsList() {
return dialogs.data();
return dialogs.get();
}
DialogsInner::FilteredDialogs &DialogsInner::filteredList() {

View file

@ -170,7 +170,7 @@ private:
bool menuPeerMuted();
void contextBlockDone(QPair<UserData*, bool> data, const MTPBool &result);
using DialogsList = UniquePointer<Dialogs::IndexedList>;
using DialogsList = std_::unique_ptr<Dialogs::IndexedList>;
DialogsList dialogs;
DialogsList contactsNoDialogs;
DialogsList contacts;

View file

@ -1917,10 +1917,10 @@ void StickerPanInner::refreshSwitchPmButton(const InlineCacheEntry *entry) {
_switchPmStartToken.clear();
} else {
if (!_switchPmButton) {
_switchPmButton = MakeUnique<BoxButton>(this, QString(), st::switchPmButton);
_switchPmButton = std_::make_unique<BoxButton>(this, QString(), st::switchPmButton);
_switchPmButton->show();
_switchPmButton->move(st::inlineResultsLeft, st::emojiPanHeader);
connect(_switchPmButton.data(), SIGNAL(clicked()), this, SLOT(onSwitchPm()));
connect(_switchPmButton.get(), SIGNAL(clicked()), this, SLOT(onSwitchPm()));
}
_switchPmButton->setText(entry->switchPmText); // doesn't perform text.toUpper()
_switchPmStartToken = entry->switchPmStartToken;

View file

@ -463,7 +463,7 @@ private:
QTimer _updateInlineItems;
bool _inlineWithThumb;
UniquePointer<BoxButton> _switchPmButton;
std_::unique_ptr<BoxButton> _switchPmButton;
QString _switchPmStartToken;
typedef QVector<InlineItem*> InlineItems;

View file

@ -1969,7 +1969,7 @@ HistoryBlock *History::finishBuildingFrontBlock() {
}
}
_buildingFrontBlock.clear();
_buildingFrontBlock = nullptr;
return block;
}
@ -2641,7 +2641,7 @@ int ReplyKeyboard::naturalHeight() const {
}
void ReplyKeyboard::paint(Painter &p, const QRect &clip) const {
t_assert(!_st.isNull());
t_assert(_st != nullptr);
t_assert(_width > 0);
_st->startPaint(p);
@ -2815,7 +2815,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector<MTPKeyboardBu
void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
flags = 0;
rows.clear();
inlineKeyboard.clear();
inlineKeyboard = nullptr;
switch (markup.type()) {
case mtpc_replyKeyboardMarkup: {
@ -6349,7 +6349,7 @@ bool HistoryMessageReply::updateData(HistoryMessage *holder, bool force) {
}
void HistoryMessageReply::clearData(HistoryMessage *holder) {
_replyToVia.clear();
_replyToVia = nullptr;
if (replyToMsg) {
App::historyUnregDependency(holder, replyToMsg);
replyToMsg = nullptr;
@ -6817,7 +6817,7 @@ void HistoryMessage::initDimensions() {
}
if (HistoryMessageReplyMarkup *markup = inlineReplyMarkup()) {
if (!markup->inlineKeyboard) {
markup->inlineKeyboard.reset(new ReplyKeyboard(this, MakeUnique<KeyboardStyle>(st::msgBotKbButton)));
markup->inlineKeyboard.reset(new ReplyKeyboard(this, std_::make_unique<KeyboardStyle>(st::msgBotKbButton)));
}
// if we have a text bubble we can resize it to fit the keyboard

View file

@ -350,12 +350,12 @@ public:
NotifyQueue notifies;
HistoryDraft *msgDraft() {
return _msgDraft.data();
return _msgDraft.get();
}
HistoryEditDraft *editDraft() {
return _editDraft.data();
return _editDraft.get();
}
void setMsgDraft(UniquePointer<HistoryDraft> &&draft) {
void setMsgDraft(std_::unique_ptr<HistoryDraft> &&draft) {
_msgDraft = std_::move(draft);
}
void takeMsgDraft(History *from) {
@ -367,14 +367,14 @@ public:
from->clearMsgDraft();
}
}
void setEditDraft(UniquePointer<HistoryEditDraft> &&draft) {
void setEditDraft(std_::unique_ptr<HistoryEditDraft> &&draft) {
_editDraft = std_::move(draft);
}
void clearMsgDraft() {
_msgDraft.clear();
_msgDraft = nullptr;
}
void clearEditDraft() {
_editDraft.clear();
_editDraft = nullptr;
}
HistoryDraft *draft() {
return _editDraft ? editDraft() : msgDraft();
@ -513,7 +513,7 @@ protected:
void startBuildingFrontBlock(int expectedItemsCount = 1);
HistoryBlock *finishBuildingFrontBlock(); // Returns the built block or nullptr if nothing was added.
bool isBuildingFrontBlock() const {
return !_buildingFrontBlock.isNull();
return _buildingFrontBlock != nullptr;
}
private:
@ -553,14 +553,14 @@ private:
int expectedItemsCount = 0; // optimization for block->items.reserve() call
HistoryBlock *block = nullptr;
};
UniquePointer<BuildingBlock> _buildingFrontBlock;
std_::unique_ptr<BuildingBlock> _buildingFrontBlock;
// Creates if necessary a new block for adding item.
// Depending on isBuildingFrontBlock() gets front or back block.
HistoryBlock *prepareBlockForAddingItem();
UniquePointer<HistoryDraft> _msgDraft;
UniquePointer<HistoryEditDraft> _editDraft;
std_::unique_ptr<HistoryDraft> _msgDraft;
std_::unique_ptr<HistoryEditDraft> _editDraft;
};
@ -782,7 +782,7 @@ struct HistoryMessageReply : public BaseComponent<HistoryMessageReply> {
~HistoryMessageReply() {
// clearData() should be called by holder
t_assert(replyToMsg == nullptr);
t_assert(_replyToVia.data() == nullptr);
t_assert(_replyToVia == nullptr);
}
bool updateData(HistoryMessage *holder, bool force = false);
@ -816,7 +816,7 @@ struct HistoryMessageReply : public BaseComponent<HistoryMessageReply> {
mutable Text replyToName, replyToText;
mutable int replyToVersion = 0;
mutable int _maxReplyWidth = 0;
UniquePointer<HistoryMessageVia> _replyToVia;
std_::unique_ptr<HistoryMessageVia> _replyToVia;
int toWidth = 0;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(HistoryMessageReply::PaintFlags);
@ -849,7 +849,7 @@ struct HistoryMessageReplyMarkup : public BaseComponent<HistoryMessageReplyMarku
ButtonRows rows;
MTPDreplyKeyboardMarkup::Flags flags = 0;
UniquePointer<ReplyKeyboard> inlineKeyboard;
std_::unique_ptr<ReplyKeyboard> inlineKeyboard;
// If >= 0 it holds the y coord of the inlineKeyboard before the last edition.
int oldTop = -1;
@ -900,7 +900,7 @@ public:
friend class ReplyKeyboard;
};
typedef UniquePointer<Style> StylePtr;
typedef std_::unique_ptr<Style> StylePtr;
ReplyKeyboard(const HistoryItem *item, StylePtr &&s);
ReplyKeyboard(const ReplyKeyboard &other) = delete;
@ -1482,7 +1482,7 @@ protected:
}
const ReplyKeyboard *inlineReplyKeyboard() const {
if (auto markup = inlineReplyMarkup()) {
return markup->inlineKeyboard.data();
return markup->inlineKeyboard.get();
}
return nullptr;
}

View file

@ -1688,7 +1688,7 @@ void HistoryInner::onUpdateSelected() {
if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
bool inText = false;
_botAbout->info->text.getState(lnk, inText, point.x() - _botAbout->rect.left() - st::msgPadding.left(), point.y() - _botAbout->rect.top() - st::msgPadding.top() - st::botDescSkip - st::msgNameFont->height, _botAbout->width);
lnkhost = _botAbout.data();
lnkhost = _botAbout.get();
cursorState = inText ? HistoryInTextCursorState : HistoryDefaultCursorState;
}
} else if (item) {
@ -1903,7 +1903,7 @@ void HistoryInner::notifyIsBotChanged() {
App::api()->requestFullPeer(_peer);
}
} else {
_botAbout.clear();
_botAbout = nullptr;
}
}
@ -2270,7 +2270,7 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
_maximizeSize = !(markup->flags & MTPDreplyKeyboardMarkup::Flag::f_resize);
_singleUse = _forceReply || (markup->flags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
_impl.reset(markup->rows.isEmpty() ? nullptr : new ReplyKeyboard(to, MakeUnique<Style>(this, *_st)));
_impl.reset(markup->rows.isEmpty() ? nullptr : new ReplyKeyboard(to, std_::make_unique<Style>(this, *_st)));
updateStyle();
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
@ -2286,14 +2286,14 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
_maximizeSize = _singleUse = _forceReply = false;
_wasForMsgId = FullMsgId();
clearSelection();
_impl.clear();
_impl = nullptr;
return true;
}
return false;
}
bool BotKeyboard::hasMarkup() const {
return !_impl.isNull();
return _impl != nullptr;
}
bool BotKeyboard::forceReply() const {
@ -2323,7 +2323,7 @@ void BotKeyboard::updateStyle(int32 w) {
int implWidth = ((w < 0) ? width() : w) - _st->margin - st::botKbScroll.width;
_st = _impl->isEnoughSpace(implWidth, st::botKbButton) ? &st::botKbButton : &st::botKbTinyButton;
_impl->setStyle(MakeUnique<Style>(this, *_st));
_impl->setStyle(std_::make_unique<Style>(this, *_st));
}
void BotKeyboard::clearSelection() {
@ -3239,7 +3239,7 @@ void HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query) {
}
History *h = App::history(bot->botInfo->inlineReturnPeerId);
auto text = '@' + bot->username + ' ' + query;
h->setMsgDraft(MakeUnique<HistoryDraft>(text, 0, MessageCursor(text.size(), text.size(), QFIXED_MAX), false));
h->setMsgDraft(std_::make_unique<HistoryDraft>(text, 0, MessageCursor(text.size(), text.size(), QFIXED_MAX), false));
if (h == _history) {
applyDraft();
} else {
@ -3633,10 +3633,10 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
if (_history) {
if (_editMsgId) {
_history->setEditDraft(MakeUnique<HistoryEditDraft>(_field, _editMsgId, _previewCancelled, _saveEditMsgRequestId));
_history->setEditDraft(std_::make_unique<HistoryEditDraft>(_field, _editMsgId, _previewCancelled, _saveEditMsgRequestId));
} else {
if (_replyToId || !_field.getLastText().isEmpty()) {
_history->setMsgDraft(MakeUnique<HistoryDraft>(_field, _replyToId, _previewCancelled));
_history->setMsgDraft(std_::make_unique<HistoryDraft>(_field, _replyToId, _previewCancelled));
} else {
_history->clearMsgDraft();
}
@ -5907,13 +5907,13 @@ void HistoryWidget::clearInlineBot() {
void HistoryWidget::inlineBotChanged() {
bool isInlineBot = _inlineBot && (_inlineBot != LookingUpInlineBot);
if (isInlineBot && !_inlineBotCancel) {
_inlineBotCancel = MakeUnique<IconedButton>(this, st::inlineBotCancel);
connect(_inlineBotCancel.data(), SIGNAL(clicked()), this, SLOT(onInlineBotCancel()));
_inlineBotCancel = std_::make_unique<IconedButton>(this, st::inlineBotCancel);
connect(_inlineBotCancel.get(), SIGNAL(clicked()), this, SLOT(onInlineBotCancel()));
_inlineBotCancel->setGeometry(_send.geometry());
updateFieldSubmitSettings();
updateControlsVisibility();
} else if (!isInlineBot && _inlineBotCancel) {
_inlineBotCancel.clear();
_inlineBotCancel = nullptr;
updateFieldSubmitSettings();
updateControlsVisibility();
}
@ -7232,7 +7232,7 @@ void HistoryWidget::onReplyToMessage() {
if (auto msgDraft = _history->msgDraft()) {
msgDraft->msgId = to->id;
} else {
_history->setMsgDraft(MakeUnique<HistoryDraft>(QString(), to->id, MessageCursor(), false));
_history->setMsgDraft(std_::make_unique<HistoryDraft>(QString(), to->id, MessageCursor(), false));
}
} else {
_replyEditMsg = to;
@ -7266,13 +7266,13 @@ void HistoryWidget::onEditMessage() {
delete box;
if (_replyToId || !_field.getLastText().isEmpty()) {
_history->setMsgDraft(MakeUnique<HistoryDraft>(_field, _replyToId, _previewCancelled));
_history->setMsgDraft(std_::make_unique<HistoryDraft>(_field, _replyToId, _previewCancelled));
} else {
_history->clearMsgDraft();
}
QString text(textApplyEntities(to->originalText(), to->originalEntities()));
_history->setEditDraft(MakeUnique<HistoryEditDraft>(text, to->id, MessageCursor(text.size(), text.size(), QFIXED_MAX), false));
_history->setEditDraft(std_::make_unique<HistoryEditDraft>(text, to->id, MessageCursor(text.size(), text.size(), QFIXED_MAX), false));
applyDraft(false);
_previewData = 0;

View file

@ -170,7 +170,7 @@ private:
HistoryInner *_parent;
};
UniquePointer<BotAbout> _botAbout;
std_::unique_ptr<BotAbout> _botAbout;
HistoryWidget *_widget = nullptr;
ScrollArea *_scroll = nullptr;
@ -362,7 +362,7 @@ private:
bool _forceReply = false;
QPoint _lastMousePos;
UniquePointer<ReplyKeyboard> _impl;
std_::unique_ptr<ReplyKeyboard> _impl;
class Style : public ReplyKeyboard::Style {
public:
@ -1011,7 +1011,7 @@ private:
UserData *_inlineBot = nullptr;
QString _inlineBotUsername;
mtpRequestId _inlineBotResolveRequestId = 0;
UniquePointer<IconedButton> _inlineBotCancel;
std_::unique_ptr<IconedButton> _inlineBotCancel;
void inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result);
bool inlineBotResolveFail(QString name, const RPCError &error);

View file

@ -831,7 +831,7 @@ void File::ensureAnimation() const {
void File::checkAnimationFinished() {
if (_animation && !_animation->_a_thumbOver.animating() && !_animation->radial.animating()) {
if (getShownDocument()->loaded()) {
_animation.clear();
_animation = nullptr;
}
}
}

View file

@ -277,7 +277,7 @@ private:
RadialAnimation radial;
};
mutable UniquePointer<AnimationData> _animation;
mutable std_::unique_ptr<AnimationData> _animation;
Text _title, _description;
ClickHandlerPtr _open, _cancel;

View file

@ -99,25 +99,25 @@ void ItemBase::update() {
}
}
UniquePointer<ItemBase> ItemBase::createLayout(Result *result, bool forceThumb) {
std_::unique_ptr<ItemBase> ItemBase::createLayout(Result *result, bool forceThumb) {
using Type = Result::Type;
switch (result->_type) {
case Type::Photo: return MakeUnique<internal::Photo>(result); break;
case Type::Photo: return std_::make_unique<internal::Photo>(result); break;
case Type::Audio:
case Type::File: return MakeUnique<internal::File>(result); break;
case Type::Video: return MakeUnique<internal::Video>(result); break;
case Type::Sticker: return MakeUnique<internal::Sticker>(result); break;
case Type::Gif: return MakeUnique<internal::Gif>(result); break;
case Type::File: return std_::make_unique<internal::File>(result); break;
case Type::Video: return std_::make_unique<internal::Video>(result); break;
case Type::Sticker: return std_::make_unique<internal::Sticker>(result); break;
case Type::Gif: return std_::make_unique<internal::Gif>(result); break;
case Type::Article:
case Type::Venue: return MakeUnique<internal::Article>(result, forceThumb); break;
case Type::Contact: return MakeUnique<internal::Contact>(result); break;
case Type::Venue: return std_::make_unique<internal::Article>(result, forceThumb); break;
case Type::Contact: return std_::make_unique<internal::Contact>(result); break;
}
return UniquePointer<ItemBase>();
return std_::unique_ptr<ItemBase>();
}
UniquePointer<ItemBase> ItemBase::createLayoutGif(DocumentData *document) {
return MakeUnique<internal::Gif>(document, true);
std_::unique_ptr<ItemBase> ItemBase::createLayoutGif(DocumentData *document) {
return std_::make_unique<internal::Gif>(document, true);
}
DocumentData *ItemBase::getResultDocument() const {

View file

@ -91,8 +91,8 @@ public:
update();
}
static UniquePointer<ItemBase> createLayout(Result *result, bool forceThumb);
static UniquePointer<ItemBase> createLayoutGif(DocumentData *document);
static std_::unique_ptr<ItemBase> createLayout(Result *result, bool forceThumb);
static std_::unique_ptr<ItemBase> createLayoutGif(DocumentData *document);
protected:
DocumentData *getResultDocument() const;

View file

@ -60,10 +60,10 @@ Result *getResultFromLoader(FileLoader *loader) {
Result::Result(const Creator &creator) : _queryId(creator.queryId), _type(creator.type) {
}
UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &mtpData) {
std_::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult &mtpData) {
using StringToTypeMap = QMap<QString, Result::Type>;
static StaticNeverFreedPointer<StringToTypeMap> stringToTypeMap{ ([]() -> StringToTypeMap* {
auto result = MakeUnique<StringToTypeMap>();
auto result = std_::make_unique<StringToTypeMap>();
result->insert(qsl("photo"), Result::Type::Photo);
result->insert(qsl("video"), Result::Type::Video);
result->insert(qsl("audio"), Result::Type::Audio);
@ -86,10 +86,10 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
};
Type type = getInlineResultType(mtpData);
if (type == Type::Unknown) {
return UniquePointer<Result>();
return std_::unique_ptr<Result>();
}
auto result = MakeUnique<Result>(Creator{ queryId, type });
auto result = std_::make_unique<Result>(Creator{ queryId, type });
const MTPBotInlineMessage *message = nullptr;
switch (mtpData.type()) {
case mtpc_botInlineResult: {
@ -126,18 +126,18 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
bool badAttachment = (result->_photo && !result->_photo->access) || (result->_document && !result->_document->isValid());
if (!message) {
return UniquePointer<Result>();
return std_::unique_ptr<Result>();
}
// Ensure required media fields for layouts.
if (result->_type == Type::Photo) {
if (!result->_photo && result->_content_url.isEmpty()) {
return UniquePointer<Result>();
return std_::unique_ptr<Result>();
}
result->createPhoto();
} else if (result->_type == Type::File || result->_type == Type::Gif || result->_type == Type::Sticker) {
if (!result->_document && result->_content_url.isEmpty()) {
return UniquePointer<Result>();
return std_::unique_ptr<Result>();
}
result->createDocument();
}
@ -153,7 +153,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
result->sendData.reset(new internal::SendFile(result->_document, qs(r.vcaption)));
}
if (r.has_reply_markup()) {
result->_mtpKeyboard = MakeUnique<MTPReplyMarkup>(r.vreply_markup);
result->_mtpKeyboard = std_::make_unique<MTPReplyMarkup>(r.vreply_markup);
}
} break;
@ -162,7 +162,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
EntitiesInText entities = r.has_entities() ? entitiesFromMTP(r.ventities.c_vector().v) : EntitiesInText();
result->sendData.reset(new internal::SendText(qs(r.vmessage), entities, r.is_no_webpage()));
if (r.has_reply_markup()) {
result->_mtpKeyboard = MakeUnique<MTPReplyMarkup>(r.vreply_markup);
result->_mtpKeyboard = std_::make_unique<MTPReplyMarkup>(r.vreply_markup);
}
} break;
@ -174,7 +174,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
badAttachment = true;
}
if (r.has_reply_markup()) {
result->_mtpKeyboard = MakeUnique<MTPReplyMarkup>(r.vreply_markup);
result->_mtpKeyboard = std_::make_unique<MTPReplyMarkup>(r.vreply_markup);
}
} break;
@ -186,7 +186,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
badAttachment = true;
}
if (r.has_reply_markup()) {
result->_mtpKeyboard = MakeUnique<MTPReplyMarkup>(r.vreply_markup);
result->_mtpKeyboard = std_::make_unique<MTPReplyMarkup>(r.vreply_markup);
}
} break;
@ -194,7 +194,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
const auto &r(message->c_botInlineMessageMediaContact());
result->sendData.reset(new internal::SendContact(qs(r.vfirst_name), qs(r.vlast_name), qs(r.vphone_number)));
if (r.has_reply_markup()) {
result->_mtpKeyboard = MakeUnique<MTPReplyMarkup>(r.vreply_markup);
result->_mtpKeyboard = std_::make_unique<MTPReplyMarkup>(r.vreply_markup);
}
} break;
@ -204,7 +204,7 @@ UniquePointer<Result> Result::create(uint64 queryId, const MTPBotInlineResult &m
}
if (badAttachment || !result->sendData || !result->sendData->isValid()) {
return UniquePointer<Result>();
return std_::unique_ptr<Result>();
}
if (result->_thumb->isNull() && !result->_thumb_url.isEmpty()) {

View file

@ -43,10 +43,10 @@ private:
public:
// Constructor is public only for MakeUnique<>() to work.
// Constructor is public only for std::make_unique<>() to work.
// You should use create() static method instead.
explicit Result(const Creator &creator);
static UniquePointer<Result> create(uint64 queryId, const MTPBotInlineResult &mtpData);
static std_::unique_ptr<Result> create(uint64 queryId, const MTPBotInlineResult &mtpData);
Result(const Result &other) = delete;
Result &operator=(const Result &other) = delete;
@ -112,11 +112,11 @@ private:
DocumentData *_document = nullptr;
PhotoData *_photo = nullptr;
UniquePointer<MTPReplyMarkup> _mtpKeyboard;
std_::unique_ptr<MTPReplyMarkup> _mtpKeyboard;
ImagePtr _thumb, _locationThumb;
UniquePointer<internal::SendData> sendData;
std_::unique_ptr<internal::SendData> sendData;
};
Result *getResultFromLoader(FileLoader *loader);

View file

@ -2435,12 +2435,12 @@ namespace Local {
if (msgText.isEmpty() && !msgReplyTo) {
h->clearMsgDraft();
} else {
h->setMsgDraft(MakeUnique<HistoryDraft>(msgText, msgReplyTo, msgCursor, msgPreviewCancelled));
h->setMsgDraft(std_::make_unique<HistoryDraft>(msgText, msgReplyTo, msgCursor, msgPreviewCancelled));
}
if (!editMsgId) {
h->clearEditDraft();
} else {
h->setEditDraft(MakeUnique<HistoryEditDraft>(editText, editMsgId, editCursor, editPreviewCancelled));
h->setEditDraft(std_::make_unique<HistoryEditDraft>(editText, editMsgId, editCursor, editPreviewCancelled));
}
}

View file

@ -509,7 +509,7 @@ bool MainWidget::onShareUrl(const PeerId &peer, const QString &url, const QStrin
return false;
}
History *h = App::history(peer);
h->setMsgDraft(MakeUnique<HistoryDraft>(url + '\n' + text, 0, MessageCursor(url.size() + 1, url.size() + 1 + text.size(), QFIXED_MAX), false));
h->setMsgDraft(std_::make_unique<HistoryDraft>(url + '\n' + text, 0, MessageCursor(url.size() + 1, url.size() + 1 + text.size(), QFIXED_MAX), false));
h->clearEditDraft();
bool opened = history.peer() && (history.peer()->id == peer);
if (opened) {
@ -527,7 +527,7 @@ bool MainWidget::onInlineSwitchChosen(const PeerId &peer, const QString &botAndQ
return false;
}
History *h = App::history(peer);
h->setMsgDraft(MakeUnique<HistoryDraft>(botAndQuery, 0, MessageCursor(botAndQuery.size(), botAndQuery.size(), QFIXED_MAX), false));
h->setMsgDraft(std_::make_unique<HistoryDraft>(botAndQuery, 0, MessageCursor(botAndQuery.size(), botAndQuery.size(), QFIXED_MAX), false));
h->clearEditDraft();
bool opened = history.peer() && (history.peer()->id == peer);
if (opened) {

View file

@ -1026,13 +1026,13 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
} break;
case mtpc_documentAttributeAnimated: if (type == FileDocument || type == StickerDocument || type == VideoDocument) {
type = AnimatedDocument;
_additional.clear();
_additional = nullptr;
} break;
case mtpc_documentAttributeSticker: {
const auto &d(attributes[i].c_documentAttributeSticker());
if (type == FileDocument) {
type = StickerDocument;
_additional = MakeUnique<StickerData>();
_additional = std_::make_unique<StickerData>();
}
if (sticker()) {
sticker()->alt = qs(d.valt);
@ -1052,10 +1052,10 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
if (type == FileDocument) {
if (d.is_voice()) {
type = VoiceDocument;
_additional = MakeUnique<VoiceData>();
_additional = std_::make_unique<VoiceData>();
} else {
type = SongDocument;
_additional = MakeUnique<SongData>();
_additional = std_::make_unique<SongData>();
}
}
if (voice()) {
@ -1080,7 +1080,7 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
if (type == StickerDocument) {
if (dimensions.width() <= 0 || dimensions.height() <= 0 || dimensions.width() > StickerMaxSize || dimensions.height() > StickerMaxSize || size > StickerInMemory) {
type = FileDocument;
_additional.clear();
_additional = nullptr;
}
}
}

View file

@ -1032,7 +1032,7 @@ public:
ImagePtr makeReplyPreview();
StickerData *sticker() {
return (type == StickerDocument) ? static_cast<StickerData*>(_additional.data()) : nullptr;
return (type == StickerDocument) ? static_cast<StickerData*>(_additional.get()) : nullptr;
}
void checkSticker() {
StickerData *s = sticker();
@ -1052,16 +1052,16 @@ public:
}
}
SongData *song() {
return (type == SongDocument) ? static_cast<SongData*>(_additional.data()) : nullptr;
return (type == SongDocument) ? static_cast<SongData*>(_additional.get()) : nullptr;
}
const SongData *song() const {
return (type == SongDocument) ? static_cast<const SongData*>(_additional.data()) : nullptr;
return (type == SongDocument) ? static_cast<const SongData*>(_additional.get()) : nullptr;
}
VoiceData *voice() {
return (type == VoiceDocument) ? static_cast<VoiceData*>(_additional.data()) : nullptr;
return (type == VoiceDocument) ? static_cast<VoiceData*>(_additional.get()) : nullptr;
}
const VoiceData *voice() const {
return (type == VoiceDocument) ? static_cast<const VoiceData*>(_additional.data()) : nullptr;
return (type == VoiceDocument) ? static_cast<const VoiceData*>(_additional.get()) : nullptr;
}
bool isAnimation() const {
return (type == AnimatedDocument) || !mime.compare(qstr("image/gif"), Qt::CaseInsensitive);
@ -1070,7 +1070,7 @@ public:
return (type == AnimatedDocument) && !mime.compare(qstr("video/mp4"), Qt::CaseInsensitive);
}
bool isMusic() const {
return (type == SongDocument) ? !static_cast<SongData*>(_additional.data())->title.isEmpty() : false;
return (type == SongDocument) ? !static_cast<SongData*>(_additional.get())->title.isEmpty() : false;
}
bool isVideo() const {
return (type == VideoDocument);
@ -1142,7 +1142,7 @@ private:
FileLocation _location;
QByteArray _data;
UniquePointer<DocumentAdditionalData> _additional;
std_::unique_ptr<DocumentAdditionalData> _additional;
int32 _duration = -1;
ActionOnLoad _actionOnLoad = ActionOnLoadNone;

View file

@ -29,16 +29,16 @@ namespace Ui {
namespace Toast {
Instance::Instance(const Config &config, QWidget *widgetParent, const Private &)
: _a_fade(animation(this, &Instance::step_fade))
, _hideAtMs(getms(true) + config.durationMs) {
_widget = MakeUnique<internal::Widget>(widgetParent, config);
: _a_fade(animation(this, &Instance::step_fade))
, _hideAtMs(getms(true) + config.durationMs) {
_widget = std_::make_unique<internal::Widget>(widgetParent, config);
_a_fade.start();
}
void Show(const Config &config) {
if (internal::Manager *manager = internal::Manager::instance()) {
if (Window *window = App::wnd()) {
auto toast = MakeUnique<Instance>(config, window, Instance::Private());
auto toast = std_::make_unique<Instance>(config, window, Instance::Private());
manager->addToast(std_::move(toast));
}
}

View file

@ -58,7 +58,7 @@ private:
// ToastManager should reset _widget pointer if _widget is destroyed.
friend class internal::Manager;
friend void Show(const Config &config);
UniquePointer<internal::Widget> _widget;
std_::unique_ptr<internal::Widget> _widget;
};

View file

@ -47,10 +47,10 @@ Manager *Manager::instance() {
return _instance;
}
void Manager::addToast(UniquePointer<Instance> &&toast) {
void Manager::addToast(std_::unique_ptr<Instance> &&toast) {
_toasts.push_back(toast.release());
Instance *t = _toasts.back();
Widget *widget = t->_widget.data();
Widget *widget = t->_widget.get();
_toastByWidget.insert(widget, t);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(onToastWidgetDestroyed(QObject*)));

View file

@ -36,7 +36,7 @@ public:
static Manager *instance();
void addToast(UniquePointer<Instance> &&toast);
void addToast(std_::unique_ptr<Instance> &&toast);
~Manager();

View file

@ -848,7 +848,7 @@ bool Window::ui_isMediaViewShown() {
void Window::ui_showMediaPreview(DocumentData *document) {
if (!document || ((!document->isAnimation() || !document->loaded()) && !document->sticker())) return;
if (!_mediaPreview) {
_mediaPreview = MakeUnique<MediaPreviewWidget>(this);
_mediaPreview = std_::make_unique<MediaPreviewWidget>(this);
resizeEvent(nullptr);
}
if (_mediaPreview->isHidden()) {
@ -860,7 +860,7 @@ void Window::ui_showMediaPreview(DocumentData *document) {
void Window::ui_showMediaPreview(PhotoData *photo) {
if (!photo) return;
if (!_mediaPreview) {
_mediaPreview = MakeUnique<MediaPreviewWidget>(this);
_mediaPreview = std_::make_unique<MediaPreviewWidget>(this);
resizeEvent(nullptr);
}
if (_mediaPreview->isHidden()) {

View file

@ -315,7 +315,7 @@ private:
MainWidget *main = nullptr;
SettingsWidget *settings = nullptr;
BackgroundWidget *layerBg = nullptr;
UniquePointer<MediaPreviewWidget> _mediaPreview;
std_::unique_ptr<MediaPreviewWidget> _mediaPreview;
QTimer _isActiveTimer;
bool _isActive = false;