From 3ab6953246c96227953e8750942b0ec732ffb6fa Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 12 Jan 2024 22:03:19 -0500 Subject: [PATCH] Avoid use of raw pointers in machine creation. --- Machines/Amiga/Amiga.cpp | 4 ++-- Machines/Amiga/Amiga.hpp | 4 +++- Machines/AmstradCPC/AmstradCPC.cpp | 6 +++--- Machines/AmstradCPC/AmstradCPC.hpp | 2 +- Machines/Apple/AppleII/AppleII.cpp | 10 +++++----- Machines/Apple/AppleII/AppleII.hpp | 2 +- Machines/Apple/AppleIIgs/AppleIIgs.cpp | 4 ++-- Machines/Apple/AppleIIgs/AppleIIgs.hpp | 2 +- Machines/Apple/Macintosh/Macintosh.cpp | 10 +++++----- Machines/Apple/Macintosh/Macintosh.hpp | 2 +- Machines/Atari/2600/Atari2600.cpp | 4 ++-- Machines/Atari/2600/Atari2600.hpp | 4 +++- Machines/Atari/ST/AtariST.cpp | 4 ++-- Machines/Atari/ST/AtariST.hpp | 2 +- Machines/ColecoVision/ColecoVision.cpp | 4 ++-- Machines/ColecoVision/ColecoVision.hpp | 4 +++- Machines/Commodore/Vic-20/Vic20.cpp | 4 ++-- Machines/Commodore/Vic-20/Vic20.hpp | 2 +- Machines/Electron/Electron.cpp | 6 +++--- Machines/Electron/Electron.hpp | 2 +- Machines/Enterprise/Enterprise.cpp | 4 ++-- Machines/Enterprise/Enterprise.hpp | 5 +++-- Machines/MSX/MSX.cpp | 10 +++++----- Machines/MSX/MSX.hpp | 2 +- Machines/MasterSystem/MasterSystem.cpp | 8 ++++---- Machines/MasterSystem/MasterSystem.hpp | 2 +- Machines/Oric/Oric.cpp | 12 ++++++------ Machines/Oric/Oric.hpp | 2 +- Machines/PCCompatible/PCCompatible.cpp | 6 +++--- Machines/PCCompatible/PCCompatible.hpp | 2 +- Machines/Sinclair/ZX8081/ZX8081.cpp | 6 +++--- Machines/Sinclair/ZX8081/ZX8081.hpp | 2 +- Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp | 14 +++++++------- Machines/Sinclair/ZXSpectrum/ZXSpectrum.hpp | 2 +- Machines/Utility/MachineForTarget.cpp | 12 ++++++------ Machines/Utility/MachineForTarget.hpp | 4 ++-- Machines/Utility/TypedDynamicMachine.hpp | 4 +++- OSBindings/Mac/Clock Signal/Machine/CSMachine.mm | 2 +- OSBindings/Qt/mainwindow.cpp | 2 +- 39 files changed, 96 insertions(+), 87 deletions(-) diff --git a/Machines/Amiga/Amiga.cpp b/Machines/Amiga/Amiga.cpp index d6e314f80..7bb1ff05d 100644 --- a/Machines/Amiga/Amiga.cpp +++ b/Machines/Amiga/Amiga.cpp @@ -251,10 +251,10 @@ class ConcreteMachine: using namespace Amiga; -Machine *Machine::Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::Amiga::Target; const Target *const amiga_target = dynamic_cast(target); - return new Amiga::ConcreteMachine(*amiga_target, rom_fetcher); + return std::make_unique(*amiga_target, rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/Amiga/Amiga.hpp b/Machines/Amiga/Amiga.hpp index caa7fe965..e820613d0 100644 --- a/Machines/Amiga/Amiga.hpp +++ b/Machines/Amiga/Amiga.hpp @@ -12,6 +12,8 @@ #include "../../Analyser/Static/StaticAnalyser.hpp" #include "../ROMMachine.hpp" +#include + namespace Amiga { class Machine { @@ -19,7 +21,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an Amiga. - static Machine *Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); }; } diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 60b2e048e..ce15aae9b 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -1285,12 +1285,12 @@ template class ConcreteMachine: using namespace AmstradCPC; // See header; constructs and returns an instance of the Amstrad CPC. -Machine *Machine::AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::AmstradCPC::Target; const Target *const cpc_target = dynamic_cast(target); switch(cpc_target->model) { - default: return new AmstradCPC::ConcreteMachine(*cpc_target, rom_fetcher); - case Target::Model::CPC464: return new AmstradCPC::ConcreteMachine(*cpc_target, rom_fetcher); + default: return std::make_unique>(*cpc_target, rom_fetcher); + case Target::Model::CPC464: return std::make_unique>(*cpc_target, rom_fetcher); } } diff --git a/Machines/AmstradCPC/AmstradCPC.hpp b/Machines/AmstradCPC/AmstradCPC.hpp index ae1cf1015..b6184dce8 100644 --- a/Machines/AmstradCPC/AmstradCPC.hpp +++ b/Machines/AmstradCPC/AmstradCPC.hpp @@ -26,7 +26,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an Amstrad CPC. - static Machine *AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); /// Defines the runtime options available for an Amstrad CPC. class Options: diff --git a/Machines/Apple/AppleII/AppleII.cpp b/Machines/Apple/AppleII/AppleII.cpp index c4fdb77af..dace81906 100644 --- a/Machines/Apple/AppleII/AppleII.cpp +++ b/Machines/Apple/AppleII/AppleII.cpp @@ -985,15 +985,15 @@ template class ConcreteMachine: using namespace Apple::II; -Machine *Machine::AppleII(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::AppleII(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::AppleII::Target; const Target *const appleii_target = dynamic_cast(target); switch(appleii_target->model) { default: return nullptr; - case Target::Model::II: return new ConcreteMachine(*appleii_target, rom_fetcher); - case Target::Model::IIplus: return new ConcreteMachine(*appleii_target, rom_fetcher); - case Target::Model::IIe: return new ConcreteMachine(*appleii_target, rom_fetcher); - case Target::Model::EnhancedIIe: return new ConcreteMachine(*appleii_target, rom_fetcher); + case Target::Model::II: return std::make_unique>(*appleii_target, rom_fetcher); + case Target::Model::IIplus: return std::make_unique>(*appleii_target, rom_fetcher); + case Target::Model::IIe: return std::make_unique>(*appleii_target, rom_fetcher); + case Target::Model::EnhancedIIe: return std::make_unique>(*appleii_target, rom_fetcher); } } diff --git a/Machines/Apple/AppleII/AppleII.hpp b/Machines/Apple/AppleII/AppleII.hpp index 2e8733ce4..82feaff5b 100644 --- a/Machines/Apple/AppleII/AppleII.hpp +++ b/Machines/Apple/AppleII/AppleII.hpp @@ -23,7 +23,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an AppleII. - static Machine *AppleII(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr AppleII(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); /// Defines the runtime options available for an Apple II. class Options: public Reflection::StructImpl, public Configurable::DisplayOption { diff --git a/Machines/Apple/AppleIIgs/AppleIIgs.cpp b/Machines/Apple/AppleIIgs/AppleIIgs.cpp index 53de14c53..06f48ad44 100644 --- a/Machines/Apple/AppleIIgs/AppleIIgs.cpp +++ b/Machines/Apple/AppleIIgs/AppleIIgs.cpp @@ -1010,8 +1010,8 @@ class ConcreteMachine: using namespace Apple::IIgs; -Machine *Machine::AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { - return new ConcreteMachine(*dynamic_cast(target), rom_fetcher); +std::unique_ptr Machine::AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { + return std::make_unique(*dynamic_cast(target), rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/Apple/AppleIIgs/AppleIIgs.hpp b/Machines/Apple/AppleIIgs/AppleIIgs.hpp index 1cd1a862a..0ae1075eb 100644 --- a/Machines/Apple/AppleIIgs/AppleIIgs.hpp +++ b/Machines/Apple/AppleIIgs/AppleIIgs.hpp @@ -23,7 +23,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an AppleIIgs. - static Machine *AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); }; } diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index ccbb589d5..51f89347a 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -840,16 +840,16 @@ template class ConcreteMachin using namespace Apple::Macintosh; -Machine *Machine::Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { auto *const mac_target = dynamic_cast(target); using Model = Analyser::Static::Macintosh::Target::Model; switch(mac_target->model) { default: - case Model::Mac128k: return new ConcreteMachine(*mac_target, rom_fetcher); - case Model::Mac512k: return new ConcreteMachine(*mac_target, rom_fetcher); - case Model::Mac512ke: return new ConcreteMachine(*mac_target, rom_fetcher); - case Model::MacPlus: return new ConcreteMachine(*mac_target, rom_fetcher); + case Model::Mac128k: return std::make_unique>(*mac_target, rom_fetcher); + case Model::Mac512k: return std::make_unique>(*mac_target, rom_fetcher); + case Model::Mac512ke: return std::make_unique>(*mac_target, rom_fetcher); + case Model::MacPlus: return std::make_unique>(*mac_target, rom_fetcher); } } diff --git a/Machines/Apple/Macintosh/Macintosh.hpp b/Machines/Apple/Macintosh/Macintosh.hpp index 167106ff7..1676b1cd5 100644 --- a/Machines/Apple/Macintosh/Macintosh.hpp +++ b/Machines/Apple/Macintosh/Macintosh.hpp @@ -21,7 +21,7 @@ class Machine { virtual ~Machine(); /// Creates and returns a Macintosh. - static Machine *Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::QuickbootOption { friend Configurable::QuickbootOption; diff --git a/Machines/Atari/2600/Atari2600.cpp b/Machines/Atari/2600/Atari2600.cpp index 72ff213d6..fb146400d 100644 --- a/Machines/Atari/2600/Atari2600.cpp +++ b/Machines/Atari/2600/Atari2600.cpp @@ -212,9 +212,9 @@ class ConcreteMachine: using namespace Atari2600; -Machine *Machine::Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &) { +std::unique_ptr Machine::Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &) { const Target *const atari_target = dynamic_cast(target); - return new Atari2600::ConcreteMachine(*atari_target); + return std::make_unique(*atari_target); } Machine::~Machine() {} diff --git a/Machines/Atari/2600/Atari2600.hpp b/Machines/Atari/2600/Atari2600.hpp index 43e3cddbb..16fb6d2a5 100644 --- a/Machines/Atari/2600/Atari2600.hpp +++ b/Machines/Atari/2600/Atari2600.hpp @@ -15,6 +15,8 @@ #include "Atari2600Inputs.h" +#include + namespace Atari2600 { /*! @@ -25,7 +27,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an Atari 2600 on the heap. - static Machine *Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); /// Sets the switch @c input to @c state. virtual void set_switch_is_enabled(Atari2600Switch input, bool state) = 0; diff --git a/Machines/Atari/ST/AtariST.cpp b/Machines/Atari/ST/AtariST.cpp index 84c74aa2c..56dd9c0de 100644 --- a/Machines/Atari/ST/AtariST.cpp +++ b/Machines/Atari/ST/AtariST.cpp @@ -706,13 +706,13 @@ class ConcreteMachine: using namespace Atari::ST; -Machine *Machine::AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { auto *const atari_target = dynamic_cast(target); if(!atari_target) { return nullptr; } - return new ConcreteMachine(*atari_target, rom_fetcher); + return std::make_unique(*atari_target, rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/Atari/ST/AtariST.hpp b/Machines/Atari/ST/AtariST.hpp index 604019779..9ed5747b1 100644 --- a/Machines/Atari/ST/AtariST.hpp +++ b/Machines/Atari/ST/AtariST.hpp @@ -22,7 +22,7 @@ class Machine { public: virtual ~Machine(); - static Machine *AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption { friend Configurable::DisplayOption; diff --git a/Machines/ColecoVision/ColecoVision.cpp b/Machines/ColecoVision/ColecoVision.cpp index 19ba93adb..2ee9da78d 100644 --- a/Machines/ColecoVision/ColecoVision.cpp +++ b/Machines/ColecoVision/ColecoVision.cpp @@ -412,8 +412,8 @@ class ConcreteMachine: using namespace Coleco::Vision; -Machine *Machine::ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { - return new ConcreteMachine(*target, rom_fetcher); +std::unique_ptr Machine::ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { + return std::make_unique(*target, rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/ColecoVision/ColecoVision.hpp b/Machines/ColecoVision/ColecoVision.hpp index 1438e48bf..1ea2a208f 100644 --- a/Machines/ColecoVision/ColecoVision.hpp +++ b/Machines/ColecoVision/ColecoVision.hpp @@ -14,12 +14,14 @@ #include "../../Analyser/Static/StaticAnalyser.hpp" #include "../ROMMachine.hpp" +#include + namespace Coleco::Vision { class Machine { public: virtual ~Machine(); - static Machine *ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption { friend Configurable::DisplayOption; diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index dc7f1df73..2346e5096 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -758,10 +758,10 @@ class ConcreteMachine: using namespace Commodore::Vic20; -Machine *Machine::Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::Commodore::Target; const Target *const commodore_target = dynamic_cast(target); - return new Vic20::ConcreteMachine(*commodore_target, rom_fetcher); + return std::make_unique(*commodore_target, rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 51a8db20d..59c5dec28 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -26,7 +26,7 @@ class Machine { virtual ~Machine(); /// Creates and returns a Vic-20. - static Machine *Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption, public Configurable::QuickloadOption { friend Configurable::DisplayOption; diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 76752c3b8..4bd2781a5 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -786,14 +786,14 @@ template class ConcreteMachine: using namespace Electron; -Machine *Machine::Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::Acorn::Target; const Target *const acorn_target = dynamic_cast(target); if(acorn_target->media.mass_storage_devices.empty()) { - return new Electron::ConcreteMachine(*acorn_target, rom_fetcher); + return std::make_unique>(*acorn_target, rom_fetcher); } else { - return new Electron::ConcreteMachine(*acorn_target, rom_fetcher); + return std::make_unique>(*acorn_target, rom_fetcher); } } diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 5fd5daaa6..0996b1c83 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -29,7 +29,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an Electron. - static Machine *Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); /// Defines the runtime options available for an Electron. class Options: public Reflection::StructImpl, public Configurable::DisplayOption, public Configurable::QuickloadOption { diff --git a/Machines/Enterprise/Enterprise.cpp b/Machines/Enterprise/Enterprise.cpp index 45cbea195..4a235e524 100644 --- a/Machines/Enterprise/Enterprise.cpp +++ b/Machines/Enterprise/Enterprise.cpp @@ -748,13 +748,13 @@ template class ConcreteMachine: using namespace Enterprise; -Machine *Machine::Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::Enterprise::Target; const Target *const enterprise_target = dynamic_cast(target); #define BuildMachine(exdos, sixmhz) \ if((enterprise_target->dos == Target::DOS::None) != exdos && (enterprise_target->speed == Target::Speed::SixMHz) == sixmhz) { \ - return new Enterprise::ConcreteMachine(*enterprise_target, rom_fetcher); \ + return std::make_unique>(*enterprise_target, rom_fetcher); \ } BuildMachine(false, false); diff --git a/Machines/Enterprise/Enterprise.hpp b/Machines/Enterprise/Enterprise.hpp index 4970a66f1..86d16f606 100644 --- a/Machines/Enterprise/Enterprise.hpp +++ b/Machines/Enterprise/Enterprise.hpp @@ -14,6 +14,8 @@ #include "../../Configurable/StandardOptions.hpp" #include "../ROMMachine.hpp" +#include + namespace Enterprise { /*! @@ -25,8 +27,7 @@ namespace Enterprise { class Machine { public: virtual ~Machine(); - - static Machine *Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); /// Defines the runtime options available for an Enterprise. class Options: public Reflection::StructImpl, public Configurable::DisplayOption { diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index cc5de7f72..2b4b2024c 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -1030,19 +1030,19 @@ class ConcreteMachine: using namespace MSX; -Machine *Machine::MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { const auto msx_target = dynamic_cast(target); if(msx_target->has_msx_music) { switch(msx_target->model) { default: return nullptr; - case Target::Model::MSX1: return new ConcreteMachine(*msx_target, rom_fetcher); - case Target::Model::MSX2: return new ConcreteMachine(*msx_target, rom_fetcher); + case Target::Model::MSX1: return std::make_unique>(*msx_target, rom_fetcher); + case Target::Model::MSX2: return std::make_unique>(*msx_target, rom_fetcher); } } else { switch(msx_target->model) { default: return nullptr; - case Target::Model::MSX1: return new ConcreteMachine(*msx_target, rom_fetcher); - case Target::Model::MSX2: return new ConcreteMachine(*msx_target, rom_fetcher); + case Target::Model::MSX1: return std::make_unique>(*msx_target, rom_fetcher); + case Target::Model::MSX2: return std::make_unique>(*msx_target, rom_fetcher); } } } diff --git a/Machines/MSX/MSX.hpp b/Machines/MSX/MSX.hpp index 902ad5a78..fe6507e15 100644 --- a/Machines/MSX/MSX.hpp +++ b/Machines/MSX/MSX.hpp @@ -21,7 +21,7 @@ namespace MSX { class Machine { public: virtual ~Machine(); - static Machine *MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption, public Configurable::QuickloadOption { friend Configurable::DisplayOption; diff --git a/Machines/MasterSystem/MasterSystem.cpp b/Machines/MasterSystem/MasterSystem.cpp index 8136049f6..a84276131 100644 --- a/Machines/MasterSystem/MasterSystem.cpp +++ b/Machines/MasterSystem/MasterSystem.cpp @@ -557,14 +557,14 @@ template class ConcreteMachine: using namespace Sega::MasterSystem; -Machine *Machine::MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::Sega::Target; const Target *const sega_target = dynamic_cast(target); switch(sega_target->model) { - case Target::Model::SG1000: return new ConcreteMachine(*sega_target, rom_fetcher); - case Target::Model::MasterSystem: return new ConcreteMachine(*sega_target, rom_fetcher); - case Target::Model::MasterSystem2: return new ConcreteMachine(*sega_target, rom_fetcher); + case Target::Model::SG1000: return std::make_unique>(*sega_target, rom_fetcher); + case Target::Model::MasterSystem: return std::make_unique>(*sega_target, rom_fetcher); + case Target::Model::MasterSystem2: return std::make_unique>(*sega_target, rom_fetcher); default: assert(false); return nullptr; diff --git a/Machines/MasterSystem/MasterSystem.hpp b/Machines/MasterSystem/MasterSystem.hpp index c3b0fca6b..34960578c 100644 --- a/Machines/MasterSystem/MasterSystem.hpp +++ b/Machines/MasterSystem/MasterSystem.hpp @@ -21,7 +21,7 @@ namespace Sega::MasterSystem { class Machine { public: virtual ~Machine(); - static Machine *MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption { friend Configurable::DisplayOption; diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 42bd23697..2aeed45ed 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -795,16 +795,16 @@ template Machine::Oric(const Analyser::Static::Target *target_hint, const ROMMachine::ROMFetcher &rom_fetcher) { auto *const oric_target = dynamic_cast(target_hint); #define DiskInterfaceSwitch(processor) \ switch(oric_target->disk_interface) { \ - default: return new ConcreteMachine(*oric_target, rom_fetcher); \ - case DiskInterface::Microdisc: return new ConcreteMachine(*oric_target, rom_fetcher); \ - case DiskInterface::Pravetz: return new ConcreteMachine(*oric_target, rom_fetcher); \ - case DiskInterface::Jasmin: return new ConcreteMachine(*oric_target, rom_fetcher); \ - case DiskInterface::BD500: return new ConcreteMachine(*oric_target, rom_fetcher); \ + default: return std::make_unique>(*oric_target, rom_fetcher); \ + case DiskInterface::Microdisc: return std::make_unique>(*oric_target, rom_fetcher); \ + case DiskInterface::Pravetz: return std::make_unique>(*oric_target, rom_fetcher); \ + case DiskInterface::Jasmin: return std::make_unique>(*oric_target, rom_fetcher); \ + case DiskInterface::BD500: return std::make_unique>(*oric_target, rom_fetcher); \ } switch(oric_target->processor) { diff --git a/Machines/Oric/Oric.hpp b/Machines/Oric/Oric.hpp index 44167d77d..037248b6d 100644 --- a/Machines/Oric/Oric.hpp +++ b/Machines/Oric/Oric.hpp @@ -26,7 +26,7 @@ class Machine { virtual ~Machine(); /// Creates and returns an Oric. - static Machine *Oric(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr Oric(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); class Options: public Reflection::StructImpl, public Configurable::DisplayOption, public Configurable::QuickloadOption { friend Configurable::DisplayOption; diff --git a/Machines/PCCompatible/PCCompatible.cpp b/Machines/PCCompatible/PCCompatible.cpp index ef0aa6a8c..4cdd8b13a 100644 --- a/Machines/PCCompatible/PCCompatible.cpp +++ b/Machines/PCCompatible/PCCompatible.cpp @@ -1199,12 +1199,12 @@ class ConcreteMachine: using namespace PCCompatible; // See header; constructs and returns an instance of the Amstrad CPC. -Machine *Machine::PCCompatible(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::PCCompatible(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { const Target *const pc_target = dynamic_cast(target); switch(pc_target->adaptor) { - case Target::VideoAdaptor::MDA: return new PCCompatible::ConcreteMachine(*pc_target, rom_fetcher); - case Target::VideoAdaptor::CGA: return new PCCompatible::ConcreteMachine(*pc_target, rom_fetcher); + case Target::VideoAdaptor::MDA: return std::make_unique>(*pc_target, rom_fetcher); + case Target::VideoAdaptor::CGA: return std::make_unique>(*pc_target, rom_fetcher); default: return nullptr; } } diff --git a/Machines/PCCompatible/PCCompatible.hpp b/Machines/PCCompatible/PCCompatible.hpp index d2b8c9c41..74cacb829 100644 --- a/Machines/PCCompatible/PCCompatible.hpp +++ b/Machines/PCCompatible/PCCompatible.hpp @@ -24,7 +24,7 @@ class Machine { virtual ~Machine(); /// Creates and returns a PC Compatible. - static Machine *PCCompatible( + static std::unique_ptr PCCompatible( const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher ); diff --git a/Machines/Sinclair/ZX8081/ZX8081.cpp b/Machines/Sinclair/ZX8081/ZX8081.cpp index 9d238bb0e..535bbd36d 100644 --- a/Machines/Sinclair/ZX8081/ZX8081.cpp +++ b/Machines/Sinclair/ZX8081/ZX8081.cpp @@ -496,12 +496,12 @@ template class ConcreteMachine: using namespace Sinclair::ZX8081; // See header; constructs and returns an instance of the ZX80 or 81. -Machine *Machine::ZX8081(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::ZX8081(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { const auto zx_target = dynamic_cast(target); // Instantiate the correct type of machine. - if(zx_target->is_ZX81) return new ConcreteMachine(*zx_target, rom_fetcher); - else return new ConcreteMachine(*zx_target, rom_fetcher); + if(zx_target->is_ZX81) return std::make_unique>(*zx_target, rom_fetcher); + else return std::make_unique>(*zx_target, rom_fetcher); } Machine::~Machine() {} diff --git a/Machines/Sinclair/ZX8081/ZX8081.hpp b/Machines/Sinclair/ZX8081/ZX8081.hpp index c755f8c94..4f0884a0b 100644 --- a/Machines/Sinclair/ZX8081/ZX8081.hpp +++ b/Machines/Sinclair/ZX8081/ZX8081.hpp @@ -22,7 +22,7 @@ namespace Sinclair::ZX8081 { class Machine { public: virtual ~Machine(); - static Machine *ZX8081(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr ZX8081(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); virtual void set_tape_is_playing(bool is_playing) = 0; virtual bool get_tape_is_playing() = 0; diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp index 7f7ad7f08..049d31e82 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp @@ -991,16 +991,16 @@ template class ConcreteMachine: using namespace Sinclair::ZXSpectrum; -Machine *Machine::ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { +std::unique_ptr Machine::ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { const auto zx_target = dynamic_cast(target); switch(zx_target->model) { - case Model::SixteenK: return new ConcreteMachine(*zx_target, rom_fetcher); - case Model::FortyEightK: return new ConcreteMachine(*zx_target, rom_fetcher); - case Model::OneTwoEightK: return new ConcreteMachine(*zx_target, rom_fetcher); - case Model::Plus2: return new ConcreteMachine(*zx_target, rom_fetcher); - case Model::Plus2a: return new ConcreteMachine(*zx_target, rom_fetcher); - case Model::Plus3: return new ConcreteMachine(*zx_target, rom_fetcher); + case Model::SixteenK: return std::make_unique>(*zx_target, rom_fetcher); + case Model::FortyEightK: return std::make_unique>(*zx_target, rom_fetcher); + case Model::OneTwoEightK: return std::make_unique>(*zx_target, rom_fetcher); + case Model::Plus2: return std::make_unique>(*zx_target, rom_fetcher); + case Model::Plus2a: return std::make_unique>(*zx_target, rom_fetcher); + case Model::Plus3: return std::make_unique>(*zx_target, rom_fetcher); } return nullptr; diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.hpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.hpp index 383252c90..d21017b80 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.hpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.hpp @@ -21,7 +21,7 @@ namespace Sinclair::ZXSpectrum { class Machine { public: virtual ~Machine(); - static Machine *ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); virtual void set_tape_is_playing(bool is_playing) = 0; virtual bool get_tape_is_playing() = 0; diff --git a/Machines/Utility/MachineForTarget.cpp b/Machines/Utility/MachineForTarget.cpp index c5fa20745..a6a459809 100644 --- a/Machines/Utility/MachineForTarget.cpp +++ b/Machines/Utility/MachineForTarget.cpp @@ -50,12 +50,12 @@ #include "../../Analyser/Dynamic/MultiMachine/MultiMachine.hpp" #include "TypedDynamicMachine.hpp" -Machine::DynamicMachine *Machine::MachineForTarget(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher, Machine::Error &error) { +std::unique_ptr Machine::MachineForTarget(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher, Machine::Error &error) { error = Machine::Error::None; - Machine::DynamicMachine *machine = nullptr; + std::unique_ptr machine; try { -#define BindD(name, m) case Analyser::Machine::m: machine = new Machine::TypedDynamicMachine<::name::Machine>(name::Machine::m(target, rom_fetcher)); break; +#define BindD(name, m) case Analyser::Machine::m: machine = std::make_unique>(name::Machine::m(target, rom_fetcher)); break; #define Bind(m) BindD(m, m) switch(target->machine) { Bind(Amiga) @@ -95,7 +95,7 @@ Machine::DynamicMachine *Machine::MachineForTarget(const Analyser::Static::Targe return machine; } -Machine::DynamicMachine *Machine::MachineForTargets(const Analyser::Static::TargetList &targets, const ROMMachine::ROMFetcher &rom_fetcher, Error &error) { +std::unique_ptr Machine::MachineForTargets(const Analyser::Static::TargetList &targets, const ROMMachine::ROMFetcher &rom_fetcher, Error &error) { // Zero targets implies no machine. if(targets.empty()) { error = Error::NoTargets; @@ -117,9 +117,9 @@ Machine::DynamicMachine *Machine::MachineForTargets(const Analyser::Static::Targ // If a multimachine would just instantly collapse the list to a single machine, do // so without the ongoing baggage of a multimachine. if(Analyser::Dynamic::MultiMachine::would_collapse(machines)) { - return machines.front().release(); + return std::move(machines.front()); } else { - return new Analyser::Dynamic::MultiMachine(std::move(machines)); + return std::make_unique(std::move(machines)); } } diff --git a/Machines/Utility/MachineForTarget.hpp b/Machines/Utility/MachineForTarget.hpp index e0b0dbc37..8cf0e0b93 100644 --- a/Machines/Utility/MachineForTarget.hpp +++ b/Machines/Utility/MachineForTarget.hpp @@ -45,13 +45,13 @@ enum class Error { receive the supplied static analyser result. The machine has been allocated on the heap. It is the caller's responsibility to delete the class when finished. */ -DynamicMachine *MachineForTargets(const Analyser::Static::TargetList &targets, const ::ROMMachine::ROMFetcher &rom_fetcher, Error &error); +std::unique_ptr MachineForTargets(const Analyser::Static::TargetList &targets, const ::ROMMachine::ROMFetcher &rom_fetcher, Error &error); /*! Allocates an instance of DynamicMaachine holding the machine described by @c target. It is the caller's responsibility to delete the class when finished. */ -DynamicMachine *MachineForTarget(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher, Machine::Error &error); +std::unique_ptr MachineForTarget(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher, Machine::Error &error); /*! Returns a short string name for the machine identified by the target, diff --git a/Machines/Utility/TypedDynamicMachine.hpp b/Machines/Utility/TypedDynamicMachine.hpp index 5e60226cc..b6a9b699b 100644 --- a/Machines/Utility/TypedDynamicMachine.hpp +++ b/Machines/Utility/TypedDynamicMachine.hpp @@ -11,11 +11,13 @@ #include "MachineForTarget.hpp" +#include + namespace Machine { template class TypedDynamicMachine: public ::Machine::DynamicMachine { public: - TypedDynamicMachine(T *machine) : machine_(machine) {} + TypedDynamicMachine(std::unique_ptr &&machine) : machine_(std::move(machine)) {} T *get() { return machine_.get(); } TypedDynamicMachine() : TypedDynamicMachine(nullptr) {} diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index 1a49f67b0..81bafb355 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -142,7 +142,7 @@ struct ActivityObserver: public Activity::Observer { Machine::Error error; ROM::Request missing_roms; - _machine.reset(Machine::MachineForTargets(_analyser.targets, CSROMFetcher(&missing_roms), error)); + _machine = Machine::MachineForTargets(_analyser.targets, CSROMFetcher(&missing_roms), error); if(!_machine) { const std::wstring description = missing_roms.description(0, L'•'); static_assert(sizeof(wchar_t) == 4, "This code assumes wchar_t is UTF32"); diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index 378ef09b8..37080d954 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -288,7 +288,7 @@ void MainWindow::launchMachine() { return results; }; Machine::Error error; - machine.reset(Machine::MachineForTargets(targets, rom_fetcher, error)); + machine = Machine::MachineForTargets(targets, rom_fetcher, error); if(error != Machine::Error::None) { switch(error) {