Card: Make querying functions const member functions where applicable

These don't modify member state, so they can be made const .
This commit is contained in:
Lioncash 2019-09-02 08:23:38 -04:00
parent 66ce5ed823
commit ed2a6b3ce8
2 changed files with 13 additions and 10 deletions

View File

@ -204,7 +204,7 @@ public:
*
* @return Gets the name of the given file.
*/
const char* getFilename(const FileHandle& fh);
const char* getFilename(const FileHandle& fh) const;
/**
* @brief deleteFile
@ -269,7 +269,7 @@ public:
*
* @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
@ -425,7 +425,7 @@ public:
* @param checksum The 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.
@ -433,7 +433,7 @@ public:
* @param bytesNotUsed Number of free bytes 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.

View File

@ -246,10 +246,13 @@ FileHandle Card::nextFile(const FileHandle& cur) {
return FileHandle(m_dirs[m_currentDir].indexForFile(next));
}
const char* Card::getFilename(const FileHandle& fh) {
File* f = _fileFromHandle(fh);
if (!f)
const char* Card::getFilename(const FileHandle& fh) const {
const File* const f = _fileFromHandle(fh);
if (f == nullptr) {
return nullptr;
}
return f->m_filename;
}
@ -454,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) {
File* file = _fileFromHandle(fh);
@ -755,12 +758,12 @@ void Card::getSerial(uint64_t& serial) {
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;
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;
filesNotUsed = m_dirs[m_currentDir].numFreeFiles();
}