GCMemcardUtils: Make use of std::span where applicable
Generifies bits of the interface so that some functions aren't explicitly tied down to only using std::vector.
This commit is contained in:
parent
78f5c5f8d2
commit
1044bc40ca
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue