Merge pull request #11909 from lioncash/spans
GCMemcardUtils: Make use of std::span where applicable
This commit is contained in:
commit
e3cae72c18
|
@ -75,7 +75,7 @@ bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasDuplicateIdentity(const std::vector<Savefile>& savefiles)
|
bool HasDuplicateIdentity(std::span<const Savefile> savefiles)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < savefiles.size(); ++i)
|
for (size_t i = 0; i < savefiles.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -338,7 +338,7 @@ std::string GetDefaultExtension(SavefileFormat format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Savefile> GetSavefiles(const GCMemcard& card, const std::vector<u8>& file_indices)
|
std::vector<Savefile> GetSavefiles(const GCMemcard& card, std::span<const u8> file_indices)
|
||||||
{
|
{
|
||||||
std::vector<Savefile> files;
|
std::vector<Savefile> files;
|
||||||
files.reserve(file_indices.size());
|
files.reserve(file_indices.size());
|
||||||
|
@ -352,7 +352,7 @@ std::vector<Savefile> GetSavefiles(const GCMemcard& card, const std::vector<u8>&
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetBlockCount(const std::vector<Savefile>& savefiles)
|
size_t GetBlockCount(std::span<const Savefile> savefiles)
|
||||||
{
|
{
|
||||||
size_t block_count = 0;
|
size_t block_count = 0;
|
||||||
for (const Savefile& savefile : savefiles)
|
for (const Savefile& savefile : savefiles)
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Core/HW/GCMemcard/GCMemcard.h"
|
#include "Core/HW/GCMemcard/GCMemcard.h"
|
||||||
|
|
||||||
|
@ -13,7 +16,7 @@ namespace Memcard
|
||||||
bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs);
|
bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs);
|
||||||
|
|
||||||
// Check if any two given savefiles have the same identity.
|
// Check if any two given savefiles have the same identity.
|
||||||
bool HasDuplicateIdentity(const std::vector<Savefile>& savefiles);
|
bool HasDuplicateIdentity(std::span<const Savefile> savefiles);
|
||||||
|
|
||||||
enum class ReadSavefileErrorCode
|
enum class ReadSavefileErrorCode
|
||||||
{
|
{
|
||||||
|
@ -43,8 +46,8 @@ std::string GenerateFilename(const DEntry& entry);
|
||||||
std::string GetDefaultExtension(SavefileFormat format);
|
std::string GetDefaultExtension(SavefileFormat format);
|
||||||
|
|
||||||
// Reads multiple savefiles from a card. Returns empty vector if even a single file can't be read.
|
// Reads multiple savefiles from a card. Returns empty vector if even a single file can't be read.
|
||||||
std::vector<Savefile> GetSavefiles(const GCMemcard& card, const std::vector<u8>& file_indices);
|
std::vector<Savefile> GetSavefiles(const GCMemcard& card, std::span<const u8> file_indices);
|
||||||
|
|
||||||
// Gets the total amount of blocks the given saves use.
|
// Gets the total amount of blocks the given saves use.
|
||||||
size_t GetBlockCount(const std::vector<Savefile>& savefiles);
|
size_t GetBlockCount(std::span<const Savefile> savefiles);
|
||||||
} // namespace Memcard
|
} // namespace Memcard
|
||||||
|
|
|
@ -502,7 +502,7 @@ void GCMemcardManager::ExportFiles(Memcard::SavefileFormat format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCMemcardManager::ImportFiles(Slot slot, const std::vector<Memcard::Savefile>& savefiles)
|
void GCMemcardManager::ImportFiles(Slot slot, std::span<const Memcard::Savefile> savefiles)
|
||||||
{
|
{
|
||||||
auto& card = m_slot_memcard[slot];
|
auto& card = m_slot_memcard[slot];
|
||||||
if (!card)
|
if (!card)
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <span>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
@ -62,7 +61,7 @@ private:
|
||||||
|
|
||||||
std::vector<u8> GetSelectedFileIndices();
|
std::vector<u8> GetSelectedFileIndices();
|
||||||
|
|
||||||
void ImportFiles(ExpansionInterface::Slot slot, const std::vector<Memcard::Savefile>& savefiles);
|
void ImportFiles(ExpansionInterface::Slot slot, std::span<const Memcard::Savefile> savefiles);
|
||||||
|
|
||||||
void CopyFiles();
|
void CopyFiles();
|
||||||
void ImportFile();
|
void ImportFile();
|
||||||
|
@ -89,16 +88,17 @@ private:
|
||||||
QPushButton* m_fix_checksums_button;
|
QPushButton* m_fix_checksums_button;
|
||||||
|
|
||||||
// Slots
|
// Slots
|
||||||
Common::EnumMap<std::map<u8, IconAnimationData>, ExpansionInterface::MAX_MEMCARD_SLOT>
|
template <typename T>
|
||||||
m_slot_active_icons;
|
using SlotEnumMap = Common::EnumMap<T, ExpansionInterface::MAX_MEMCARD_SLOT>;
|
||||||
Common::EnumMap<std::unique_ptr<Memcard::GCMemcard>, ExpansionInterface::MAX_MEMCARD_SLOT>
|
|
||||||
m_slot_memcard;
|
SlotEnumMap<std::map<u8, IconAnimationData>> m_slot_active_icons;
|
||||||
Common::EnumMap<QGroupBox*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_group;
|
SlotEnumMap<std::unique_ptr<Memcard::GCMemcard>> m_slot_memcard;
|
||||||
Common::EnumMap<QLineEdit*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_file_edit;
|
SlotEnumMap<QGroupBox*> m_slot_group;
|
||||||
Common::EnumMap<QPushButton*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_open_button;
|
SlotEnumMap<QLineEdit*> m_slot_file_edit;
|
||||||
Common::EnumMap<QPushButton*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_create_button;
|
SlotEnumMap<QPushButton*> m_slot_open_button;
|
||||||
Common::EnumMap<QTableWidget*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_table;
|
SlotEnumMap<QPushButton*> m_slot_create_button;
|
||||||
Common::EnumMap<QLabel*, ExpansionInterface::MAX_MEMCARD_SLOT> m_slot_stat_label;
|
SlotEnumMap<QTableWidget*> m_slot_table;
|
||||||
|
SlotEnumMap<QLabel*> m_slot_stat_label;
|
||||||
|
|
||||||
ExpansionInterface::Slot m_active_slot;
|
ExpansionInterface::Slot m_active_slot;
|
||||||
u64 m_current_frame = 0;
|
u64 m_current_frame = 0;
|
||||||
|
|
Loading…
Reference in New Issue