Replace boost::optional with std::optional (#4877)

This commit is contained in:
pajlada
2023-10-08 18:50:48 +02:00
committed by GitHub
parent fe4d6121a2
commit fec45889a8
88 changed files with 428 additions and 383 deletions
+1 -1
View File
@@ -914,7 +914,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
c->addMessage(_message);
auto overrideFlags = boost::optional<MessageFlags>(_message->flags);
auto overrideFlags = std::optional<MessageFlags>(_message->flags);
overrideFlags->set(MessageFlag::DoNotTriggerNotification);
overrideFlags->set(MessageFlag::DoNotLog);
+2 -2
View File
@@ -727,14 +727,14 @@ void PubSub::registerNonce(QString nonce, NonceInfo info)
this->nonces_[nonce] = std::move(info);
}
boost::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
std::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
{
// TODO: This should also DELETE the nonceinfo from the map
auto it = this->nonces_.find(nonce);
if (it == this->nonces_.end())
{
return boost::none;
return std::nullopt;
}
return it->second;
+2 -2
View File
@@ -5,7 +5,6 @@
#include "util/ExponentialBackoff.hpp"
#include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp>
#include <QJsonObject>
#include <QString>
@@ -15,6 +14,7 @@
#include <chrono>
#include <map>
#include <memory>
#include <optional>
#include <thread>
#include <unordered_map>
#include <vector>
@@ -188,7 +188,7 @@ private:
void registerNonce(QString nonce, NonceInfo nonceInfo);
// Find client associated with a nonce
boost::optional<NonceInfo> findNonceInfo(QString nonce);
std::optional<NonceInfo> findNonceInfo(QString nonce);
std::unordered_map<QString, NonceInfo> nonces_;
+5 -5
View File
@@ -149,8 +149,8 @@ void TwitchBadges::loaded()
}
}
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
const QString &version) const
std::optional<EmotePtr> TwitchBadges::badge(const QString &set,
const QString &version) const
{
auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set);
@@ -162,10 +162,10 @@ boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
return it2->second;
}
}
return boost::none;
return std::nullopt;
}
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set) const
std::optional<EmotePtr> TwitchBadges::badge(const QString &set) const
{
auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set);
@@ -176,7 +176,7 @@ boost::optional<EmotePtr> TwitchBadges::badge(const QString &set) const
return it->second.begin()->second;
}
}
return boost::none;
return std::nullopt;
}
void TwitchBadges::getBadgeIcon(const QString &name, BadgeIconCallback callback)
+4 -4
View File
@@ -3,7 +3,6 @@
#include "common/UniqueAccess.hpp"
#include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp>
#include <QIcon>
#include <QJsonObject>
@@ -11,6 +10,7 @@
#include <QString>
#include <memory>
#include <optional>
#include <queue>
#include <shared_mutex>
#include <unordered_map>
@@ -35,10 +35,10 @@ public:
static TwitchBadges *instance();
// Get badge from name and version
boost::optional<EmotePtr> badge(const QString &set,
const QString &version) const;
std::optional<EmotePtr> badge(const QString &set,
const QString &version) const;
// Get first matching badge with name, regardless of version
boost::optional<EmotePtr> badge(const QString &set) const;
std::optional<EmotePtr> badge(const QString &set) const;
void getBadgeIcon(const QString &name, BadgeIconCallback callback);
void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback);
+25 -25
View File
@@ -35,6 +35,7 @@
#include "singletons/Settings.hpp"
#include "singletons/Toasts.hpp"
#include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include "util/PostToThread.hpp"
#include "util/QStringHash.hpp"
#include "widgets/Window.hpp"
@@ -396,14 +397,14 @@ bool TwitchChannel::isChannelPointRewardKnown(const QString &rewardId)
return it != pointRewards->end();
}
boost::optional<ChannelPointReward> TwitchChannel::channelPointReward(
std::optional<ChannelPointReward> TwitchChannel::channelPointReward(
const QString &rewardId) const
{
auto rewards = this->channelPointRewards_.accessConst();
auto it = rewards->find(rewardId);
if (it == rewards->end())
return boost::none;
return std::nullopt;
return it->second;
}
@@ -751,35 +752,34 @@ SharedAccessGuard<const TwitchChannel::StreamStatus>
return this->streamStatus_.accessConst();
}
boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
std::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
{
auto emotes = this->bttvEmotes_.get();
auto it = emotes->find(name);
if (it == emotes->end())
return boost::none;
return std::nullopt;
return it->second;
}
boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
std::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
{
auto emotes = this->ffzEmotes_.get();
auto it = emotes->find(name);
if (it == emotes->end())
return boost::none;
return std::nullopt;
return it->second;
}
boost::optional<EmotePtr> TwitchChannel::seventvEmote(
const EmoteName &name) const
std::optional<EmotePtr> TwitchChannel::seventvEmote(const EmoteName &name) const
{
auto emotes = this->seventvEmotes_.get();
auto it = emotes->find(name);
if (it == emotes->end())
{
return boost::none;
return std::nullopt;
}
return it->second;
}
@@ -865,7 +865,7 @@ void TwitchChannel::removeBttvEmote(
}
this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/,
removed.get()->name.string);
(*removed)->name.string);
}
void TwitchChannel::addSeventvEmote(
@@ -904,7 +904,7 @@ void TwitchChannel::removeSeventvEmote(
}
this->addOrReplaceLiveUpdatesAddRemove(false, "7TV", dispatch.actorName,
removed.get()->name.string);
(*removed)->name.string);
}
void TwitchChannel::updateSeventvUser(
@@ -955,13 +955,13 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
return;
}
boost::optional<QString> oldUserID = boost::make_optional(
const auto oldUserID = makeConditionedOptional(
!this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID,
this->seventvUserID_);
boost::optional<QString> oldEmoteSetID =
boost::make_optional(!this->seventvEmoteSetID_.isEmpty() &&
this->seventvEmoteSetID_ != newEmoteSetID,
this->seventvEmoteSetID_);
const auto oldEmoteSetID =
makeConditionedOptional(!this->seventvEmoteSetID_.isEmpty() &&
this->seventvEmoteSetID_ != newEmoteSetID,
this->seventvEmoteSetID_);
this->seventvUserID_ = newUserID;
this->seventvEmoteSetID_ = newEmoteSetID;
@@ -974,8 +974,8 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
if (oldUserID || oldEmoteSetID)
{
getApp()->twitch->dropSeventvChannel(
oldUserID.get_value_or(QString()),
oldEmoteSetID.get_value_or(QString()));
oldUserID.value_or(QString()),
oldEmoteSetID.value_or(QString()));
}
}
});
@@ -1538,8 +1538,8 @@ void TwitchChannel::createClip()
});
}
boost::optional<EmotePtr> TwitchChannel::twitchBadge(
const QString &set, const QString &version) const
std::optional<EmotePtr> TwitchChannel::twitchBadge(const QString &set,
const QString &version) const
{
auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set);
@@ -1551,20 +1551,20 @@ boost::optional<EmotePtr> TwitchChannel::twitchBadge(
return it2->second;
}
}
return boost::none;
return std::nullopt;
}
boost::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
std::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
{
return this->ffzCustomModBadge_.get();
}
boost::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const
std::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const
{
return this->ffzCustomVipBadge_.get();
}
boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
std::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
{
auto sets = this->cheerEmoteSets_.access();
for (const auto &set : *sets)
@@ -1590,7 +1590,7 @@ boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
}
}
}
return boost::none;
return std::nullopt;
}
void TwitchChannel::updateSevenTVActivity()
+11 -12
View File
@@ -9,7 +9,6 @@
#include "providers/twitch/TwitchEmotes.hpp"
#include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <boost/signals2.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QColor>
@@ -134,9 +133,9 @@ public:
SharedAccessGuard<const StreamStatus> accessStreamStatus() const;
// Emotes
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
boost::optional<EmotePtr> seventvEmote(const EmoteName &name) const;
std::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
std::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
std::optional<EmotePtr> seventvEmote(const EmoteName &name) const;
std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const;
std::shared_ptr<const EmoteMap> seventvEmotes() const;
@@ -172,13 +171,13 @@ public:
const QString &newEmoteSetID);
// Badges
boost::optional<EmotePtr> ffzCustomModBadge() const;
boost::optional<EmotePtr> ffzCustomVipBadge() const;
boost::optional<EmotePtr> twitchBadge(const QString &set,
const QString &version) const;
std::optional<EmotePtr> ffzCustomModBadge() const;
std::optional<EmotePtr> ffzCustomVipBadge() const;
std::optional<EmotePtr> twitchBadge(const QString &set,
const QString &version) const;
// Cheers
boost::optional<CheerEmote> cheerEmote(const QString &string);
std::optional<CheerEmote> cheerEmote(const QString &string);
// Replies
/**
@@ -217,7 +216,7 @@ public:
channelPointRewardAdded;
void addChannelPointReward(const ChannelPointReward &reward);
bool isChannelPointRewardKnown(const QString &rewardId);
boost::optional<ChannelPointReward> channelPointReward(
std::optional<ChannelPointReward> channelPointReward(
const QString &rewardId) const;
// Live status
@@ -342,8 +341,8 @@ protected:
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> seventvEmotes_;
Atomic<boost::optional<EmotePtr>> ffzCustomModBadge_;
Atomic<boost::optional<EmotePtr>> ffzCustomVipBadge_;
Atomic<std::optional<EmotePtr>> ffzCustomModBadge_;
Atomic<std::optional<EmotePtr>> ffzCustomVipBadge_;
private:
// Badges
+15 -15
View File
@@ -228,8 +228,8 @@ MessagePtr TwitchMessageBuilder::build()
this->args.channelPointRewardId);
if (reward)
{
this->appendChannelPointRewardMessage(
reward.get(), this, this->channel->isMod(),
TwitchMessageBuilder::appendChannelPointRewardMessage(
*reward, this, this->channel->isMod(),
this->channel->isBroadcaster());
}
}
@@ -1069,7 +1069,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
const auto &globalSeventvEmotes = app->twitch->getSeventvEmotes();
auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{};
auto emote = std::optional<EmotePtr>{};
bool zeroWidth = false;
// Emote order:
@@ -1115,7 +1115,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
!this->isEmpty())
{
// Attempt to merge current zero-width emote into any previous emotes
auto asEmote = dynamic_cast<EmoteElement *>(&this->back());
auto *asEmote = dynamic_cast<EmoteElement *>(&this->back());
if (asEmote)
{
// Make sure to access asEmote before taking ownership when releasing
@@ -1124,18 +1124,18 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
auto baseEmoteElement = this->releaseBack();
std::vector<LayeredEmoteElement::Emote> layers = {
{baseEmote, baseEmoteElement->getFlags()},
{emote.get(), flags}};
{baseEmote, baseEmoteElement->getFlags()}, {*emote, flags}};
this->emplace<LayeredEmoteElement>(
std::move(layers), baseEmoteElement->getFlags() | flags,
this->textColor_);
return Success;
}
auto asLayered = dynamic_cast<LayeredEmoteElement *>(&this->back());
auto *asLayered =
dynamic_cast<LayeredEmoteElement *>(&this->back());
if (asLayered)
{
asLayered->addEmoteLayer({emote.get(), flags});
asLayered->addEmoteLayer({*emote, flags});
asLayered->addFlags(flags);
return Success;
}
@@ -1143,15 +1143,15 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
// No emote to merge with, just show as regular emote
}
this->emplace<EmoteElement>(emote.get(), flags, this->textColor_);
this->emplace<EmoteElement>(*emote, flags, this->textColor_);
return Success;
}
return Failure;
}
boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
const Badge &badge)
std::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
const Badge &badge) const
{
if (auto channelBadge =
this->twitchChannel->twitchBadge(badge.key_, badge.value_))
@@ -1165,7 +1165,7 @@ boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
return globalBadge;
}
return boost::none;
return std::nullopt;
}
std::unordered_map<QString, QString> TwitchMessageBuilder::parseBadgeInfoTag(
@@ -1248,7 +1248,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
if (auto customModBadge = this->twitchChannel->ffzCustomModBadge())
{
this->emplace<ModBadgeElement>(
customModBadge.get(),
*customModBadge,
MessageElementFlag::BadgeChannelAuthority)
->setTooltip((*customModBadge)->tooltip.string);
// early out, since we have to add a custom badge element here
@@ -1260,7 +1260,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
if (auto customVipBadge = this->twitchChannel->ffzCustomVipBadge())
{
this->emplace<VipBadgeElement>(
customVipBadge.get(),
*customVipBadge,
MessageElementFlag::BadgeChannelAuthority)
->setTooltip((*customVipBadge)->tooltip.string);
// early out, since we have to add a custom badge element here
@@ -1302,7 +1302,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
}
}
this->emplace<BadgeElement>(badgeEmote.get(), badge.flag_)
this->emplace<BadgeElement>(*badgeEmote, badge.flag_)
->setTooltip(tooltip);
}
@@ -4,11 +4,11 @@
#include "common/Outcome.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include <boost/optional.hpp>
#include <IrcMessage>
#include <QString>
#include <QVariant>
#include <optional>
#include <unordered_map>
namespace chatterino {
@@ -108,7 +108,7 @@ private:
void runIgnoreReplaces(std::vector<TwitchEmoteOccurrence> &twitchEmotes);
boost::optional<EmotePtr> getTwitchBadge(const Badge &badge);
std::optional<EmotePtr> getTwitchBadge(const Badge &badge) const;
Outcome tryAppendEmote(const EmoteName &name) override;
void addWords(const QStringList &words,
+6 -6
View File
@@ -1741,7 +1741,7 @@ void Helix::updateEmoteMode(
void Helix::updateFollowerMode(
QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration,
std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{
@@ -1758,7 +1758,7 @@ void Helix::updateFollowerMode(
void Helix::updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration,
std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{
@@ -1777,7 +1777,7 @@ void Helix::updateNonModeratorChatDelay(
void Helix::updateSlowMode(
QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime,
std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{
@@ -2138,7 +2138,7 @@ void Helix::fetchModerators(
// Ban/timeout a user
// https://dev.twitch.tv/docs/api/reference#ban-user
void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason,
std::optional<int> duration, QString reason,
ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback)
{
@@ -2890,14 +2890,14 @@ NetworkRequest Helix::makeRequest(const QString &url, const QUrlQuery &urlQuery,
{
qCDebug(chatterinoTwitch)
<< "Helix::makeRequest called without a client ID set BabyRage";
// return boost::none;
// return std::nullopt;
}
if (this->oauthToken.isEmpty())
{
qCDebug(chatterinoTwitch)
<< "Helix::makeRequest called without an oauth token set BabyRage";
// return boost::none;
// return std::nullopt;
}
const QString baseUrl("https://api.twitch.tv/helix/");
+17 -17
View File
@@ -3,9 +3,9 @@
#include "common/Aliases.hpp"
#include "common/NetworkRequest.hpp"
#include "providers/twitch/TwitchEmotes.hpp"
#include "util/Helpers.hpp"
#include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <QDateTime>
#include <QJsonArray>
#include <QJsonObject>
@@ -15,6 +15,7 @@
#include <QUrlQuery>
#include <functional>
#include <optional>
#include <unordered_set>
#include <vector>
@@ -277,24 +278,23 @@ struct HelixChannelEmote {
struct HelixChatSettings {
const QString broadcasterId;
const bool emoteMode;
// boost::none if disabled
const boost::optional<int> followerModeDuration; // time in minutes
const boost::optional<int>
nonModeratorChatDelayDuration; // time in seconds
const boost::optional<int> slowModeWaitTime; // time in seconds
// std::nullopt if disabled
const std::optional<int> followerModeDuration; // time in minutes
const std::optional<int> nonModeratorChatDelayDuration; // time in seconds
const std::optional<int> slowModeWaitTime; // time in seconds
const bool subscriberMode;
const bool uniqueChatMode;
explicit HelixChatSettings(QJsonObject jsonObject)
: broadcasterId(jsonObject.value("broadcaster_id").toString())
, emoteMode(jsonObject.value("emote_mode").toBool())
, followerModeDuration(boost::make_optional(
, followerModeDuration(makeConditionedOptional(
jsonObject.value("follower_mode").toBool(),
jsonObject.value("follower_mode_duration").toInt()))
, nonModeratorChatDelayDuration(boost::make_optional(
, nonModeratorChatDelayDuration(makeConditionedOptional(
jsonObject.value("non_moderator_chat_delay").toBool(),
jsonObject.value("non_moderator_chat_delay_duration").toInt()))
, slowModeWaitTime(boost::make_optional(
, slowModeWaitTime(makeConditionedOptional(
jsonObject.value("slow_mode").toBool(),
jsonObject.value("slow_mode_wait_time").toInt()))
, subscriberMode(jsonObject.value("subscriber_mode").toBool())
@@ -908,7 +908,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateFollowerMode(
QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration,
std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0;
@@ -917,7 +917,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration,
std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0;
@@ -926,7 +926,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateSlowMode(
QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime,
std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0;
@@ -951,7 +951,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#ban-user
virtual void banUser(
QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason,
std::optional<int> duration, QString reason,
ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback) = 0;
@@ -1224,7 +1224,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateFollowerMode(
QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration,
std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
final;
@@ -1233,7 +1233,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration,
std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
final;
@@ -1241,7 +1241,7 @@ public:
// Updates the slow mode using
// https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateSlowMode(QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime,
std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) final;
@@ -1266,7 +1266,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#ban-user
void banUser(
QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason,
std::optional<int> duration, QString reason,
ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback) final;
+7 -7
View File
@@ -1,11 +1,12 @@
#pragma once
#include <boost/optional.hpp>
#include <magic_enum.hpp>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <optional>
namespace chatterino {
struct PubSubMessage {
@@ -27,16 +28,16 @@ struct PubSubMessage {
PubSubMessage(QJsonObject _object);
template <class InnerClass>
boost::optional<InnerClass> toInner();
std::optional<InnerClass> toInner();
};
template <class InnerClass>
boost::optional<InnerClass> PubSubMessage::toInner()
std::optional<InnerClass> PubSubMessage::toInner()
{
auto dataValue = this->object.value("data");
if (!dataValue.isObject())
{
return boost::none;
return std::nullopt;
}
auto data = dataValue.toObject();
@@ -44,14 +45,13 @@ boost::optional<InnerClass> PubSubMessage::toInner()
return InnerClass{this->nonce, data};
}
static boost::optional<PubSubMessage> parsePubSubBaseMessage(
const QString &blob)
static std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob)
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return boost::none;
return std::nullopt;
}
return PubSubMessage(jsonDoc.object());
@@ -2,11 +2,12 @@
#include "common/QLogging.hpp"
#include <boost/optional.hpp>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <optional>
namespace chatterino {
struct PubSubMessageMessage {
@@ -42,15 +43,15 @@ struct PubSubMessageMessage {
}
template <class InnerClass>
boost::optional<InnerClass> toInner() const;
std::optional<InnerClass> toInner() const;
};
template <class InnerClass>
boost::optional<InnerClass> PubSubMessageMessage::toInner() const
std::optional<InnerClass> PubSubMessageMessage::toInner() const
{
if (this->messageObject.empty())
{
return boost::none;
return std::nullopt;
}
return InnerClass{this->messageObject};