SI_Device: Provide proper insertion/extraction operators for SIDevices enum

Allows the enumeration to be safely used with our type parsing
functions.
This commit is contained in:
Lioncash 2019-10-20 10:23:41 -04:00
parent febd1c3dba
commit cfbabd4c41
3 changed files with 30 additions and 1 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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: