1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Remove opt::optional polyfill

std::optional is supported by Xcode 10. The non-polyfill variant was already used in our code, so this is not likely to break anything that wasn't broken before.
This commit is contained in:
Gymnasiast
2020-02-01 22:11:45 +01:00
parent fd6c709128
commit ca2f37ae7f
10 changed files with 24 additions and 50 deletions

View File

@@ -1,29 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#ifdef __has_include
# if __has_include(<optional>)
# include <optional>
# elif __has_include(<experimental/optional>)
# include <experimental/optional>
# else
# error Missing <optional>
# endif
#else
# error __has_include is not defined
#endif
// `optional` and friends will be available in NS `::opt`
#if __has_include(<optional>)
namespace opt = std;
#elif __has_include(<experimental/optional>)
namespace opt = std::experimental;
#endif

View File

@@ -17,7 +17,6 @@
#include "../audio/audio.h"
#include "../core/Console.hpp"
#include "../core/Imaging.h"
#include "../core/Optional.hpp"
#include "../drawing/Drawing.h"
#include "../drawing/X8DrawingEngine.h"
#include "../localisation/Localisation.h"
@@ -33,6 +32,7 @@
#include <chrono>
#include <cstdlib>
#include <memory>
#include <optional>
#include <string>
using namespace std::literals::string_literals;
@@ -135,7 +135,7 @@ static std::string screenshot_get_formatted_date_time()
return formatted;
}
static opt::optional<std::string> screenshot_get_next_path()
static std::optional<std::string> screenshot_get_next_path()
{
auto screenshotDirectory = screenshot_get_directory();
if (!platform_ensure_directory_exists(screenshotDirectory.c_str()))
@@ -173,7 +173,7 @@ std::string screenshot_dump_png(rct_drawpixelinfo* dpi)
// Get a free screenshot path
auto path = screenshot_get_next_path();
if (path == opt::nullopt)
if (path == std::nullopt)
{
return "";
}
@@ -193,7 +193,7 @@ std::string screenshot_dump_png_32bpp(int32_t width, int32_t height, const void*
{
auto path = screenshot_get_next_path();
if (path == opt::nullopt)
if (path == std::nullopt)
{
return "";
}
@@ -398,7 +398,7 @@ void screenshot_giant()
try
{
auto path = screenshot_get_next_path();
if (path == opt::nullopt)
if (path == std::nullopt)
{
throw std::runtime_error("Giant screenshot failed, unable to find a suitable destination path.");
}

View File

@@ -10,10 +10,10 @@
#ifndef _VIEWPORT_H_
#define _VIEWPORT_H_
#include "../core/Optional.hpp"
#include "../world/Location.hpp"
#include "Window.h"
#include <optional>
#include <vector>
struct paint_session;

View File

@@ -10,10 +10,11 @@
#pragma once
#include "../common.h"
#include "../core/Optional.hpp"
#include "../object/ObjectLimits.h"
#include "../ride/Ride.h"
#include <optional>
struct rct_ride_entry;
struct ResearchItem

View File

@@ -26,6 +26,7 @@
# include <algorithm>
# include <numeric>
# include <optional>
using namespace OpenRCT2;
@@ -75,7 +76,7 @@ bool ServerListEntry::IsVersionValid() const
return version.empty() || version == network_get_version();
}
opt::optional<ServerListEntry> ServerListEntry::FromJson(const json_t* server)
std::optional<ServerListEntry> ServerListEntry::FromJson(const json_t* server)
{
auto port = json_object_get(server, "port");
auto name = json_object_get(server, "name");

View File

@@ -10,9 +10,9 @@
#pragma once
#include "../common.h"
#include "../core/Optional.hpp"
#include <future>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>
@@ -35,7 +35,7 @@ struct ServerListEntry
int32_t CompareTo(const ServerListEntry& other) const;
bool IsVersionValid() const;
static opt::optional<ServerListEntry> FromJson(const json_t* root);
static std::optional<ServerListEntry> FromJson(const json_t* root);
};
class ServerList

View File

@@ -11,7 +11,6 @@
#define _PEEP_H_
#include "../common.h"
#include "../core/Optional.hpp"
#include "../management/Finance.h"
#include "../rct12/RCT12.h"
#include "../ride/Ride.h"
@@ -20,6 +19,7 @@
#include "../world/SpriteBase.h"
#include <bitset>
#include <optional>
#define PEEP_MAX_THOUGHTS 5
#define PEEP_THOUGHT_ITEM_NONE 255

View File

@@ -50,6 +50,7 @@
#include <cstring>
#include <functional>
#include <iterator>
#include <optional>
S6Exporter::S6Exporter()
{
@@ -457,7 +458,7 @@ void S6Exporter::ExportParkName()
{
auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark();
auto stringId = AllocateUserString(park.Name);
if (stringId != opt::nullopt)
if (stringId != std::nullopt)
{
_s6.park_name = *stringId;
_s6.park_name_args = 0;
@@ -517,7 +518,7 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src)
{
// Custom name, allocate user string for ride
auto stringId = AllocateUserString(src->custom_name);
if (stringId != opt::nullopt)
if (stringId != std::nullopt)
{
dst->name = *stringId;
dst->name_arguments = 0;
@@ -1067,7 +1068,7 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src)
if (src->name != nullptr)
{
auto stringId = AllocateUserString(src->name);
if (stringId != opt::nullopt)
if (stringId != std::nullopt)
{
dst->name_string_idx = *stringId;
generateName = false;
@@ -1338,7 +1339,7 @@ void S6Exporter::ExportBanner(RCT12Banner& dst, const Banner& src)
}
auto stringId = AllocateUserString(bannerText);
if (stringId != opt::nullopt)
if (stringId != std::nullopt)
{
dst.string_idx = *stringId;
}
@@ -1551,7 +1552,7 @@ void S6Exporter::ExportTileElement(RCT12TileElement* dst, TileElement* src)
}
}
opt::optional<uint16_t> S6Exporter::AllocateUserString(const std::string_view& value)
std::optional<uint16_t> S6Exporter::AllocateUserString(const std::string_view& value)
{
auto nextId = _userStrings.size();
if (nextId < RCT12_MAX_USER_STRINGS)

View File

@@ -10,10 +10,10 @@
#pragma once
#include "../common.h"
#include "../core/Optional.hpp"
#include "../object/ObjectList.h"
#include "../scenario/Scenario.h"
#include <optional>
#include <string>
#include <string_view>
#include <vector>
@@ -72,6 +72,6 @@ private:
void ExportTileElements();
void ExportTileElement(RCT12TileElement* dst, TileElement* src);
opt::optional<uint16_t> AllocateUserString(const std::string_view& value);
std::optional<uint16_t> AllocateUserString(const std::string_view& value);
void ExportUserStrings();
};

View File

@@ -25,7 +25,6 @@
#include "../common.h"
#include "../config/Config.h"
#include "../core/Guard.hpp"
#include "../core/Optional.hpp"
#include "../interface/Window.h"
#include "../localisation/Date.h"
#include "../localisation/Localisation.h"
@@ -70,6 +69,7 @@
#include <cstdlib>
#include <iterator>
#include <limits>
#include <optional>
using namespace OpenRCT2;
@@ -6594,9 +6594,9 @@ uint64_t ride_entry_get_supported_track_pieces(const rct_ride_entry* rideEntry)
return supportedPieces;
}
static opt::optional<int32_t> ride_get_smallest_station_length(Ride* ride)
static std::optional<int32_t> ride_get_smallest_station_length(Ride* ride)
{
opt::optional<int32_t> result;
std::optional<int32_t> result;
for (const auto& station : ride->stations)
{
if (!station.Start.isNull())