core: Replace boost::optional with std::optional
This commit is contained in:
@@ -100,6 +100,7 @@ add_library(common STATIC
|
|||||||
serialization/boost_flat_set.h
|
serialization/boost_flat_set.h
|
||||||
serialization/boost_small_vector.hpp
|
serialization/boost_small_vector.hpp
|
||||||
serialization/boost_vector.hpp
|
serialization/boost_vector.hpp
|
||||||
|
serialization/optional.h
|
||||||
string_util.cpp
|
string_util.cpp
|
||||||
string_util.h
|
string_util.h
|
||||||
swap.h
|
swap.h
|
||||||
|
66
src/common/serialization/optional.h
Normal file
66
src/common/serialization/optional.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// Copyright 2022 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/serialization/item_version_type.hpp>
|
||||||
|
#include <boost/serialization/library_version_type.hpp>
|
||||||
|
#include <boost/serialization/version.hpp>
|
||||||
|
#include <boost/serialization/split_free.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace serialization {
|
||||||
|
|
||||||
|
// Allow serialization of std::optional
|
||||||
|
template<class Archive, class T>
|
||||||
|
void save(Archive& ar, const std::optional<T>& t, const unsigned int /*version*/) {
|
||||||
|
const bool tflag = t.has_value();
|
||||||
|
ar << boost::serialization::make_nvp("initialized", tflag);
|
||||||
|
if (tflag) {
|
||||||
|
ar << boost::serialization::make_nvp("value", *t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Archive, class T>
|
||||||
|
void load(Archive& ar, std::optional<T>& t, const unsigned int version) {
|
||||||
|
bool tflag;
|
||||||
|
ar >> boost::serialization::make_nvp("initialized", tflag);
|
||||||
|
if (!tflag) {
|
||||||
|
t.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version == 0) {
|
||||||
|
boost::serialization::item_version_type item_version(0);
|
||||||
|
boost::serialization::library_version_type library_version(
|
||||||
|
ar.get_library_version()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (boost::serialization::library_version_type(3) < library_version) {
|
||||||
|
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!t.has_value()) {
|
||||||
|
t = T();
|
||||||
|
}
|
||||||
|
|
||||||
|
ar >> boost::serialization::make_nvp("value", *t);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Archive, class T>
|
||||||
|
void serialize(Archive& ar, std::optional<T>& t, const unsigned int version) {
|
||||||
|
boost::serialization::split_free(ar, t, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct version<std::optional<T>> {
|
||||||
|
BOOST_STATIC_CONSTANT(int, value = 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // serialization
|
||||||
|
} // boost
|
@@ -568,7 +568,7 @@ void System::Reset() {
|
|||||||
// TODO: Properly implement the reset
|
// TODO: Properly implement the reset
|
||||||
|
|
||||||
// Since the system is completely reinitialized, we'll have to store the deliver arg manually.
|
// Since the system is completely reinitialized, we'll have to store the deliver arg manually.
|
||||||
boost::optional<Service::APT::AppletManager::DeliverArg> deliver_arg;
|
std::optional<Service::APT::AppletManager::DeliverArg> deliver_arg;
|
||||||
if (auto apt = Service::APT::GetModule(*this)) {
|
if (auto apt = Service::APT::GetModule(*this)) {
|
||||||
deliver_arg = apt->GetAppletManager()->ReceiveDeliverArg();
|
deliver_arg = apt->GetAppletManager()->ReceiveDeliverArg();
|
||||||
}
|
}
|
||||||
|
@@ -9,10 +9,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <boost/serialization/array.hpp>
|
#include <boost/serialization/array.hpp>
|
||||||
#include <boost/serialization/optional.hpp>
|
|
||||||
#include <boost/serialization/shared_ptr.hpp>
|
#include <boost/serialization/shared_ptr.hpp>
|
||||||
#include <boost/serialization/vector.hpp>
|
#include <boost/serialization/vector.hpp>
|
||||||
|
#include "common/serialization/optional.h"
|
||||||
#include "core/global.h"
|
#include "core/global.h"
|
||||||
#include "core/hle/kernel/event.h"
|
#include "core/hle/kernel/event.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
@@ -178,10 +179,10 @@ public:
|
|||||||
|
|
||||||
ResultCode DoApplicationJump(DeliverArg arg);
|
ResultCode DoApplicationJump(DeliverArg arg);
|
||||||
|
|
||||||
boost::optional<DeliverArg> ReceiveDeliverArg() const {
|
std::optional<DeliverArg> ReceiveDeliverArg() const {
|
||||||
return deliver_arg;
|
return deliver_arg;
|
||||||
}
|
}
|
||||||
void SetDeliverArg(boost::optional<DeliverArg> arg) {
|
void SetDeliverArg(std::optional<DeliverArg> arg) {
|
||||||
deliver_arg = std::move(arg);
|
deliver_arg = std::move(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +225,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
/// Parameter data to be returned in the next call to Glance/ReceiveParameter.
|
/// Parameter data to be returned in the next call to Glance/ReceiveParameter.
|
||||||
// NOTE: A bug in gcc prevents serializing std::optional
|
// NOTE: A bug in gcc prevents serializing std::optional
|
||||||
boost::optional<MessageParameter> next_parameter;
|
std::optional<MessageParameter> next_parameter;
|
||||||
|
|
||||||
static constexpr std::size_t NumAppletSlot = 4;
|
static constexpr std::size_t NumAppletSlot = 4;
|
||||||
|
|
||||||
@@ -271,7 +272,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
ApplicationJumpParameters app_jump_parameters{};
|
ApplicationJumpParameters app_jump_parameters{};
|
||||||
boost::optional<DeliverArg> deliver_arg{};
|
std::optional<DeliverArg> deliver_arg{};
|
||||||
|
|
||||||
// Holds data about the concurrently running applets in the system.
|
// Holds data about the concurrently running applets in the system.
|
||||||
std::array<AppletSlotData, NumAppletSlot> applet_slots = {};
|
std::array<AppletSlotData, NumAppletSlot> applet_slots = {};
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/optional.hpp>
|
#include <optional>
|
||||||
#include <boost/serialization/optional.hpp>
|
#include <boost/serialization/optional.hpp>
|
||||||
#include <boost/serialization/shared_ptr.hpp>
|
#include <boost/serialization/shared_ptr.hpp>
|
||||||
#include <boost/serialization/string.hpp>
|
#include <boost/serialization/string.hpp>
|
||||||
@@ -221,7 +221,7 @@ public:
|
|||||||
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
|
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
|
||||||
/// The HTTP context that is currently bound to this session, this can be empty if no context
|
/// The HTTP context that is currently bound to this session, this can be empty if no context
|
||||||
/// has been bound. Certain commands can only be called on a session with a bound context.
|
/// has been bound. Certain commands can only be called on a session with a bound context.
|
||||||
boost::optional<Context::Handle> current_http_context;
|
std::optional<Context::Handle> current_http_context;
|
||||||
|
|
||||||
u32 session_id;
|
u32 session_id;
|
||||||
|
|
||||||
|
@@ -544,7 +544,7 @@ void NWM_UDS::OnWifiPacketReceived(const Network::WifiPacket& packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<Network::MacAddress> NWM_UDS::GetNodeMacAddress(u16 dest_node_id, u8 flags) {
|
std::optional<Network::MacAddress> NWM_UDS::GetNodeMacAddress(u16 dest_node_id, u8 flags) {
|
||||||
constexpr u8 BroadcastFlag = 0x2;
|
constexpr u8 BroadcastFlag = 0x2;
|
||||||
if ((flags & BroadcastFlag) || dest_node_id == BroadcastNetworkNodeId) {
|
if ((flags & BroadcastFlag) || dest_node_id == BroadcastNetworkNodeId) {
|
||||||
// Broadcast
|
// Broadcast
|
||||||
@@ -559,7 +559,7 @@ boost::optional<Network::MacAddress> NWM_UDS::GetNodeMacAddress(u16 dest_node_id
|
|||||||
return node.second.node_id == dest_node_id && node.second.connected;
|
return node.second.node_id == dest_node_id && node.second.connected;
|
||||||
});
|
});
|
||||||
if (destination == node_map.end()) {
|
if (destination == node_map.end()) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return destination->first;
|
return destination->first;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/optional.hpp>
|
#include <optional>
|
||||||
#include <boost/serialization/export.hpp>
|
#include <boost/serialization/export.hpp>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
@@ -506,7 +506,7 @@ private:
|
|||||||
/// Callback to parse and handle a received wifi packet.
|
/// Callback to parse and handle a received wifi packet.
|
||||||
void OnWifiPacketReceived(const Network::WifiPacket& packet);
|
void OnWifiPacketReceived(const Network::WifiPacket& packet);
|
||||||
|
|
||||||
boost::optional<Network::MacAddress> GetNodeMacAddress(u16 dest_node_id, u8 flags);
|
std::optional<Network::MacAddress> GetNodeMacAddress(u16 dest_node_id, u8 flags);
|
||||||
|
|
||||||
// Event that is signaled every time the connection status changes.
|
// Event that is signaled every time the connection status changes.
|
||||||
std::shared_ptr<Kernel::Event> connection_status_event;
|
std::shared_ptr<Kernel::Event> connection_status_event;
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/optional.hpp>
|
#include <optional>
|
||||||
#include <cryptopp/hex.h>
|
#include <cryptopp/hex.h>
|
||||||
#include <cryptopp/osrng.h>
|
#include <cryptopp/osrng.h>
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
@@ -574,30 +574,28 @@ void Movie::SetReadOnly(bool read_only_) {
|
|||||||
read_only = read_only_;
|
read_only = read_only_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boost::optional<CTMHeader> ReadHeader(const std::string& movie_file) {
|
static std::optional<CTMHeader> ReadHeader(const std::string& movie_file) {
|
||||||
FileUtil::IOFile save_record(movie_file, "rb");
|
FileUtil::IOFile save_record(movie_file, "rb");
|
||||||
const u64 size = save_record.GetSize();
|
const u64 size = save_record.GetSize();
|
||||||
|
|
||||||
if (!save_record || size <= sizeof(CTMHeader)) {
|
if (!save_record || size <= sizeof(CTMHeader)) {
|
||||||
return boost::none;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTMHeader header;
|
CTMHeader header;
|
||||||
save_record.ReadArray(&header, 1);
|
save_record.ReadArray(&header, 1);
|
||||||
|
|
||||||
if (header_magic_bytes != header.filetype) {
|
if (header_magic_bytes != header.filetype) {
|
||||||
return boost::none;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Movie::PrepareForPlayback(const std::string& movie_file) {
|
void Movie::PrepareForPlayback(const std::string& movie_file) {
|
||||||
auto header = ReadHeader(movie_file);
|
if (auto header = ReadHeader(movie_file); header) {
|
||||||
if (header == boost::none)
|
init_time = header.value().clock_init_time;
|
||||||
return;
|
}
|
||||||
|
|
||||||
init_time = header.value().clock_init_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Movie::PrepareForRecording() {
|
void Movie::PrepareForRecording() {
|
||||||
@@ -638,15 +636,15 @@ Movie::ValidationResult Movie::ValidateMovie(const std::string& movie_file) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
Movie::MovieMetadata Movie::GetMovieMetadata(const std::string& movie_file) const {
|
Movie::MovieMetadata Movie::GetMovieMetadata(const std::string& movie_file) const {
|
||||||
auto header = ReadHeader(movie_file);
|
if (auto header = ReadHeader(movie_file); header) {
|
||||||
if (header == boost::none)
|
std::array<char, 33> author{}; // Add a null terminator
|
||||||
return {};
|
std::memcpy(author.data(), header->author.data(), header->author.size());
|
||||||
|
|
||||||
std::array<char, 33> author{}; // Add a null terminator
|
return {header->program_id, std::string{author.data()}, header->rerecord_count,
|
||||||
std::memcpy(author.data(), header->author.data(), header->author.size());
|
header->input_count};
|
||||||
|
}
|
||||||
|
|
||||||
return {header->program_id, std::string{author.data()}, header->rerecord_count,
|
return {};
|
||||||
header->input_count};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Movie::Shutdown() {
|
void Movie::Shutdown() {
|
||||||
|
@@ -6,7 +6,6 @@
|
|||||||
"boost-serialization",
|
"boost-serialization",
|
||||||
"boost-system",
|
"boost-system",
|
||||||
"boost-range",
|
"boost-range",
|
||||||
"boost-optional",
|
|
||||||
"boost-icl",
|
"boost-icl",
|
||||||
"boost-date-time",
|
"boost-date-time",
|
||||||
"boost-crc",
|
"boost-crc",
|
||||||
@@ -38,6 +37,7 @@
|
|||||||
"lodepng",
|
"lodepng",
|
||||||
"glslang",
|
"glslang",
|
||||||
"soundtouch",
|
"soundtouch",
|
||||||
|
"robin-map",
|
||||||
"xbyak",
|
"xbyak",
|
||||||
"zstd",
|
"zstd",
|
||||||
"sdl2",
|
"sdl2",
|
||||||
|
Reference in New Issue
Block a user