mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Remove Nullable and use std::optional instead
This commit is contained in:
@@ -1685,7 +1685,6 @@
|
||||
F76C838B1EC4E7CC00FA49E2 /* Memory.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Memory.hpp; sourceTree = "<group>"; };
|
||||
F76C838C1EC4E7CC00FA49E2 /* MemoryStream.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryStream.cpp; sourceTree = "<group>"; };
|
||||
F76C838D1EC4E7CC00FA49E2 /* MemoryStream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MemoryStream.h; sourceTree = "<group>"; };
|
||||
F76C838E1EC4E7CC00FA49E2 /* Nullable.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Nullable.hpp; sourceTree = "<group>"; };
|
||||
F76C838F1EC4E7CC00FA49E2 /* Path.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Path.cpp; sourceTree = "<group>"; };
|
||||
F76C83901EC4E7CC00FA49E2 /* Path.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Path.hpp; sourceTree = "<group>"; };
|
||||
F76C83921EC4E7CC00FA49E2 /* String.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = String.cpp; sourceTree = "<group>"; };
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2020 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
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
template<typename T> struct Nullable
|
||||
{
|
||||
public:
|
||||
Nullable()
|
||||
{
|
||||
_value = T();
|
||||
_hasValue = false;
|
||||
}
|
||||
|
||||
Nullable(std::nullptr_t)
|
||||
{
|
||||
_value = T();
|
||||
_hasValue = false;
|
||||
}
|
||||
|
||||
Nullable(const T& value)
|
||||
{
|
||||
_value = value;
|
||||
_hasValue = true;
|
||||
}
|
||||
|
||||
bool HasValue() const
|
||||
{
|
||||
return _hasValue;
|
||||
}
|
||||
|
||||
T GetValue() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
T GetValueOrDefault(T defaultValue) const
|
||||
{
|
||||
return _hasValue ? _value : defaultValue;
|
||||
}
|
||||
|
||||
private:
|
||||
T _value;
|
||||
bool _hasValue;
|
||||
};
|
||||
@@ -175,7 +175,6 @@
|
||||
<ClInclude Include="core\Memory.hpp" />
|
||||
<ClInclude Include="core\MemoryStream.h" />
|
||||
<ClInclude Include="core\Meta.hpp" />
|
||||
<ClInclude Include="core\Nullable.hpp" />
|
||||
<ClInclude Include="core\Numerics.hpp" />
|
||||
<ClInclude Include="core\Path.hpp" />
|
||||
<ClInclude Include="core\Random.hpp" />
|
||||
|
||||
@@ -61,7 +61,6 @@ static constexpr uint32_t MaxPacketsPerUpdate = 100;
|
||||
# include "../core/Console.hpp"
|
||||
# include "../core/FileStream.h"
|
||||
# include "../core/MemoryStream.h"
|
||||
# include "../core/Nullable.hpp"
|
||||
# include "../core/Path.hpp"
|
||||
# include "../core/String.hpp"
|
||||
# include "../interface/Chat.h"
|
||||
@@ -912,9 +911,9 @@ uint8_t NetworkBase::GetGroupIDByHash(const std::string& keyhash)
|
||||
const NetworkUser* networkUser = _userManager.GetUserByHash(keyhash);
|
||||
|
||||
uint8_t groupId = GetDefaultGroup();
|
||||
if (networkUser != nullptr && networkUser->GroupId.HasValue())
|
||||
if (networkUser != nullptr && networkUser->GroupId.has_value())
|
||||
{
|
||||
const uint8_t assignedGroup = networkUser->GroupId.GetValue();
|
||||
const uint8_t assignedGroup = *networkUser->GroupId;
|
||||
if (GetGroupByID(assignedGroup) != nullptr)
|
||||
{
|
||||
groupId = assignedGroup;
|
||||
@@ -2058,7 +2057,7 @@ NetworkPlayer* NetworkBase::AddPlayer(const std::string& name, const std::string
|
||||
}
|
||||
else
|
||||
{
|
||||
player->Group = networkUser->GroupId.GetValueOrDefault(GetDefaultGroup());
|
||||
player->Group = networkUser->GroupId.has_value() ? *networkUser->GroupId : GetDefaultGroup();
|
||||
player->SetName(networkUser->Name);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ json_t NetworkUser::ToJson() const
|
||||
jsonData["name"] = Name;
|
||||
|
||||
json_t jsonGroupId;
|
||||
if (GroupId.HasValue())
|
||||
if (GroupId.has_value())
|
||||
{
|
||||
jsonGroupId = GroupId.GetValue();
|
||||
jsonGroupId = *GroupId;
|
||||
}
|
||||
jsonData["groupId"] = jsonGroupId;
|
||||
|
||||
@@ -172,9 +172,9 @@ void NetworkUserManager::UnsetUsersOfGroup(uint8_t groupId)
|
||||
for (const auto& kvp : _usersByHash)
|
||||
{
|
||||
NetworkUser* networkUser = kvp.second;
|
||||
if (networkUser->GroupId.HasValue() && networkUser->GroupId.GetValue() == groupId)
|
||||
if (networkUser->GroupId.has_value() && *networkUser->GroupId == groupId)
|
||||
{
|
||||
networkUser->GroupId = nullptr;
|
||||
networkUser->GroupId = std::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
#include "../common.h"
|
||||
#include "../core/JsonFwd.hpp"
|
||||
#include "../core/Nullable.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class NetworkUser final
|
||||
@@ -21,7 +21,7 @@ class NetworkUser final
|
||||
public:
|
||||
std::string Hash;
|
||||
std::string Name;
|
||||
Nullable<uint8_t> GroupId;
|
||||
std::optional<uint8_t> GroupId;
|
||||
bool Remove;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user