Replace boost::optional with std::optional (#4877)
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
boost::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const
|
||||
std::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
|
||||
@@ -22,7 +22,7 @@ boost::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SeventvBadges::assignBadgeToUser(const QString &badgeID,
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include "common/Singleton.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -20,7 +20,7 @@ class SeventvBadges : public Singleton
|
||||
{
|
||||
public:
|
||||
// Return the badge, if any, that is assigned to the user
|
||||
boost::optional<EmotePtr> getBadge(const UserId &id) const;
|
||||
std::optional<EmotePtr> getBadge(const UserId &id) const;
|
||||
|
||||
// Assign the given badge to the user
|
||||
void assignBadgeToUser(const QString &badgeID, const UserId &userID);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "providers/seventv/SeventvAPI.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -109,7 +110,7 @@ CreateEmoteResult createEmote(const QJsonObject &activeEmote,
|
||||
auto emote =
|
||||
Emote({emoteName, imageSet, tooltip,
|
||||
Url{EMOTE_LINK_FORMAT.arg(emoteId.string)}, zeroWidth, emoteId,
|
||||
author, boost::make_optional(aliasedName, baseEmoteName)});
|
||||
author, makeConditionedOptional(aliasedName, baseEmoteName)});
|
||||
|
||||
return {emote, emoteId, emoteName, !emote.images.getImage1()->isEmpty()};
|
||||
}
|
||||
@@ -162,7 +163,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
|
||||
bool toNonAliased = oldEmote->baseName.has_value() &&
|
||||
dispatch.emoteName == oldEmote->baseName->string;
|
||||
|
||||
auto baseName = oldEmote->baseName.get_value_or(oldEmote->name);
|
||||
auto baseName = oldEmote->baseName.value_or(oldEmote->name);
|
||||
auto emote = std::make_shared<const Emote>(Emote(
|
||||
{EmoteName{dispatch.emoteName}, oldEmote->images,
|
||||
toNonAliased
|
||||
@@ -170,7 +171,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
|
||||
: createAliasedTooltip(dispatch.emoteName, baseName.string,
|
||||
oldEmote->author.string, false),
|
||||
oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id,
|
||||
oldEmote->author, boost::make_optional(!toNonAliased, baseName)}));
|
||||
oldEmote->author, makeConditionedOptional(!toNonAliased, baseName)}));
|
||||
return emote;
|
||||
}
|
||||
|
||||
@@ -191,15 +192,14 @@ std::shared_ptr<const EmoteMap> SeventvEmotes::globalEmotes() const
|
||||
return this->global_.get();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> SeventvEmotes::globalEmote(
|
||||
const EmoteName &name) const
|
||||
std::optional<EmotePtr> SeventvEmotes::globalEmote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->global_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
||||
if (it == emotes->end())
|
||||
{
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
@@ -328,7 +328,7 @@ void SeventvEmotes::loadChannelEmotes(
|
||||
});
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> SeventvEmotes::addEmote(
|
||||
std::optional<EmotePtr> SeventvEmotes::addEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const EmoteAddDispatch &dispatch)
|
||||
{
|
||||
@@ -336,7 +336,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
|
||||
auto emoteData = dispatch.emoteJson["data"].toObject();
|
||||
if (emoteData.empty() || !checkEmoteVisibility(emoteData))
|
||||
{
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// This copies the map.
|
||||
@@ -347,7 +347,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
|
||||
// Incoming emote didn't contain any images, abort
|
||||
qCDebug(chatterinoSeventv)
|
||||
<< "Emote without images:" << dispatch.emoteJson;
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
auto emote = std::make_shared<const Emote>(std::move(result.emote));
|
||||
updatedMap[result.name] = emote;
|
||||
@@ -356,7 +356,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
|
||||
return emote;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> SeventvEmotes::updateEmote(
|
||||
std::optional<EmotePtr> SeventvEmotes::updateEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const EmoteUpdateDispatch &dispatch)
|
||||
{
|
||||
@@ -364,7 +364,7 @@ boost::optional<EmotePtr> SeventvEmotes::updateEmote(
|
||||
auto oldEmote = oldMap->findEmote(dispatch.emoteName, dispatch.emoteID);
|
||||
if (oldEmote == oldMap->end())
|
||||
{
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// This copies the map.
|
||||
@@ -378,7 +378,7 @@ boost::optional<EmotePtr> SeventvEmotes::updateEmote(
|
||||
return emote;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> SeventvEmotes::removeEmote(
|
||||
std::optional<EmotePtr> SeventvEmotes::removeEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const EmoteRemoveDispatch &dispatch)
|
||||
{
|
||||
@@ -389,7 +389,7 @@ boost::optional<EmotePtr> SeventvEmotes::removeEmote(
|
||||
{
|
||||
// We already copied the map at this point and are now discarding the copy.
|
||||
// This is fine, because this case should be really rare.
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
auto emote = it->second;
|
||||
updatedMap.erase(it);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/FlagsEnum.hpp"
|
||||
@@ -8,6 +7,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
SeventvEmotes();
|
||||
|
||||
std::shared_ptr<const EmoteMap> globalEmotes() const;
|
||||
boost::optional<EmotePtr> globalEmote(const EmoteName &name) const;
|
||||
std::optional<EmotePtr> globalEmote(const EmoteName &name) const;
|
||||
void loadGlobalEmotes();
|
||||
void setGlobalEmotes(std::shared_ptr<const EmoteMap> emotes);
|
||||
static void loadChannelEmotes(
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
*
|
||||
* @return The added emote if an emote was added.
|
||||
*/
|
||||
static boost::optional<EmotePtr> addEmote(
|
||||
static std::optional<EmotePtr> addEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const seventv::eventapi::EmoteAddDispatch &dispatch);
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
*
|
||||
* @return The updated emote if any emote was updated.
|
||||
*/
|
||||
static boost::optional<EmotePtr> updateEmote(
|
||||
static std::optional<EmotePtr> updateEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const seventv::eventapi::EmoteUpdateDispatch &dispatch);
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
*
|
||||
* @return The removed emote if any emote was removed.
|
||||
*/
|
||||
static boost::optional<EmotePtr> removeEmote(
|
||||
static std::optional<EmotePtr> removeEmote(
|
||||
Atomic<std::shared_ptr<const EmoteMap>> &map,
|
||||
const seventv::eventapi::EmoteRemoveDispatch &dispatch);
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
#include "providers/seventv/eventapi/Subscription.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace chatterino::seventv::eventapi {
|
||||
|
||||
struct Message {
|
||||
@@ -18,22 +19,22 @@ struct Message {
|
||||
Message(QJsonObject _json);
|
||||
|
||||
template <class InnerClass>
|
||||
boost::optional<InnerClass> toInner();
|
||||
std::optional<InnerClass> toInner();
|
||||
};
|
||||
|
||||
template <class InnerClass>
|
||||
boost::optional<InnerClass> Message::toInner()
|
||||
std::optional<InnerClass> Message::toInner()
|
||||
{
|
||||
return InnerClass{this->data};
|
||||
}
|
||||
|
||||
static boost::optional<Message> parseBaseMessage(const QString &blob)
|
||||
static std::optional<Message> parseBaseMessage(const QString &blob)
|
||||
{
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
|
||||
|
||||
if (jsonDoc.isNull())
|
||||
{
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return Message(jsonDoc.object());
|
||||
|
||||
Reference in New Issue
Block a user