mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 16:31:31 +00:00
Merge pull request #282 from TomHarte/BooleanSelections
Boolean selections
This commit is contained in:
commit
6f8d4d6c5c
27
Configurable/Configurable.cpp
Normal file
27
Configurable/Configurable.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// Configurable.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/11/2017.
|
||||
// Copyright © 2017 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Configurable.hpp"
|
||||
|
||||
using namespace Configurable;
|
||||
|
||||
ListSelection *BooleanSelection::list_selection() {
|
||||
return new ListSelection(value ? "yes" : "no");
|
||||
}
|
||||
|
||||
ListSelection *ListSelection::list_selection() {
|
||||
return new ListSelection(value);
|
||||
}
|
||||
|
||||
BooleanSelection *ListSelection::boolean_selection() {
|
||||
return new BooleanSelection(value != "no" && value != "n");
|
||||
}
|
||||
|
||||
BooleanSelection *BooleanSelection::boolean_selection() {
|
||||
return new BooleanSelection(value);
|
||||
}
|
@ -37,20 +37,31 @@ struct ListOption: public Option {
|
||||
ListOption(const std::string &long_name, const std::string &short_name, const std::vector<std::string> &options) : Option(long_name, short_name), options(options) {}
|
||||
};
|
||||
|
||||
struct BooleanSelection;
|
||||
struct ListSelection;
|
||||
|
||||
/*!
|
||||
Selections are responses to Options.
|
||||
*/
|
||||
struct Selection {
|
||||
virtual ~Selection() {}
|
||||
virtual ListSelection *list_selection() = 0;
|
||||
virtual BooleanSelection *boolean_selection() = 0;
|
||||
};
|
||||
|
||||
struct BooleanSelection: public Selection {
|
||||
bool value;
|
||||
|
||||
ListSelection *list_selection();
|
||||
BooleanSelection *boolean_selection();
|
||||
BooleanSelection(bool value) : value(value) {}
|
||||
};
|
||||
|
||||
struct ListSelection: public Selection {
|
||||
std::string value;
|
||||
|
||||
ListSelection *list_selection();
|
||||
BooleanSelection *boolean_selection();
|
||||
ListSelection(const std::string value) : value(value) {}
|
||||
};
|
||||
|
||||
|
@ -123,6 +123,8 @@
|
||||
4B055AEF1FAE9BF00060FFFF /* Typer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2B3A471F9B8FA70062DABF /* Typer.cpp */; };
|
||||
4B055AF11FAE9C160060FFFF /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */; };
|
||||
4B055AF21FAE9C1C0060FFFF /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B055AF01FAE9C080060FFFF /* OpenGL.framework */; };
|
||||
4B07835A1FC11D10001D12BB /* Configurable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0783591FC11D10001D12BB /* Configurable.cpp */; };
|
||||
4B07835B1FC11D42001D12BB /* Configurable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0783591FC11D10001D12BB /* Configurable.cpp */; };
|
||||
4B08A2751EE35D56008B7065 /* Z80InterruptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B08A2741EE35D56008B7065 /* Z80InterruptTests.swift */; };
|
||||
4B08A2781EE39306008B7065 /* TestMachine.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B08A2771EE39306008B7065 /* TestMachine.mm */; };
|
||||
4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0CCC421C62D0B3001CAC5F /* CRT.cpp */; };
|
||||
@ -617,6 +619,7 @@
|
||||
4B055ABE1FAE98000060FFFF /* MachineForTarget.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MachineForTarget.cpp; sourceTree = "<group>"; };
|
||||
4B055ABF1FAE98000060FFFF /* MachineForTarget.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MachineForTarget.hpp; sourceTree = "<group>"; };
|
||||
4B055AF01FAE9C080060FFFF /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
|
||||
4B0783591FC11D10001D12BB /* Configurable.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Configurable.cpp; sourceTree = "<group>"; };
|
||||
4B08A2741EE35D56008B7065 /* Z80InterruptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Z80InterruptTests.swift; sourceTree = "<group>"; };
|
||||
4B08A2761EE39306008B7065 /* TestMachine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMachine.h; sourceTree = "<group>"; };
|
||||
4B08A2771EE39306008B7065 /* TestMachine.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestMachine.mm; sourceTree = "<group>"; };
|
||||
@ -1514,6 +1517,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4B31B88F1FBFBCD800C140D5 /* Configurable.hpp */,
|
||||
4B0783591FC11D10001D12BB /* Configurable.cpp */,
|
||||
);
|
||||
name = Configurable;
|
||||
path = ../../Configurable;
|
||||
@ -3218,6 +3222,7 @@
|
||||
4B055AAF1FAE85FD0060FFFF /* UnformattedTrack.cpp in Sources */,
|
||||
4B055A7E1FAE84AA0060FFFF /* main.cpp in Sources */,
|
||||
4B055A9F1FAE85DA0060FFFF /* HFE.cpp in Sources */,
|
||||
4B07835B1FC11D42001D12BB /* Configurable.cpp in Sources */,
|
||||
4B055AE71FAE9B6F0060FFFF /* Shader.cpp in Sources */,
|
||||
4B055AEC1FAE9BA20060FFFF /* Z80Base.cpp in Sources */,
|
||||
4B055AE31FAE9B6F0060FFFF /* TextureBuilder.cpp in Sources */,
|
||||
@ -3254,6 +3259,7 @@
|
||||
4BCF1FA41DADC3DD0039D2E7 /* Oric.cpp in Sources */,
|
||||
4B54C0CB1F8D92590050900F /* Keyboard.cpp in Sources */,
|
||||
4BEA525E1DF33323007E74F2 /* Tape.cpp in Sources */,
|
||||
4B07835A1FC11D10001D12BB /* Configurable.cpp in Sources */,
|
||||
4B8334951F5E25B60097E338 /* C1540.cpp in Sources */,
|
||||
4B1497921EE4B5A800CE2596 /* ZX8081.cpp in Sources */,
|
||||
4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */,
|
||||
|
@ -18,6 +18,8 @@ SOURCES += glob.glob('../../Components/AY38910/*.cpp')
|
||||
|
||||
SOURCES += glob.glob('../../Concurrency/*.cpp')
|
||||
|
||||
SOURCES += glob.glob('../../Configurable/*.cpp')
|
||||
|
||||
SOURCES += glob.glob('../../Inputs/*.cpp')
|
||||
|
||||
SOURCES += glob.glob('../../Machines/*.cpp')
|
||||
|
@ -298,6 +298,22 @@ int main(int argc, char *argv[]) {
|
||||
Configurable::Device *configurable_device = machine->configurable_device();
|
||||
if(configurable_device) {
|
||||
configurable_device->set_selections(configurable_device->get_user_friendly_selections());
|
||||
|
||||
// Consider transcoding any list selections that map to Boolean options.
|
||||
for(auto &option: configurable_device->get_options()) {
|
||||
// Check for a corresponding selection.
|
||||
auto selection = arguments.selections.find(option->short_name);
|
||||
if(selection != arguments.selections.end()) {
|
||||
// Transcode selection if necessary.
|
||||
if(dynamic_cast<Configurable::BooleanOption *>(option.get())) {
|
||||
arguments.selections[selection->first] = std::unique_ptr<Configurable::Selection>(selection->second->boolean_selection());
|
||||
}
|
||||
|
||||
if(dynamic_cast<Configurable::ListOption *>(option.get())) {
|
||||
arguments.selections[selection->first] = std::unique_ptr<Configurable::Selection>(selection->second->list_selection());
|
||||
}
|
||||
}
|
||||
}
|
||||
configurable_device->set_selections(arguments.selections);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user