diff options
| author | Lioncash <mathew1800@gmail.com> | 2019-10-20 10:23:41 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2019-11-11 07:33:01 -0500 |
| commit | cfbabd4c4116ed042c8e0002ed480e3f4a3dade3 (patch) | |
| tree | 3c90c62d297130b10cd29ce7247d49d974959702 /Source/Core | |
| parent | febd1c3dbae4cdf56db7fb52aab06745fd16ba58 (diff) | |
SI_Device: Provide proper insertion/extraction operators for SIDevices enum
Allows the enumeration to be safely used with our type parsing
functions.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/ConfigManager.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Core/HW/SI/SI_Device.cpp | 25 | ||||
| -rw-r--r-- | Source/Core/Core/HW/SI/SI_Device.h | 4 |
3 files changed, 30 insertions, 1 deletions
diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 56a3003d0f..1915a7eb5f 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -500,7 +500,7 @@ void SConfig::LoadCoreSettings(IniFile& ini) core->Get("BBA_MAC", &m_bba_mac); for (size_t i = 0; i < std::size(m_SIDevice); ++i) { - core->Get(fmt::format("SIDevice{}", i), (u32*)&m_SIDevice[i], + core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i], (i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE); core->Get(fmt::format("AdapterRumble{}", i), &m_AdapterRumble[i], true); core->Get(fmt::format("SimulateKonga{}", i), &m_AdapterKonga[i], false); diff --git a/Source/Core/Core/HW/SI/SI_Device.cpp b/Source/Core/Core/HW/SI/SI_Device.cpp index e4637709bd..dfe74b4f0e 100644 --- a/Source/Core/Core/HW/SI/SI_Device.cpp +++ b/Source/Core/Core/HW/SI/SI_Device.cpp @@ -4,8 +4,11 @@ #include "Core/HW/SI/SI_Device.h" +#include <istream> #include <memory> +#include <ostream> #include <string> +#include <type_traits> #include <fmt/format.h> @@ -21,6 +24,28 @@ namespace SerialInterface { +std::ostream& operator<<(std::ostream& stream, SIDevices device) +{ + stream << static_cast<std::underlying_type_t<SIDevices>>(device); + return stream; +} + +std::istream& operator>>(std::istream& stream, SIDevices& device) +{ + std::underlying_type_t<SIDevices> value; + + if (stream >> value) + { + device = static_cast<SIDevices>(value); + } + else + { + device = SIDevices::SIDEVICE_NONE; + } + + return stream; +} + ISIDevice::ISIDevice(SIDevices device_type, int device_number) : m_device_number(device_number), m_device_type(device_type) { diff --git a/Source/Core/Core/HW/SI/SI_Device.h b/Source/Core/Core/HW/SI/SI_Device.h index c666f98805..b6418ec698 100644 --- a/Source/Core/Core/HW/SI/SI_Device.h +++ b/Source/Core/Core/HW/SI/SI_Device.h @@ -4,6 +4,7 @@ #pragma once +#include <iosfwd> #include <memory> #include "Common/CommonTypes.h" @@ -63,6 +64,9 @@ enum SIDevices : int SIDEVICE_COUNT, }; +std::ostream& operator<<(std::ostream& stream, SIDevices device); +std::istream& operator>>(std::istream& stream, SIDevices& device); + class ISIDevice { public: |
