| e8555c89 Andy McCall |
1 |
#include "HDImageCLI.hh" |
| 2 |
|
| 3 |
#include "CommandLineParser.hh" |
| 4 |
#include "MSXException.hh" |
| 5 |
|
| 6 |
#include <algorithm> |
| 7 |
#include <utility> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
namespace openmsx { |
| 11 |
|
| 12 |
namespace { |
| 13 |
struct IdImage { |
| 14 |
int id; |
| 15 |
std::string image; |
| 16 |
}; |
| 17 |
} |
| 18 |
static std::vector<IdImage> images; |
| 19 |
|
| 20 |
HDImageCLI::HDImageCLI(CommandLineParser& parser_) |
| 21 |
: parser(parser_) |
| 22 |
{ |
| 23 |
parser.registerOption("-hda", *this, CommandLineParser::Phase::BEFORE_MACHINE); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
void HDImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine) |
| 28 |
{ |
| 29 |
|
| 30 |
int id = option[3] - 'a'; |
| 31 |
images.emplace_back(id, getArgument(option, cmdLine)); |
| 32 |
} |
| 33 |
|
| 34 |
std::string HDImageCLI::getImageForId(int id) |
| 35 |
{ |
| 36 |
|
| 37 |
|
| 38 |
std::string result; |
| 39 |
if (auto it = std::ranges::find(images, id, &IdImage::id); |
| 40 |
it != end(images)) { |
| 41 |
result = std::move(it->image); |
| 42 |
images.erase(it); |
| 43 |
} |
| 44 |
return result; |
| 45 |
} |
| 46 |
|
| 47 |
void HDImageCLI::parseDone() |
| 48 |
{ |
| 49 |
|
| 50 |
|
| 51 |
if (!images.empty()) { |
| 52 |
auto hd = char(::toupper('a' + images.front().id)); |
| 53 |
throw MSXException("No hard disk ", hd, " present."); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
std::string_view HDImageCLI::optionHelp() const |
| 58 |
{ |
| 59 |
return "Use hard disk image in argument for the IDE or SCSI extensions"; |
| 60 |
} |
| 61 |
|
| 62 |
} |