Merge pull request #557 from lioncash/data

cd_image: Make use of std::array where applicable
This commit is contained in:
Connor McLaughlin 2020-06-23 19:55:25 +10:00 committed by GitHub
commit c8082fcdf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 14 deletions

View file

@ -308,7 +308,7 @@ void CDImage::AddLeadOutIndex()
m_indices.push_back(index);
}
u16 CDImage::SubChannelQ::ComputeCRC(const u8* data)
u16 CDImage::SubChannelQ::ComputeCRC(const Data& data)
{
static constexpr std::array<u16, 256> crc16_table = {
{0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD,

View file

@ -1,6 +1,7 @@
#pragma once
#include "bitfield.h"
#include "types.h"
#include <array>
#include <memory>
#include <string>
#include <tuple>
@ -118,6 +119,8 @@ public:
union SubChannelQ
{
using Data = std::array<u8, SUBCHANNEL_BYTES_PER_FRAME>;
union Control
{
u8 bits;
@ -144,15 +147,15 @@ public:
u16 crc;
};
u8 data[SUBCHANNEL_BYTES_PER_FRAME];
Data data;
static u16 ComputeCRC(const u8* data);
static u16 ComputeCRC(const Data& data);
bool IsCRCValid() const;
SubChannelQ& operator=(const SubChannelQ& q)
{
std::copy(q.data, q.data + SUBCHANNEL_BYTES_PER_FRAME, data);
data = q.data;
return *this;
}
};

View file

@ -72,7 +72,7 @@ bool CDSubChannelReplacement::LoadSBI(const char* path)
std::copy_n(entry.data, countof(entry.data), subq_data.data());
// generate an invalid crc by flipping all bits from the valid crc (will never collide)
const u16 crc = CDImage::SubChannelQ::ComputeCRC(subq_data.data()) ^ 0xFFFF;
const u16 crc = CDImage::SubChannelQ::ComputeCRC(subq_data) ^ 0xFFFF;
subq_data[10] = Truncate8(crc);
subq_data[11] = Truncate8(crc >> 8);
@ -83,17 +83,18 @@ bool CDSubChannelReplacement::LoadSBI(const char* path)
return true;
}
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, u8* subq_data) const
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd,
ReplacementData& subq_data) const
{
return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq_data);
}
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, u8* subq_data) const
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const
{
ReplacementMap::const_iterator iter = m_replacement_subq.find(lba);
if (iter == m_replacement_subq.end())
const auto iter = m_replacement_subq.find(lba);
if (iter == m_replacement_subq.cend())
return false;
std::copy(iter->second.begin(), iter->second.end(), subq_data);
subq_data = iter->second;
return true;
}

View file

@ -13,6 +13,8 @@ public:
SUBCHANNEL_Q_SIZE = 12,
};
using ReplacementData = std::array<u8, SUBCHANNEL_Q_SIZE>;
CDSubChannelReplacement();
~CDSubChannelReplacement();
@ -21,14 +23,13 @@ public:
bool LoadSBI(const char* path);
/// Returns the replacement subchannel data for the specified position (in BCD).
bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, u8* subq_data) const;
bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, ReplacementData& subq_data) const;
/// Returns the replacement subchannel data for the specified sector.
bool GetReplacementSubChannelQ(u32 lba, u8* subq_data) const;
bool GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const;
private:
using ReplacementData = std::array<u8, SUBCHANNEL_Q_SIZE>;
using ReplacementMap = std::unordered_map<u32, ReplacementData>;
std::unordered_map<u32, ReplacementData> m_replacement_subq;
ReplacementMap m_replacement_subq;
};