Use nullptr instead of std::unique_ptr<Type>().

This commit is contained in:
John Preston 2017-08-13 19:14:00 +03:00
parent 0bea2620b5
commit 012d59ab42
11 changed files with 29 additions and 24 deletions

View file

@ -601,7 +601,7 @@ ContactsBox::Inner::Inner(QWidget *parent, ChatData *chat, MembersFilter members
, _aboutWidth(st::boxWideWidth - st::contactsPadding.left() - st::contactsPadding.right())
, _aboutAllAdmins(st::defaultTextStyle, lang(lng_chat_about_all_admins), _defaultOptions, _aboutWidth)
, _aboutAdmins(st::defaultTextStyle, lang(lng_chat_about_admins), _defaultOptions, _aboutWidth)
, _customList((membersFilter == MembersFilter::Recent) ? std::unique_ptr<Dialogs::IndexedList>() : std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _customList((membersFilter == MembersFilter::Recent) ? nullptr : std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Add))
, _contacts((membersFilter == MembersFilter::Recent) ? App::main()->contactsList() : _customList.get())
, _addContactLnk(this, lang(lng_add_contact_button)) {
initList();

View file

@ -78,12 +78,13 @@ void PrivacyExceptionsBoxController::rowClicked(gsl::not_null<PeerListRow*> row)
}
std::unique_ptr<PrivacyExceptionsBoxController::Row> PrivacyExceptionsBoxController::createRow(gsl::not_null<History*> history) {
if (auto user = history->peer->asUser()) {
if (!user->isSelf()) {
return std::make_unique<Row>(history);
}
if (history->peer->isSelf()) {
return nullptr;
}
return std::unique_ptr<Row>();
if (auto user = history->peer->asUser()) {
return std::make_unique<Row>(history);
}
return nullptr;
}
} // namespace

View file

@ -258,7 +258,7 @@ public:
return _searchController ? _searchController->isLoading() : false;
}
virtual std::unique_ptr<PeerListRow> createSearchRow(gsl::not_null<PeerData*> peer) {
return std::unique_ptr<PeerListRow>();
return nullptr;
}
bool isRowSelected(gsl::not_null<PeerData*> peer) {

View file

@ -4275,7 +4275,7 @@ void HistoryWidget::uploadFiles(const QStringList &files, SendMediaType type) {
if (!canWriteMessage()) return;
auto caption = QString();
uploadFilesAfterConfirmation(files, QByteArray(), QImage(), std::unique_ptr<FileLoadTask::MediaInformation>(), type, caption);
uploadFilesAfterConfirmation(files, QByteArray(), QImage(), nullptr, type, caption);
}
void HistoryWidget::uploadFilesAfterConfirmation(const QStringList &files, const QByteArray &content, const QImage &image, std::unique_ptr<FileLoadTask::MediaInformation> information, SendMediaType type, QString caption) {

View file

@ -121,7 +121,7 @@ std::unique_ptr<ItemBase> ItemBase::createLayout(gsl::not_null<Context*> context
case Type::Game: return std::make_unique<internal::Game>(context, result); break;
case Type::Contact: return std::make_unique<internal::Contact>(context, result); break;
}
return std::unique_ptr<ItemBase>();
return nullptr;
}
std::unique_ptr<ItemBase> ItemBase::createLayoutGif(gsl::not_null<Context*> context, DocumentData *document) {

View file

@ -60,7 +60,7 @@ std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult
};
Type type = getInlineResultType(mtpData);
if (type == Type::Unknown) {
return std::unique_ptr<Result>();
return nullptr;
}
auto result = std::make_unique<Result>(Creator{ queryId, type });
@ -100,18 +100,18 @@ std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult
bool badAttachment = (result->_photo && !result->_photo->access) || (result->_document && !result->_document->isValid());
if (!message) {
return std::unique_ptr<Result>();
return nullptr;
}
// Ensure required media fields for layouts.
if (result->_type == Type::Photo) {
if (!result->_photo && result->_content_url.isEmpty()) {
return std::unique_ptr<Result>();
return nullptr;
}
result->createPhoto();
} else if (result->_type == Type::File || result->_type == Type::Gif || result->_type == Type::Sticker) {
if (!result->_document && result->_content_url.isEmpty()) {
return std::unique_ptr<Result>();
return nullptr;
}
result->createDocument();
}
@ -186,7 +186,7 @@ std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult
}
if (badAttachment || !result->sendData || !result->sendData->isValid()) {
return std::unique_ptr<Result>();
return nullptr;
}
if (result->_thumb->isNull() && !result->_thumb_url.isEmpty()) {

View file

@ -616,7 +616,7 @@ bool Mixer::fadedStop(AudioMsgId::Type type, bool *fadedStart) {
void Mixer::play(const AudioMsgId &audio, int64 position) {
setSongVolume(Global::SongVolume());
play(audio, std::unique_ptr<VideoSoundData>(), position);
play(audio, nullptr, position);
}
void Mixer::play(const AudioMsgId &audio, std::unique_ptr<VideoSoundData> videoData, int64 position) {

View file

@ -121,7 +121,7 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createSearchRow(gsl::not
if (auto user = peer->asUser()) {
return createRow(user);
}
return std::unique_ptr<PeerListRow>();
return nullptr;
}
template <typename Callback>
@ -691,12 +691,13 @@ AddParticipantBoxController::AddParticipantBoxController(gsl::not_null<ChannelDa
}
std::unique_ptr<PeerListRow> AddParticipantBoxController::createSearchRow(gsl::not_null<PeerData*> peer) {
if (!peer->isSelf()) {
if (auto user = peer->asUser()) {
return createRow(user);
}
if (peer->isSelf()) {
return nullptr;
}
return std::unique_ptr<PeerListRow>();
if (auto user = peer->asUser()) {
return createRow(user);
}
return nullptr;
}
void AddParticipantBoxController::prepare() {

View file

@ -83,12 +83,15 @@ void BlockUserBoxController::rowClicked(gsl::not_null<PeerListRow*> row) {
}
std::unique_ptr<BlockUserBoxController::Row> BlockUserBoxController::createRow(gsl::not_null<History*> history) {
if (history->peer->isSelf()) {
return nullptr;
}
if (auto user = history->peer->asUser()) {
auto row = std::make_unique<Row>(history);
updateIsBlocked(row.get(), user);
return row;
}
return std::unique_ptr<Row>();
return nullptr;
}
} // namespace

View file

@ -392,7 +392,7 @@ void CountrySelectBox::Inner::mousePressEvent(QMouseEvent *e) {
if (_ripples.size() <= _pressed) {
_ripples.reserve(_pressed + 1);
while (_ripples.size() <= _pressed) {
_ripples.push_back(std::unique_ptr<Ui::RippleAnimation>());
_ripples.push_back(nullptr);
}
}
if (!_ripples[_pressed]) {

View file

@ -893,7 +893,7 @@ std::unique_ptr<Preview> GeneratePreview(const QString &filepath, const CurrentD
auto result = std::make_unique<Preview>();
result->path = filepath;
if (!LoadFromFile(filepath, &result->instance, &result->content)) {
return std::unique_ptr<Preview>();
return nullptr;
}
result->preview = Generator(result->instance, data).generate();
return result;