diff --git a/Analyser/Static/StaticAnalyser.cpp b/Analyser/Static/StaticAnalyser.cpp index 2a4920acc..88167f26c 100644 --- a/Analyser/Static/StaticAnalyser.cpp +++ b/Analyser/Static/StaticAnalyser.cpp @@ -80,6 +80,8 @@ // Target Platform Types #include "../../Storage/TargetPlatforms.hpp" +template inline constexpr bool always_false_v = false; + using namespace Analyser::Static; namespace { @@ -123,7 +125,21 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform:: if(extension == "2mg") { // 2MG uses a factory method; defer to it. try { - InsertInstance(result.disks, Storage::Disk::Disk2MG::open(file_name), TargetPlatform::DiskII) + const auto media = Storage::Disk::Disk2MG::open(file_name); + std::visit([&result, &potential_platforms](auto &&arg) { + using Type = typename std::decay::type; + + if constexpr (std::is_same::value) { + // It's valid for no media to be returned. + } else if constexpr (std::is_same::value) { + InsertInstance(result.disks, arg, TargetPlatform::DiskII); + } else if constexpr (std::is_same::value) { + // TODO: or is it Apple IIgs? + InsertInstance(result.mass_storage_devices, arg, TargetPlatform::AppleII); + } else { + static_assert(always_false_v, "Unexpected type encountered."); + } + }, media); } catch(...) {} } diff --git a/Storage/Disk/DiskImage/Formats/2MG.cpp b/Storage/Disk/DiskImage/Formats/2MG.cpp index 3defec745..b7839b9ae 100644 --- a/Storage/Disk/DiskImage/Formats/2MG.cpp +++ b/Storage/Disk/DiskImage/Formats/2MG.cpp @@ -14,7 +14,7 @@ using namespace Storage::Disk; -DiskImageHolderBase *Disk2MG::open(const std::string &file_name) { +Disk2MG::DiskOrMassStorageDevice Disk2MG::open(const std::string &file_name) { FileHolder file(file_name); // Check the signature. diff --git a/Storage/Disk/DiskImage/Formats/2MG.hpp b/Storage/Disk/DiskImage/Formats/2MG.hpp index 8b37112a2..8b512e189 100644 --- a/Storage/Disk/DiskImage/Formats/2MG.hpp +++ b/Storage/Disk/DiskImage/Formats/2MG.hpp @@ -10,8 +10,12 @@ #define _MG_hpp #include "../DiskImage.hpp" +#include "../../../MassStorage/MassStorageDevice.hpp" + #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -26,7 +30,8 @@ namespace Disk { class Disk2MG { public: - static DiskImageHolderBase *open(const std::string &file_name); + using DiskOrMassStorageDevice = std::variant; + static DiskOrMassStorageDevice open(const std::string &file_name); }; }