From 2ea050556b1644847074248444292e7f6677407d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Nov 2017 21:09:26 -0500 Subject: [PATCH 1/2] Adds transcoding of ostensible list selections to Boolean selections, and vice versa. --- Configurable/Configurable.cpp | 27 +++++++++++++++++++ Configurable/Configurable.hpp | 11 ++++++++ .../Clock Signal.xcodeproj/project.pbxproj | 6 +++++ OSBindings/SDL/SConstruct | 2 ++ OSBindings/SDL/main.cpp | 16 +++++++++++ 5 files changed, 62 insertions(+) create mode 100644 Configurable/Configurable.cpp diff --git a/Configurable/Configurable.cpp b/Configurable/Configurable.cpp new file mode 100644 index 000000000..3478ced64 --- /dev/null +++ b/Configurable/Configurable.cpp @@ -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); +} diff --git a/Configurable/Configurable.hpp b/Configurable/Configurable.hpp index 0748331d7..7def8d64a 100644 --- a/Configurable/Configurable.hpp +++ b/Configurable/Configurable.hpp @@ -37,20 +37,31 @@ struct ListOption: public Option { ListOption(const std::string &long_name, const std::string &short_name, const std::vector &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) {} }; diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 7cca3f355..6e8532ab6 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -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 = ""; }; 4B055ABF1FAE98000060FFFF /* MachineForTarget.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MachineForTarget.hpp; sourceTree = ""; }; 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 = ""; }; 4B08A2741EE35D56008B7065 /* Z80InterruptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Z80InterruptTests.swift; sourceTree = ""; }; 4B08A2761EE39306008B7065 /* TestMachine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMachine.h; sourceTree = ""; }; 4B08A2771EE39306008B7065 /* TestMachine.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestMachine.mm; sourceTree = ""; }; @@ -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 */, diff --git a/OSBindings/SDL/SConstruct b/OSBindings/SDL/SConstruct index 479173615..e0845d3cd 100644 --- a/OSBindings/SDL/SConstruct +++ b/OSBindings/SDL/SConstruct @@ -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') diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 02d3ec42b..bf00343e6 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.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(option.get())) { + arguments.selections[selection->first] = std::unique_ptr(selection->second->boolean_selection()); + } + + if(dynamic_cast(option.get())) { + arguments.selections[selection->first] = std::unique_ptr(selection->second->list_selection()); + } + } + } configurable_device->set_selections(arguments.selections); } From 63381ff5055104024b8b692e3ef366a1e741ca3b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Nov 2017 21:13:55 -0500 Subject: [PATCH 2/2] Fixes accidental typographic quote in SConstruct. --- OSBindings/SDL/SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OSBindings/SDL/SConstruct b/OSBindings/SDL/SConstruct index e0845d3cd..35786d80a 100644 --- a/OSBindings/SDL/SConstruct +++ b/OSBindings/SDL/SConstruct @@ -18,7 +18,7 @@ SOURCES += glob.glob('../../Components/AY38910/*.cpp') SOURCES += glob.glob('../../Concurrency/*.cpp') -SOURCES += glob.glob(‘../../Configurable/*.cpp') +SOURCES += glob.glob('../../Configurable/*.cpp') SOURCES += glob.glob('../../Inputs/*.cpp')