From 9995d776de4b38f2d4c6096e5ae964d2b57accee Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 18 Mar 2020 23:29:09 -0400 Subject: [PATCH] Attempts to fix the macOS version, plus some implicit type conversions. --- .../Mac/Clock Signal/Machine/CSMachine.mm | 63 ++++++++----------- Reflection/Enum.h | 2 +- Reflection/Struct.h | 4 +- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index c61e9e699..a3f3f27ae 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -586,9 +586,9 @@ struct ActivityObserver: public Activity::Observer { @synchronized(self) { _useFastLoadingHack = useFastLoadingHack; - Configurable::SelectionSet selection_set; - append_quick_load_tape_selection(selection_set, useFastLoadingHack ? true : false); - configurable_device->set_selections(selection_set); + auto options = configurable_device->get_options(); + Reflection::set(*options, "quickload", useFastLoadingHack ? true : false); + configurable_device->set_options(options); } } @@ -599,7 +599,6 @@ struct ActivityObserver: public Activity::Observer { @synchronized(self) { _videoSignal = videoSignal; - Configurable::SelectionSet selection_set; Configurable::Display display; switch(videoSignal) { case CSMachineVideoSignalRGB: display = Configurable::Display::RGB; break; @@ -607,8 +606,10 @@ struct ActivityObserver: public Activity::Observer { case CSMachineVideoSignalComposite: display = Configurable::Display::CompositeColour; break; case CSMachineVideoSignalMonochromeComposite: display = Configurable::Display::CompositeMonochrome; break; } - append_display_selection(selection_set, display); - configurable_device->set_selections(selection_set); + + auto options = configurable_device->get_options(); + Reflection::set(*options, "output", int(display)); + configurable_device->set_options(options); } } @@ -617,35 +618,23 @@ struct ActivityObserver: public Activity::Observer { if(!configurable_device) return NO; // Get the options this machine provides. - std::vector> options; @synchronized(self) { - options = configurable_device->get_options(); - } + auto options = configurable_device->get_options(); - // Get the standard option for this video signal. - Configurable::StandardOptions option; - switch(videoSignal) { - case CSMachineVideoSignalRGB: option = Configurable::DisplayRGB; break; - case CSMachineVideoSignalSVideo: option = Configurable::DisplaySVideo; break; - case CSMachineVideoSignalComposite: option = Configurable::DisplayCompositeColour; break; - case CSMachineVideoSignalMonochromeComposite: option = Configurable::DisplayCompositeMonochrome; break; - } - std::unique_ptr display_option = std::move(standard_options(option).front()); - Configurable::ListOption *display_list_option = dynamic_cast(display_option.get()); - NSAssert(display_list_option, @"Expected display option to be a list"); + // Get the standard option for this video signal. + Configurable::Display option; + switch(videoSignal) { + case CSMachineVideoSignalRGB: option = Configurable::Display::RGB; break; + case CSMachineVideoSignalSVideo: option = Configurable::Display::SVideo; break; + case CSMachineVideoSignalComposite: option = Configurable::Display::CompositeColour; break; + case CSMachineVideoSignalMonochromeComposite: option = Configurable::Display::CompositeMonochrome; break; + } - // See whether the video signal is included in the machine options. - for(auto &candidate: options) { - Configurable::ListOption *list_option = dynamic_cast(candidate.get()); + // Map to a string and check against returned options for the 'output' field. + const auto string_option = Reflection::Enum::to_string(option); + const auto all_values = options->values_for("output"); - // Both should be list options - if(!list_option) continue; - - // Check for same name of option. - if(candidate->short_name != display_option->short_name) continue; - - // Check that the video signal option is included. - return std::find(list_option->options.begin(), list_option->options.end(), display_list_option->options.front()) != list_option->options.end(); + return std::find(all_values.begin(), all_values.end(), string_option) != all_values.end(); } return NO; @@ -658,9 +647,9 @@ struct ActivityObserver: public Activity::Observer { @synchronized(self) { _useAutomaticTapeMotorControl = useAutomaticTapeMotorControl; - Configurable::SelectionSet selection_set; - append_automatic_tape_motor_control_selection(selection_set, useAutomaticTapeMotorControl ? true : false); - configurable_device->set_selections(selection_set); + auto options = configurable_device->get_options(); + Reflection::set(*options, "automatic_tape_motor_control", useAutomaticTapeMotorControl ? true : false); + configurable_device->set_options(options); } } @@ -671,9 +660,9 @@ struct ActivityObserver: public Activity::Observer { @synchronized(self) { _useQuickBootingHack = useQuickBootingHack; - Configurable::SelectionSet selection_set; - append_quick_boot_selection(selection_set, useQuickBootingHack ? true : false); - configurable_device->set_selections(selection_set); + auto options = configurable_device->get_options(); + Reflection::set(*options, "quickboot", useQuickBootingHack ? true : false); + configurable_device->set_options(options); } } diff --git a/Reflection/Enum.h b/Reflection/Enum.h index 95c808b2c..ede607246 100644 --- a/Reflection/Enum.h +++ b/Reflection/Enum.h @@ -122,7 +122,7 @@ class Enum { static const std::string &to_string(std::type_index type, int e) { const auto entry = members_by_type_.find(type); if(entry == members_by_type_.end()) return empty_string_; - return entry->second[e]; + return entry->second[size_t(e)]; } /*! diff --git a/Reflection/Struct.h b/Reflection/Struct.h index 7c5cba833..a1a2d99d4 100644 --- a/Reflection/Struct.h +++ b/Reflection/Struct.h @@ -219,10 +219,10 @@ template class StructImpl: public Struct { const int next = va_arg(list, int); if(next < 0) break; - if(permitted_values.size() <= next) { + if(permitted_values.size() <= size_t(next)) { permitted_values.resize(permitted_values.size() << 1); } - permitted_values[next] = true; + permitted_values[size_t(next)] = true; } va_end(list);