openMSX
HDImageCLI.cc
Go to the documentation of this file.
1#include "HDImageCLI.hh"
3#include "MSXException.hh"
4#include "ranges.hh"
5#include <utility>
6#include <vector>
7
8namespace openmsx {
9
10namespace {
11 struct IdImage {
12 int id;
13 std::string image;
14 };
15}
16static std::vector<IdImage> images;
17
19 : parser(parser_)
20{
22 // TODO: offer more options in case you want to specify 2 hard disk images?
23}
24
25void HDImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine)
26{
27 // Machine has not been loaded yet. Only remember the image.
28 int id = option[3] - 'a';
29 images.emplace_back(IdImage{id, getArgument(option, cmdLine)});
30}
31
32std::string HDImageCLI::getImageForId(int id)
33{
34 // HD queries image. Return (and clear) the remembered value, or return
35 // an empty string.
36 std::string result;
37 if (auto it = ranges::find(images, id, &IdImage::id);
38 it != end(images)) {
39 result = std::move(it->image);
40 images.erase(it);
41 }
42 return result;
43}
44
46{
47 // After parsing all remembered values should be cleared. If not there
48 // was no hard disk as specified.
49 if (!images.empty()) {
50 char hd = char(::toupper('a' + images.front().id));
51 throw MSXException("No hard disk ", hd, " present.");
52 }
53}
54
55std::string_view HDImageCLI::optionHelp() const
56{
57 return "Use hard disk image in argument for the IDE or SCSI extensions";
58}
59
60} // namespace openmsx
std::string image
Definition HDImageCLI.cc:13
uintptr_t id
static std::string getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition CLIOption.cc:9
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
void parseDone() override
Definition HDImageCLI.cc:45
std::string_view optionHelp() const override
Definition HDImageCLI.cc:55
HDImageCLI(CommandLineParser &parser)
Definition HDImageCLI.cc:18
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
Definition HDImageCLI.cc:25
static std::string getImageForId(int id)
Definition HDImageCLI.cc:32
This file implemented 3 utility functions:
Definition Autofire.cc:9
auto find(InputRange &&range, const T &value)
Definition ranges.hh:160
constexpr auto end(const zstring_view &x)