Skip to content
Permalink
Browse files

SI_Device: Provide proper insertion/extraction operators for SIDevice…

…s enum

Allows the enumeration to be safely used with our type parsing
functions.
  • Loading branch information
lioncash committed Oct 20, 2019
1 parent febd1c3 commit cfbabd4c4116ed042c8e0002ed480e3f4a3dade3
Showing with 30 additions and 1 deletion.
  1. +1 −1 Source/Core/Core/ConfigManager.cpp
  2. +25 −0 Source/Core/Core/HW/SI/SI_Device.cpp
  3. +4 −0 Source/Core/Core/HW/SI/SI_Device.h
@@ -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);
@@ -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)
{
@@ -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:

0 comments on commit cfbabd4

Please sign in to comment.
You can’t perform that action at this time.