1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-21 21:33:54 +00:00

Avoid use of raw pointers in machine creation.

This commit is contained in:
Thomas Harte 2024-01-12 22:03:19 -05:00
parent ad3632cbe4
commit 3ab6953246
39 changed files with 96 additions and 87 deletions

View File

@ -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> 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<const Target *>(target);
return new Amiga::ConcreteMachine(*amiga_target, rom_fetcher);
return std::make_unique<Amiga::ConcreteMachine>(*amiga_target, rom_fetcher);
}
Machine::~Machine() {}

View File

@ -12,6 +12,8 @@
#include "../../Analyser/Static/StaticAnalyser.hpp"
#include "../ROMMachine.hpp"
#include <memory>
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<Machine> Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
};
}

View File

@ -1285,12 +1285,12 @@ template <bool has_fdc> 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> 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<const Target *>(target);
switch(cpc_target->model) {
default: return new AmstradCPC::ConcreteMachine<true>(*cpc_target, rom_fetcher);
case Target::Model::CPC464: return new AmstradCPC::ConcreteMachine<false>(*cpc_target, rom_fetcher);
default: return std::make_unique<AmstradCPC::ConcreteMachine<true>>(*cpc_target, rom_fetcher);
case Target::Model::CPC464: return std::make_unique<AmstradCPC::ConcreteMachine<false>>(*cpc_target, rom_fetcher);
}
}

View File

@ -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<Machine> AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
/// Defines the runtime options available for an Amstrad CPC.
class Options:

View File

@ -985,15 +985,15 @@ template <Analyser::Static::AppleII::Target::Model model> class ConcreteMachine:
using namespace Apple::II;
Machine *Machine::AppleII(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> 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<const Target *>(target);
switch(appleii_target->model) {
default: return nullptr;
case Target::Model::II: return new ConcreteMachine<Target::Model::II>(*appleii_target, rom_fetcher);
case Target::Model::IIplus: return new ConcreteMachine<Target::Model::IIplus>(*appleii_target, rom_fetcher);
case Target::Model::IIe: return new ConcreteMachine<Target::Model::IIe>(*appleii_target, rom_fetcher);
case Target::Model::EnhancedIIe: return new ConcreteMachine<Target::Model::EnhancedIIe>(*appleii_target, rom_fetcher);
case Target::Model::II: return std::make_unique<ConcreteMachine<Target::Model::II>>(*appleii_target, rom_fetcher);
case Target::Model::IIplus: return std::make_unique<ConcreteMachine<Target::Model::IIplus>>(*appleii_target, rom_fetcher);
case Target::Model::IIe: return std::make_unique<ConcreteMachine<Target::Model::IIe>>(*appleii_target, rom_fetcher);
case Target::Model::EnhancedIIe: return std::make_unique<ConcreteMachine<Target::Model::EnhancedIIe>>(*appleii_target, rom_fetcher);
}
}

View File

@ -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<Machine> 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<Options>, public Configurable::DisplayOption<Options> {

View File

@ -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<const Analyser::Static::AppleIIgs::Target *>(target), rom_fetcher);
std::unique_ptr<Machine> Machine::AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
return std::make_unique<ConcreteMachine>(*dynamic_cast<const Analyser::Static::AppleIIgs::Target *>(target), rom_fetcher);
}
Machine::~Machine() {}

View File

@ -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<Machine> AppleIIgs(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
};
}

View File

@ -840,16 +840,16 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
using namespace Apple::Macintosh;
Machine *Machine::Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> Machine::Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
auto *const mac_target = dynamic_cast<const Analyser::Static::Macintosh::Target *>(target);
using Model = Analyser::Static::Macintosh::Target::Model;
switch(mac_target->model) {
default:
case Model::Mac128k: return new ConcreteMachine<Model::Mac128k>(*mac_target, rom_fetcher);
case Model::Mac512k: return new ConcreteMachine<Model::Mac512k>(*mac_target, rom_fetcher);
case Model::Mac512ke: return new ConcreteMachine<Model::Mac512ke>(*mac_target, rom_fetcher);
case Model::MacPlus: return new ConcreteMachine<Model::MacPlus>(*mac_target, rom_fetcher);
case Model::Mac128k: return std::make_unique<ConcreteMachine<Model::Mac128k>>(*mac_target, rom_fetcher);
case Model::Mac512k: return std::make_unique<ConcreteMachine<Model::Mac512k>>(*mac_target, rom_fetcher);
case Model::Mac512ke: return std::make_unique<ConcreteMachine<Model::Mac512ke>>(*mac_target, rom_fetcher);
case Model::MacPlus: return std::make_unique<ConcreteMachine<Model::MacPlus>>(*mac_target, rom_fetcher);
}
}

View File

@ -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<Machine> Macintosh(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::QuickbootOption<Options> {
friend Configurable::QuickbootOption<Options>;

View File

@ -212,9 +212,9 @@ class ConcreteMachine:
using namespace Atari2600;
Machine *Machine::Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &) {
std::unique_ptr<Machine> Machine::Atari2600(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &) {
const Target *const atari_target = dynamic_cast<const Target *>(target);
return new Atari2600::ConcreteMachine(*atari_target);
return std::make_unique<Atari2600::ConcreteMachine>(*atari_target);
}
Machine::~Machine() {}

View File

@ -15,6 +15,8 @@
#include "Atari2600Inputs.h"
#include <memory>
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<Machine> 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;

View File

@ -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> Machine::AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
auto *const atari_target = dynamic_cast<const Analyser::Static::AtariST::Target *>(target);
if(!atari_target) {
return nullptr;
}
return new ConcreteMachine(*atari_target, rom_fetcher);
return std::make_unique<ConcreteMachine>(*atari_target, rom_fetcher);
}
Machine::~Machine() {}

View File

@ -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<Machine> AtariST(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -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> Machine::ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
return std::make_unique<ConcreteMachine>(*target, rom_fetcher);
}
Machine::~Machine() {}

View File

@ -14,12 +14,14 @@
#include "../../Analyser/Static/StaticAnalyser.hpp"
#include "../ROMMachine.hpp"
#include <memory>
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<Machine> ColecoVision(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -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> 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<const Target *>(target);
return new Vic20::ConcreteMachine(*commodore_target, rom_fetcher);
return std::make_unique<Vic20::ConcreteMachine>(*commodore_target, rom_fetcher);
}
Machine::~Machine() {}

View File

@ -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<Machine> Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options>, public Configurable::QuickloadOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -786,14 +786,14 @@ template <bool has_scsi_bus> class ConcreteMachine:
using namespace Electron;
Machine *Machine::Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> 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<const Target *>(target);
if(acorn_target->media.mass_storage_devices.empty()) {
return new Electron::ConcreteMachine<false>(*acorn_target, rom_fetcher);
return std::make_unique<Electron::ConcreteMachine<false>>(*acorn_target, rom_fetcher);
} else {
return new Electron::ConcreteMachine<true>(*acorn_target, rom_fetcher);
return std::make_unique<Electron::ConcreteMachine<true>>(*acorn_target, rom_fetcher);
}
}

View File

@ -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<Machine> Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
/// Defines the runtime options available for an Electron.
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options>, public Configurable::QuickloadOption<Options> {

View File

@ -748,13 +748,13 @@ template <bool has_disk_controller, bool is_6mhz> class ConcreteMachine:
using namespace Enterprise;
Machine *Machine::Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> 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<const Target *>(target);
#define BuildMachine(exdos, sixmhz) \
if((enterprise_target->dos == Target::DOS::None) != exdos && (enterprise_target->speed == Target::Speed::SixMHz) == sixmhz) { \
return new Enterprise::ConcreteMachine<exdos, sixmhz>(*enterprise_target, rom_fetcher); \
return std::make_unique<Enterprise::ConcreteMachine<exdos, sixmhz>>(*enterprise_target, rom_fetcher); \
}
BuildMachine(false, false);

View File

@ -14,6 +14,8 @@
#include "../../Configurable/StandardOptions.hpp"
#include "../ROMMachine.hpp"
#include <memory>
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<Machine> Enterprise(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
/// Defines the runtime options available for an Enterprise.
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options> {

View File

@ -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> Machine::MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
const auto msx_target = dynamic_cast<const Target *>(target);
if(msx_target->has_msx_music) {
switch(msx_target->model) {
default: return nullptr;
case Target::Model::MSX1: return new ConcreteMachine<Target::Model::MSX1, true>(*msx_target, rom_fetcher);
case Target::Model::MSX2: return new ConcreteMachine<Target::Model::MSX2, true>(*msx_target, rom_fetcher);
case Target::Model::MSX1: return std::make_unique<ConcreteMachine<Target::Model::MSX1, true>>(*msx_target, rom_fetcher);
case Target::Model::MSX2: return std::make_unique<ConcreteMachine<Target::Model::MSX2, true>>(*msx_target, rom_fetcher);
}
} else {
switch(msx_target->model) {
default: return nullptr;
case Target::Model::MSX1: return new ConcreteMachine<Target::Model::MSX1, false>(*msx_target, rom_fetcher);
case Target::Model::MSX2: return new ConcreteMachine<Target::Model::MSX2, false>(*msx_target, rom_fetcher);
case Target::Model::MSX1: return std::make_unique<ConcreteMachine<Target::Model::MSX1, false>>(*msx_target, rom_fetcher);
case Target::Model::MSX2: return std::make_unique<ConcreteMachine<Target::Model::MSX2, false>>(*msx_target, rom_fetcher);
}
}
}

View File

@ -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<Machine> MSX(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options>, public Configurable::QuickloadOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -557,14 +557,14 @@ template <Analyser::Static::Sega::Target::Model model> class ConcreteMachine:
using namespace Sega::MasterSystem;
Machine *Machine::MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> 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<const Target *>(target);
switch(sega_target->model) {
case Target::Model::SG1000: return new ConcreteMachine<Target::Model::SG1000>(*sega_target, rom_fetcher);
case Target::Model::MasterSystem: return new ConcreteMachine<Target::Model::MasterSystem>(*sega_target, rom_fetcher);
case Target::Model::MasterSystem2: return new ConcreteMachine<Target::Model::MasterSystem2>(*sega_target, rom_fetcher);
case Target::Model::SG1000: return std::make_unique<ConcreteMachine<Target::Model::SG1000>>(*sega_target, rom_fetcher);
case Target::Model::MasterSystem: return std::make_unique<ConcreteMachine<Target::Model::MasterSystem>>(*sega_target, rom_fetcher);
case Target::Model::MasterSystem2: return std::make_unique<ConcreteMachine<Target::Model::MasterSystem2>>(*sega_target, rom_fetcher);
default:
assert(false);
return nullptr;

View File

@ -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<Machine> MasterSystem(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -795,16 +795,16 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface, CPU::MOS
using namespace Oric;
Machine *Machine::Oric(const Analyser::Static::Target *target_hint, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> Machine::Oric(const Analyser::Static::Target *target_hint, const ROMMachine::ROMFetcher &rom_fetcher) {
auto *const oric_target = dynamic_cast<const Analyser::Static::Oric::Target *>(target_hint);
#define DiskInterfaceSwitch(processor) \
switch(oric_target->disk_interface) { \
default: return new ConcreteMachine<DiskInterface::None, processor>(*oric_target, rom_fetcher); \
case DiskInterface::Microdisc: return new ConcreteMachine<DiskInterface::Microdisc, processor>(*oric_target, rom_fetcher); \
case DiskInterface::Pravetz: return new ConcreteMachine<DiskInterface::Pravetz, processor>(*oric_target, rom_fetcher); \
case DiskInterface::Jasmin: return new ConcreteMachine<DiskInterface::Jasmin, processor>(*oric_target, rom_fetcher); \
case DiskInterface::BD500: return new ConcreteMachine<DiskInterface::BD500, processor>(*oric_target, rom_fetcher); \
default: return std::make_unique<ConcreteMachine<DiskInterface::None, processor>>(*oric_target, rom_fetcher); \
case DiskInterface::Microdisc: return std::make_unique<ConcreteMachine<DiskInterface::Microdisc, processor>>(*oric_target, rom_fetcher); \
case DiskInterface::Pravetz: return std::make_unique<ConcreteMachine<DiskInterface::Pravetz, processor>>(*oric_target, rom_fetcher); \
case DiskInterface::Jasmin: return std::make_unique<ConcreteMachine<DiskInterface::Jasmin, processor>>(*oric_target, rom_fetcher); \
case DiskInterface::BD500: return std::make_unique<ConcreteMachine<DiskInterface::BD500, processor>>(*oric_target, rom_fetcher); \
}
switch(oric_target->processor) {

View File

@ -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<Machine> Oric(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options>, public Configurable::QuickloadOption<Options> {
friend Configurable::DisplayOption<Options>;

View File

@ -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> Machine::PCCompatible(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
const Target *const pc_target = dynamic_cast<const Target *>(target);
switch(pc_target->adaptor) {
case Target::VideoAdaptor::MDA: return new PCCompatible::ConcreteMachine<Target::VideoAdaptor::MDA>(*pc_target, rom_fetcher);
case Target::VideoAdaptor::CGA: return new PCCompatible::ConcreteMachine<Target::VideoAdaptor::CGA>(*pc_target, rom_fetcher);
case Target::VideoAdaptor::MDA: return std::make_unique<PCCompatible::ConcreteMachine<Target::VideoAdaptor::MDA>>(*pc_target, rom_fetcher);
case Target::VideoAdaptor::CGA: return std::make_unique<PCCompatible::ConcreteMachine<Target::VideoAdaptor::CGA>>(*pc_target, rom_fetcher);
default: return nullptr;
}
}

View File

@ -24,7 +24,7 @@ class Machine {
virtual ~Machine();
/// Creates and returns a PC Compatible.
static Machine *PCCompatible(
static std::unique_ptr<Machine> PCCompatible(
const Analyser::Static::Target *target,
const ROMMachine::ROMFetcher &rom_fetcher
);

View File

@ -496,12 +496,12 @@ template<bool is_zx81> 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> Machine::ZX8081(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
const auto zx_target = dynamic_cast<const Analyser::Static::ZX8081::Target *>(target);
// Instantiate the correct type of machine.
if(zx_target->is_ZX81) return new ConcreteMachine<true>(*zx_target, rom_fetcher);
else return new ConcreteMachine<false>(*zx_target, rom_fetcher);
if(zx_target->is_ZX81) return std::make_unique<ConcreteMachine<true>>(*zx_target, rom_fetcher);
else return std::make_unique<ConcreteMachine<false>>(*zx_target, rom_fetcher);
}
Machine::~Machine() {}

View File

@ -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<Machine> 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;

View File

@ -991,16 +991,16 @@ template<Model model> class ConcreteMachine:
using namespace Sinclair::ZXSpectrum;
Machine *Machine::ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
std::unique_ptr<Machine> Machine::ZXSpectrum(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
const auto zx_target = dynamic_cast<const Analyser::Static::ZXSpectrum::Target *>(target);
switch(zx_target->model) {
case Model::SixteenK: return new ConcreteMachine<Model::SixteenK>(*zx_target, rom_fetcher);
case Model::FortyEightK: return new ConcreteMachine<Model::FortyEightK>(*zx_target, rom_fetcher);
case Model::OneTwoEightK: return new ConcreteMachine<Model::OneTwoEightK>(*zx_target, rom_fetcher);
case Model::Plus2: return new ConcreteMachine<Model::Plus2>(*zx_target, rom_fetcher);
case Model::Plus2a: return new ConcreteMachine<Model::Plus2a>(*zx_target, rom_fetcher);
case Model::Plus3: return new ConcreteMachine<Model::Plus3>(*zx_target, rom_fetcher);
case Model::SixteenK: return std::make_unique<ConcreteMachine<Model::SixteenK>>(*zx_target, rom_fetcher);
case Model::FortyEightK: return std::make_unique<ConcreteMachine<Model::FortyEightK>>(*zx_target, rom_fetcher);
case Model::OneTwoEightK: return std::make_unique<ConcreteMachine<Model::OneTwoEightK>>(*zx_target, rom_fetcher);
case Model::Plus2: return std::make_unique<ConcreteMachine<Model::Plus2>>(*zx_target, rom_fetcher);
case Model::Plus2a: return std::make_unique<ConcreteMachine<Model::Plus2a>>(*zx_target, rom_fetcher);
case Model::Plus3: return std::make_unique<ConcreteMachine<Model::Plus3>>(*zx_target, rom_fetcher);
}
return nullptr;

View File

@ -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<Machine> 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;

View File

@ -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::DynamicMachine> 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::DynamicMachine> 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<Machine::TypedDynamicMachine<::name::Machine>>(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::DynamicMachine> 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<Analyser::Dynamic::MultiMachine>(std::move(machines));
}
}

View File

@ -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<DynamicMachine> 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<DynamicMachine> 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,

View File

@ -11,11 +11,13 @@
#include "MachineForTarget.hpp"
#include <memory>
namespace Machine {
template<typename T> class TypedDynamicMachine: public ::Machine::DynamicMachine {
public:
TypedDynamicMachine(T *machine) : machine_(machine) {}
TypedDynamicMachine(std::unique_ptr<T> &&machine) : machine_(std::move(machine)) {}
T *get() { return machine_.get(); }
TypedDynamicMachine() : TypedDynamicMachine(nullptr) {}

View File

@ -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");

View File

@ -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) {