mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 00:59:44 -06:00
Remove NonCopyable
The class NonCopyable is, like the name says, supposed to disallow
copying. But should it allow moving?
For a long time, NonCopyable used to not allow moving. (It declared
a deleted copy constructor and assigment operator without declaring
a move constructor and assignment operator, making the compiler
implicitly delete the move constructor and assignment operator.)
That's fine if the classes that inherit from NonCopyable don't need
to be movable or if writing the move constructor and assignment
operator by hand is fine, but that's not the case for all classes,
as I discovered when I was working on the DirectoryBlob PR.
Because of that, I decided to make NonCopyable movable in c7602cc
,
allowing me to use NonCopyable in DirectoryBlob.h. That was however
an unfortunate decision, because some of the classes that inherit
from NonCopyable have incorrect behavior when moved by default-
generated move constructors and assignment operators, and do not
explicitly delete the move constructors and assignment operators,
relying on NonCopyable being non-movable.
So what can we do about this? There are four solutions that I can
think of:
1. Make NonCopyable non-movable and tell DirectoryBlob to suck it.
2. Keep allowing moving NonCopyable, and expect that classes that
don't support moving will delete the move constructor and
assignment operator manually. Not only is this inconsistent
(having classes disallow copying one way and disallow moving
another way), but deleting the move constructor and assignment
operator manually is too easy to forget compared to how tricky
the resulting problems are.
3. Have one "MovableNonCopyable" and one "NonMovableNonCopyable".
It works, but it feels rather silly...
4. Don't have a NonCopyable class at all. Considering that deleting
the copy constructor and assignment operator only takes two lines
of code, I don't see much of a reason to keep NonCopyable. I
suppose that there was more of a point in having NonCopyable back
in the pre-C++11 days, when it wasn't possible to use "= delete".
I decided to go with the fourth one (like the commit title says).
The implementation of the commit is fairly straight-forward, though
I would like to point out that I skipped adding "= delete" lines
for classes whose only reason for being uncopyable is that they
contain uncopyable classes like File::IOFile and std::unique_ptr,
because the compiler makes such classes uncopyable automatically.
This commit is contained in:
@ -12,7 +12,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
#include "Core/HW/EXI/EXI_Device.h"
|
||||
#include "Core/HW/SI/SI_Device.h"
|
||||
#include "Core/TitleDatabase.h"
|
||||
@ -52,7 +51,7 @@ enum GPUDeterminismMode
|
||||
|
||||
struct BootParameters;
|
||||
|
||||
struct SConfig : NonCopyable
|
||||
struct SConfig
|
||||
{
|
||||
// Wii Devices
|
||||
bool m_WiiSDCard;
|
||||
@ -318,6 +317,11 @@ struct SConfig : NonCopyable
|
||||
bool m_SSLDumpRootCA;
|
||||
bool m_SSLDumpPeerCert;
|
||||
|
||||
SConfig(const SConfig&) = delete;
|
||||
SConfig& operator=(const SConfig&) = delete;
|
||||
SConfig(SConfig&&) = delete;
|
||||
SConfig& operator=(SConfig&&) = delete;
|
||||
|
||||
// Save settings
|
||||
void SaveSettings();
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
|
||||
class PCAP;
|
||||
|
||||
@ -51,7 +50,7 @@ public:
|
||||
|
||||
// A capture logger implementation that logs to PCAP files in a custom
|
||||
// packet-based format.
|
||||
class PCAPDSPCaptureLogger final : public DSPCaptureLogger, NonCopyable
|
||||
class PCAPDSPCaptureLogger final : public DSPCaptureLogger
|
||||
{
|
||||
public:
|
||||
// Automatically creates a writeable file (truncate existing file).
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Common/Timer.h"
|
||||
|
||||
@ -295,7 +294,7 @@ public:
|
||||
std::string m_filename;
|
||||
};
|
||||
|
||||
class GCMemcard : NonCopyable
|
||||
class GCMemcard
|
||||
{
|
||||
private:
|
||||
bool m_valid;
|
||||
@ -317,6 +316,12 @@ private:
|
||||
public:
|
||||
explicit GCMemcard(const std::string& fileName, bool forceCreation = false,
|
||||
bool shift_jis = false);
|
||||
|
||||
GCMemcard(const GCMemcard&) = delete;
|
||||
GCMemcard& operator=(const GCMemcard&) = delete;
|
||||
GCMemcard(GCMemcard&&) = default;
|
||||
GCMemcard& operator=(GCMemcard&&) = default;
|
||||
|
||||
bool IsValid() const { return m_valid; }
|
||||
bool IsShiftJIS() const;
|
||||
bool Save();
|
||||
|
@ -10,19 +10,24 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
#include "Core/HW/GCMemcard/GCMemcard.h"
|
||||
|
||||
// Uncomment this to write the system data of the memorycard from directory to disc
|
||||
//#define _WRITE_MC_HEADER 1
|
||||
void MigrateFromMemcardFile(const std::string& directory_name, int card_index);
|
||||
|
||||
class GCMemcardDirectory : public MemoryCardBase, NonCopyable
|
||||
class GCMemcardDirectory : public MemoryCardBase
|
||||
{
|
||||
public:
|
||||
GCMemcardDirectory(const std::string& directory, int slot, u16 size_mbits, bool shift_jis,
|
||||
int game_id);
|
||||
~GCMemcardDirectory();
|
||||
|
||||
GCMemcardDirectory(const GCMemcardDirectory&) = delete;
|
||||
GCMemcardDirectory& operator=(const GCMemcardDirectory&) = delete;
|
||||
GCMemcardDirectory(GCMemcardDirectory&&) = default;
|
||||
GCMemcardDirectory& operator=(GCMemcardDirectory&&) = default;
|
||||
|
||||
void FlushToFile();
|
||||
void FlushThread();
|
||||
s32 Read(u32 src_address, s32 length, u8* dest_address) override;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
|
||||
// All the templated and very repetitive MMIO-related code is isolated in this
|
||||
// file for easier reading. It mostly contains code related to handling methods
|
||||
@ -119,7 +118,7 @@ public:
|
||||
// inlinable, we need to provide some of the implementation of these two
|
||||
// classes here and can't just use a forward declaration.
|
||||
template <typename T>
|
||||
class ReadHandler : public NonCopyable
|
||||
class ReadHandler
|
||||
{
|
||||
public:
|
||||
ReadHandler();
|
||||
@ -155,7 +154,7 @@ private:
|
||||
std::function<T(u32)> m_ReadFunc;
|
||||
};
|
||||
template <typename T>
|
||||
class WriteHandler : public NonCopyable
|
||||
class WriteHandler
|
||||
{
|
||||
public:
|
||||
WriteHandler();
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "Common/Event.h"
|
||||
#include "Common/FifoQueue.h"
|
||||
#include "Common/Flag.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "Core/HW/WiimoteCommon/WiimoteConstants.h"
|
||||
#include "Core/HW/WiimoteCommon/WiimoteHid.h"
|
||||
@ -24,9 +23,14 @@ class PointerWrap;
|
||||
|
||||
namespace WiimoteReal
|
||||
{
|
||||
class Wiimote : NonCopyable
|
||||
class Wiimote
|
||||
{
|
||||
public:
|
||||
Wiimote(const Wiimote&) = delete;
|
||||
Wiimote& operator=(const Wiimote&) = delete;
|
||||
Wiimote(Wiimote&&) = default;
|
||||
Wiimote& operator=(Wiimote&&) = default;
|
||||
|
||||
virtual ~Wiimote() {}
|
||||
// This needs to be called in derived destructors!
|
||||
void Shutdown();
|
||||
|
@ -50,7 +50,6 @@ typedef struct pollfd pollfd_t;
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/IOS/IOS.h"
|
||||
#include "Core/IOS/Network/IP/Top.h"
|
||||
@ -207,7 +206,7 @@ public:
|
||||
void operator=(WiiSocket const&) = delete;
|
||||
};
|
||||
|
||||
class WiiSockMan : public ::NonCopyable
|
||||
class WiiSockMan
|
||||
{
|
||||
public:
|
||||
static s32 GetNetErrorCode(s32 ret, const char* caller, bool isRW);
|
||||
@ -249,6 +248,10 @@ public:
|
||||
|
||||
private:
|
||||
WiiSockMan() = default;
|
||||
WiiSockMan(const WiiSockMan&) = delete;
|
||||
WiiSockMan& operator=(const WiiSockMan&) = delete;
|
||||
WiiSockMan(WiiSockMan&&) = delete;
|
||||
WiiSockMan& operator=(WiiSockMan&&) = delete;
|
||||
|
||||
std::unordered_map<s32, WiiSocket> WiiSockets;
|
||||
s32 errno_last;
|
||||
|
Reference in New Issue
Block a user