mirror of https://github.com/AxioDL/kabufuda.git
Directory: Make indexForFile() a const member function
This doesn't modify instance state, so it can be turned into a const member function.
This commit is contained in:
parent
91a0a41cee
commit
66ce5ed823
|
@ -36,6 +36,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
|
||||||
|
|
|
@ -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,9 +237,12 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue