Merge pull request #12 from lioncash/const

General: Make member functions const where applicable
This commit is contained in:
Phillip Stephens 2019-09-03 00:37:32 -07:00 committed by GitHub
commit 35e5c7c90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 23 deletions

View File

@ -204,7 +204,7 @@ public:
* *
* @return Gets the name of the given file. * @return Gets the name of the given file.
*/ */
const char* getFilename(const FileHandle& fh); const char* getFilename(const FileHandle& fh) const;
/** /**
* @brief deleteFile * @brief deleteFile
@ -269,7 +269,7 @@ public:
* *
* @return The offset or -1 if an invalid handle is passed. * @return The offset or -1 if an invalid handle is passed.
*/ */
int32_t tell(const FileHandle& fh); int32_t tell(const FileHandle& fh) const;
/** /**
* @brief setPublic * @brief setPublic
@ -425,7 +425,7 @@ public:
* @param checksum The checksum of the system header. * @param checksum The checksum of the system header.
* @param inverse The inverse checksum of the system header. * @param inverse The inverse checksum of the system header.
*/ */
void getChecksum(uint16_t& checksum, uint16_t& inverse); void getChecksum(uint16_t& checksum, uint16_t& inverse) const;
/** /**
* @brief Retrieves the available storage and directory space. * @brief Retrieves the available storage and directory space.
@ -433,7 +433,7 @@ public:
* @param bytesNotUsed Number of free bytes out. * @param bytesNotUsed Number of free bytes out.
* @param filesNotUsed Number of free files out. * @param filesNotUsed Number of free files out.
*/ */
void getFreeBlocks(int32_t& bytesNotUsed, int32_t& filesNotUsed); void getFreeBlocks(int32_t& bytesNotUsed, int32_t& filesNotUsed) const;
/** /**
* @brief Formats the memory card and assigns a new serial. * @brief Formats the memory card and assigns a new serial.

View File

@ -39,6 +39,6 @@ public:
File* getFirstNonFreeFile(uint32_t start, const char* game, const char* maker); File* getFirstNonFreeFile(uint32_t start, const char* game, const char* maker);
File* getFile(const char* game, const char* maker, const char* filename); File* getFile(const char* game, const char* maker, const char* filename);
File* getFile(uint32_t idx); File* getFile(uint32_t idx);
int32_t indexForFile(File* f); int32_t indexForFile(const File* f) const;
}; };
} // namespace kabufuda } // namespace kabufuda

View File

@ -118,19 +118,23 @@ Card::Card(const char* game, const char* maker) {
Card::~Card() { close(); } Card::~Card() { close(); }
ECardResult Card::openFile(const char* filename, FileHandle& handleOut) { ECardResult Card::openFile(const char* filename, FileHandle& handleOut) {
ECardResult openRes = _pumpOpen(); const ECardResult openRes = _pumpOpen();
if (openRes != ECardResult::READY) if (openRes != ECardResult::READY) {
return openRes; return openRes;
}
handleOut = {}; handleOut = {};
File* f = m_dirs[m_currentDir].getFile(m_game, m_maker, filename); const File* const f = m_dirs[m_currentDir].getFile(m_game, m_maker, filename);
if (!f || f->m_game[0] == 0xFF) if (!f || f->m_game[0] == 0xFF) {
return ECardResult::NOFILE; return ECardResult::NOFILE;
int32_t idx = m_dirs[m_currentDir].indexForFile(f); }
const int32_t idx = m_dirs[m_currentDir].indexForFile(f);
if (idx != -1) { if (idx != -1) {
handleOut = FileHandle(idx); handleOut = FileHandle(idx);
return ECardResult::READY; return ECardResult::READY;
} }
return ECardResult::FATAL_ERROR; return ECardResult::FATAL_ERROR;
} }
@ -219,11 +223,13 @@ ECardResult Card::closeFile(FileHandle& fh) {
} }
FileHandle Card::firstFile() { FileHandle Card::firstFile() {
File* f = m_dirs[m_currentDir].getFirstNonFreeFile(0, m_game, m_maker); const File* const f = m_dirs[m_currentDir].getFirstNonFreeFile(0, m_game, m_maker);
if (f)
return FileHandle(m_dirs[m_currentDir].indexForFile(f));
return {}; if (f == nullptr) {
return {};
}
return FileHandle(m_dirs[m_currentDir].indexForFile(f));
} }
FileHandle Card::nextFile(const FileHandle& cur) { FileHandle Card::nextFile(const FileHandle& cur) {
@ -231,16 +237,22 @@ FileHandle Card::nextFile(const FileHandle& cur) {
NullFileAccess(); NullFileAccess();
return {}; return {};
} }
File* next = m_dirs[m_currentDir].getFirstNonFreeFile(cur.idx + 1, m_game, m_maker);
if (!next) const File* const next = m_dirs[m_currentDir].getFirstNonFreeFile(cur.idx + 1, m_game, m_maker);
if (next == nullptr) {
return {}; return {};
}
return FileHandle(m_dirs[m_currentDir].indexForFile(next)); return FileHandle(m_dirs[m_currentDir].indexForFile(next));
} }
const char* Card::getFilename(const FileHandle& fh) { const char* Card::getFilename(const FileHandle& fh) const {
File* f = _fileFromHandle(fh); const File* const f = _fileFromHandle(fh);
if (!f)
if (f == nullptr) {
return nullptr; return nullptr;
}
return f->m_filename; return f->m_filename;
} }
@ -445,7 +457,7 @@ void Card::seek(FileHandle& fh, int32_t pos, SeekOrigin whence) {
} }
} }
int32_t Card::tell(const FileHandle& fh) { return fh.offset; } int32_t Card::tell(const FileHandle& fh) const { return fh.offset; }
void Card::setPublic(const FileHandle& fh, bool pub) { void Card::setPublic(const FileHandle& fh, bool pub) {
File* file = _fileFromHandle(fh); File* file = _fileFromHandle(fh);
@ -746,12 +758,12 @@ void Card::getSerial(uint64_t& serial) {
m_ch._swapEndian(); m_ch._swapEndian();
} }
void Card::getChecksum(uint16_t& checksum, uint16_t& inverse) { void Card::getChecksum(uint16_t& checksum, uint16_t& inverse) const {
checksum = m_ch.m_checksum; checksum = m_ch.m_checksum;
inverse = m_ch.m_checksumInv; inverse = m_ch.m_checksumInv;
} }
void Card::getFreeBlocks(int32_t& bytesNotUsed, int32_t& filesNotUsed) { void Card::getFreeBlocks(int32_t& bytesNotUsed, int32_t& filesNotUsed) const {
bytesNotUsed = m_bats[m_currentBat].numFreeBlocks() * 0x2000; bytesNotUsed = m_bats[m_currentBat].numFreeBlocks() * 0x2000;
filesNotUsed = m_dirs[m_currentDir].numFreeFiles(); filesNotUsed = m_dirs[m_currentDir].numFreeFiles();
} }

View File

@ -125,7 +125,7 @@ File* Directory::getFile(uint32_t idx) {
return &data.m_files[idx]; return &data.m_files[idx];
} }
int32_t Directory::indexForFile(File* f) { int32_t Directory::indexForFile(const File* f) const {
if (f == nullptr) { if (f == nullptr) {
return -1; return -1;
} }