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:
parent
fb99a07625
commit
e29032d48a
|
@ -456,6 +456,9 @@ add_definitions(-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=)
|
|||
|
||||
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)
|
||||
# IPC linking code needs sem_timedwait which can be either in librt or pthreads
|
||||
if(NOT WIN32)
|
||||
|
@ -1100,6 +1103,7 @@ include_directories(
|
|||
${ZLIB_INCLUDE_DIR}
|
||||
fex
|
||||
${SDL2_INCLUDE_DIR}
|
||||
third_party/include
|
||||
third_party/include/stb
|
||||
)
|
||||
|
||||
|
|
|
@ -1052,7 +1052,7 @@ bool opt_set(const wxString& name, const wxString& val)
|
|||
return true;
|
||||
}
|
||||
|
||||
const std::optional<wxGameControl> game_control =
|
||||
const nonstd::optional<wxGameControl> game_control =
|
||||
wxGameControl::FromString(name);
|
||||
if (game_control) {
|
||||
if (val.empty()) {
|
||||
|
|
|
@ -95,7 +95,7 @@ wxString GameKeyToString(const wxGameKey& 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 = {
|
||||
{ wxT("Up"), wxGameKey::Up },
|
||||
{ wxT("Down"), wxGameKey::Down },
|
||||
|
@ -122,35 +122,35 @@ std::optional<wxGameKey> StringToGameKey(const wxString& input) {
|
|||
|
||||
const auto iter = kStringToGameKey.find(input);
|
||||
if (iter == kStringToGameKey.end()) {
|
||||
return std::nullopt;
|
||||
return nonstd::nullopt;
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
// static
|
||||
std::optional<wxGameControl> wxGameControl::FromString(const wxString &name) {
|
||||
nonstd::optional<wxGameControl> wxGameControl::FromString(const wxString &name) {
|
||||
static const wxString kJoypad(wxT("Joypad"));
|
||||
if (!wxStrncmp(name, kJoypad, kJoypad.size())) {
|
||||
wxLogDebug("Doesn't start with joypad");
|
||||
return std::nullopt;
|
||||
return nonstd::nullopt;
|
||||
}
|
||||
|
||||
auto parts = str_split(name, wxT("/"));
|
||||
if (parts.size() != 3) {
|
||||
wxLogDebug("Wrong split size: %d", parts.size());
|
||||
return std::nullopt;
|
||||
return nonstd::nullopt;
|
||||
}
|
||||
|
||||
const int joypad = parts[1][0] - wxT('1');
|
||||
if (!JoypadInRange(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) {
|
||||
wxLogDebug("Failed to parse game_key: %s", parts[2]);
|
||||
return std::nullopt;
|
||||
return nonstd::nullopt;
|
||||
}
|
||||
|
||||
return wxGameControl(joypad, game_key.value());
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include "nonstd/optional.hpp"
|
||||
#include <set>
|
||||
#include <wx/string.h>
|
||||
|
||||
|
@ -72,14 +72,14 @@ wxString GameKeyToString(const wxGameKey& game_key);
|
|||
|
||||
// Conversion utility method. Returns std::nullopt on failure.
|
||||
// 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
|
||||
// to 3), and a wxGameKey.
|
||||
class wxGameControl {
|
||||
public:
|
||||
// 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();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue