Commit a08631db authored by Chen Bill's avatar Chen Bill Committed by GitHub

class DataManager: use const member function (#2592)

* update DataManager::GetData()

* class DataManager: use const member function
parent 36195fcc
......@@ -176,24 +176,12 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
spmemvfs_env_fini();
return false;
}
bool DataManager::GetData(unsigned int code, CardData* pData) {
code_pointer cdit = _datas.find(code);
bool DataManager::GetData(unsigned int code, CardData* pData) const {
auto cdit = _datas.find(code);
if(cdit == _datas.end())
return false;
auto& data = cdit->second;
if (pData) {
pData->code = data.code;
pData->alias = data.alias;
std::memcpy(pData->setcode, data.setcode, SIZE_SETCODE);
pData->type = data.type;
pData->level = data.level;
pData->attribute = data.attribute;
pData->race = data.race;
pData->attack = data.attack;
pData->defense = data.defense;
pData->lscale = data.lscale;
pData->rscale = data.rscale;
pData->link_marker = data.link_marker;
*pData = cdit->second;
}
return true;
}
......@@ -203,7 +191,7 @@ code_pointer DataManager::GetCodePointer(unsigned int code) const {
string_pointer DataManager::GetStringPointer(unsigned int code) const {
return _strings.find(code);
}
bool DataManager::GetString(unsigned int code, CardString* pStr) {
bool DataManager::GetString(unsigned int code, CardString* pStr) const {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
pStr->name = unknown_string;
......@@ -213,7 +201,7 @@ bool DataManager::GetString(unsigned int code, CardString* pStr) {
*pStr = csit->second;
return true;
}
const wchar_t* DataManager::GetName(unsigned int code) {
const wchar_t* DataManager::GetName(unsigned int code) const {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
......@@ -221,7 +209,7 @@ const wchar_t* DataManager::GetName(unsigned int code) {
return csit->second.name.c_str();
return unknown_string;
}
const wchar_t* DataManager::GetText(unsigned int code) {
const wchar_t* DataManager::GetText(unsigned int code) const {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
......@@ -229,7 +217,7 @@ const wchar_t* DataManager::GetText(unsigned int code) {
return csit->second.text.c_str();
return unknown_string;
}
const wchar_t* DataManager::GetDesc(unsigned int strCode) {
const wchar_t* DataManager::GetDesc(unsigned int strCode) const {
if (strCode < (MIN_CARD_ID << 4))
return GetSysString(strCode);
unsigned int code = (strCode >> 4) & 0x0fffffff;
......@@ -241,7 +229,7 @@ const wchar_t* DataManager::GetDesc(unsigned int strCode) {
return csit->second.desc[offset].c_str();
return unknown_string;
}
const wchar_t* DataManager::GetSysString(int code) {
const wchar_t* DataManager::GetSysString(int code) const {
if (code < 0 || code > MAX_STRING_ID)
return unknown_string;
auto csit = _sysStrings.find(code);
......@@ -249,25 +237,25 @@ const wchar_t* DataManager::GetSysString(int code) {
return unknown_string;
return csit->second.c_str();
}
const wchar_t* DataManager::GetVictoryString(int code) {
const wchar_t* DataManager::GetVictoryString(int code) const {
auto csit = _victoryStrings.find(code);
if(csit == _victoryStrings.end())
return unknown_string;
return csit->second.c_str();
}
const wchar_t* DataManager::GetCounterName(int code) {
const wchar_t* DataManager::GetCounterName(int code) const {
auto csit = _counterStrings.find(code);
if(csit == _counterStrings.end())
return unknown_string;
return csit->second.c_str();
}
const wchar_t* DataManager::GetSetName(int code) {
const wchar_t* DataManager::GetSetName(int code) const {
auto csit = _setnameStrings.find(code);
if(csit == _setnameStrings.end())
return NULL;
return nullptr;
return csit->second.c_str();
}
std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) {
std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) const {
std::vector<unsigned int> matchingCodes;
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info
......
......@@ -19,18 +19,18 @@ public:
bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(unsigned int code, CardData* pData);
bool GetData(unsigned int code, CardData* pData) const;
code_pointer GetCodePointer(unsigned int code) const;
string_pointer GetStringPointer(unsigned int code) const;
bool GetString(unsigned int code, CardString* pStr);
const wchar_t* GetName(unsigned int code);
const wchar_t* GetText(unsigned int code);
const wchar_t* GetDesc(unsigned int strCode);
const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code);
std::vector<unsigned int> GetSetCodes(std::wstring setname);
bool GetString(unsigned int code, CardString* pStr) const;
const wchar_t* GetName(unsigned int code) const;
const wchar_t* GetText(unsigned int code) const;
const wchar_t* GetDesc(unsigned int strCode) const;
const wchar_t* GetSysString(int code) const;
const wchar_t* GetVictoryString(int code) const;
const wchar_t* GetCounterName(int code) const;
const wchar_t* GetSetName(int code) const;
std::vector<unsigned int> GetSetCodes(std::wstring setname) const;
const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment