Merge pull request #11 from lioncash/array

General: Use std::array for constructors where applicable
This commit is contained in:
Phillip Stephens 2019-09-03 00:36:32 -07:00 committed by GitHub
commit f74f1a3a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -15,9 +15,12 @@ class Directory {
uint16_t m_checksum; uint16_t m_checksum;
uint16_t m_checksumInv; uint16_t m_checksumInv;
}; };
using RawData = std::array<uint8_t, BlockSize>;
union { union {
Data data; Data data;
std::array<uint8_t, BlockSize> raw; RawData raw;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -27,7 +30,7 @@ class Directory {
public: public:
Directory(); Directory();
Directory(uint8_t data[BlockSize]); explicit Directory(const RawData& rawData);
~Directory() = default; ~Directory() = default;
bool hasFreeFile() const; bool hasFreeFile() const;

View File

@ -10,6 +10,8 @@ class File {
friend class Directory; friend class Directory;
friend class Card; friend class Card;
#pragma pack(push, 4) #pragma pack(push, 4)
using RawData = std::array<uint8_t, 0x40>;
union { union {
struct { struct {
std::array<uint8_t, 4> m_game; std::array<uint8_t, 4> m_game;
@ -28,7 +30,7 @@ class File {
uint16_t m_reserved2; uint16_t m_reserved2;
uint32_t m_commentAddr; uint32_t m_commentAddr;
}; };
std::array<uint8_t, 0x40> raw; RawData raw;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -36,8 +38,8 @@ class File {
public: public:
File(); File();
File(char data[0x40]); explicit File(const RawData& rawData);
File(const char* filename); explicit File(const char* filename);
~File() = default; ~File() = default;
}; };
} // namespace kabufuda } // namespace kabufuda

View File

@ -35,7 +35,7 @@ Directory::Directory() {
updateChecksum(); updateChecksum();
} }
Directory::Directory(uint8_t data[]) { std::memcpy(raw.data(), data, BlockSize); } Directory::Directory(const RawData& rawData) : raw{rawData} {}
bool Directory::hasFreeFile() const { bool Directory::hasFreeFile() const {
return std::any_of(data.m_files.cbegin(), data.m_files.cend(), return std::any_of(data.m_files.cbegin(), data.m_files.cend(),

View File

@ -8,7 +8,7 @@
namespace kabufuda { namespace kabufuda {
File::File() { raw.fill(0xFF); } File::File() { raw.fill(0xFF); }
File::File(char data[]) { std::memcpy(raw.data(), data, raw.size()); } File::File(const RawData& rawData) : raw{rawData} {}
File::File(const char* filename) { File::File(const char* filename) {
raw.fill(0); raw.fill(0);