Switch to nonstd::optional due to mac build issues

Switch usage of std::optional to nonstd::optional for now because of an
error from the Mac builder script, I cannot reproduce the problem yet
but will try to fix it later, it may not be fixable when targeting 10.7.

The header is from:

https://github.com/martinmoene/optional-lite
.

Usage is about the same, to include:

`#include "nonstd/optional.hpp"`

Then use nonstd::optional and nonstd::nullopt instead of the std::
counterparts.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2022-08-06 12:59:10 +00:00
parent fb99a07625
commit e29032d48a
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
5 changed files with 1863 additions and 12 deletions

View File

@ -456,6 +456,9 @@ add_definitions(-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=)
add_definitions(-D__STDC_FORMAT_MACROS) add_definitions(-D__STDC_FORMAT_MACROS)
# For C++, default to nonstd::optional for now due to mac build issues
add_definitions(-Doptional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD)
if(ENABLE_LINK) if(ENABLE_LINK)
# IPC linking code needs sem_timedwait which can be either in librt or pthreads # IPC linking code needs sem_timedwait which can be either in librt or pthreads
if(NOT WIN32) if(NOT WIN32)
@ -1100,6 +1103,7 @@ include_directories(
${ZLIB_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}
fex fex
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
third_party/include
third_party/include/stb third_party/include/stb
) )

View File

@ -1052,7 +1052,7 @@ bool opt_set(const wxString& name, const wxString& val)
return true; return true;
} }
const std::optional<wxGameControl> game_control = const nonstd::optional<wxGameControl> game_control =
wxGameControl::FromString(name); wxGameControl::FromString(name);
if (game_control) { if (game_control) {
if (val.empty()) { if (val.empty()) {

View File

@ -95,7 +95,7 @@ wxString GameKeyToString(const wxGameKey& game_key) {
return kGameKeyStrings[GameKeyToInt(game_key)]; return kGameKeyStrings[GameKeyToInt(game_key)];
} }
std::optional<wxGameKey> StringToGameKey(const wxString& input) { nonstd::optional<wxGameKey> StringToGameKey(const wxString& input) {
static const std::map<wxString, wxGameKey> kStringToGameKey = { static const std::map<wxString, wxGameKey> kStringToGameKey = {
{ wxT("Up"), wxGameKey::Up }, { wxT("Up"), wxGameKey::Up },
{ wxT("Down"), wxGameKey::Down }, { wxT("Down"), wxGameKey::Down },
@ -122,35 +122,35 @@ std::optional<wxGameKey> StringToGameKey(const wxString& input) {
const auto iter = kStringToGameKey.find(input); const auto iter = kStringToGameKey.find(input);
if (iter == kStringToGameKey.end()) { if (iter == kStringToGameKey.end()) {
return std::nullopt; return nonstd::nullopt;
} }
return iter->second; return iter->second;
} }
// static // static
std::optional<wxGameControl> wxGameControl::FromString(const wxString &name) { nonstd::optional<wxGameControl> wxGameControl::FromString(const wxString &name) {
static const wxString kJoypad(wxT("Joypad")); static const wxString kJoypad(wxT("Joypad"));
if (!wxStrncmp(name, kJoypad, kJoypad.size())) { if (!wxStrncmp(name, kJoypad, kJoypad.size())) {
wxLogDebug("Doesn't start with joypad"); wxLogDebug("Doesn't start with joypad");
return std::nullopt; return nonstd::nullopt;
} }
auto parts = str_split(name, wxT("/")); auto parts = str_split(name, wxT("/"));
if (parts.size() != 3) { if (parts.size() != 3) {
wxLogDebug("Wrong split size: %d", parts.size()); wxLogDebug("Wrong split size: %d", parts.size());
return std::nullopt; return nonstd::nullopt;
} }
const int joypad = parts[1][0] - wxT('1'); const int joypad = parts[1][0] - wxT('1');
if (!JoypadInRange(joypad)) { if (!JoypadInRange(joypad)) {
wxLogDebug("Wrong joypad index: %d", joypad); wxLogDebug("Wrong joypad index: %d", joypad);
return std::nullopt; return nonstd::nullopt;
} }
std::optional<wxGameKey> game_key = StringToGameKey(parts[2]); nonstd::optional<wxGameKey> game_key = StringToGameKey(parts[2]);
if (!game_key) { if (!game_key) {
wxLogDebug("Failed to parse game_key: %s", parts[2]); wxLogDebug("Failed to parse game_key: %s", parts[2]);
return std::nullopt; return nonstd::nullopt;
} }
return wxGameControl(joypad, game_key.value()); return wxGameControl(joypad, game_key.value());

View File

@ -3,7 +3,7 @@
#include <array> #include <array>
#include <map> #include <map>
#include <optional> #include "nonstd/optional.hpp"
#include <set> #include <set>
#include <wx/string.h> #include <wx/string.h>
@ -72,14 +72,14 @@ wxString GameKeyToString(const wxGameKey& game_key);
// Conversion utility method. Returns std::nullopt on failure. // Conversion utility method. Returns std::nullopt on failure.
// This is O(log(kNbGameKeys)). // This is O(log(kNbGameKeys)).
std::optional<wxGameKey> StringToGameKey(const wxString& input); nonstd::optional<wxGameKey> StringToGameKey(const wxString& input);
// Abstraction for an in-game control, wich is made of a player index (from 0 // Abstraction for an in-game control, wich is made of a player index (from 0
// to 3), and a wxGameKey. // to 3), and a wxGameKey.
class wxGameControl { class wxGameControl {
public: public:
// Converts a string to a wxGameControl. Returns std::nullopt on failure. // Converts a string to a wxGameControl. Returns std::nullopt on failure.
static std::optional<wxGameControl> FromString(const wxString& name); static nonstd::optional<wxGameControl> FromString(const wxString& name);
wxGameControl(int joypad, wxGameKey game_key); wxGameControl(int joypad, wxGameKey game_key);
~wxGameControl(); ~wxGameControl();

1847
third_party/include/nonstd/optional.hpp vendored Normal file

File diff suppressed because it is too large Load Diff