SignatureDB: const correctness and cleanup

This commit is contained in:
Sepalani 2017-03-16 23:13:18 +00:00
parent a2cba6d72f
commit 2daf5cb86f
3 changed files with 14 additions and 14 deletions

View File

@ -18,7 +18,7 @@
#include "Core/PowerPC/SignatureDB/DSYSignatureDB.h" #include "Core/PowerPC/SignatureDB/DSYSignatureDB.h"
std::unique_ptr<SignatureDBFormatHandler> std::unique_ptr<SignatureDBFormatHandler>
SignatureDB::CreateFormatHandler(const std::string& file_path) SignatureDB::CreateFormatHandler(const std::string& file_path) const
{ {
if (StringEndsWith(file_path, ".csv")) if (StringEndsWith(file_path, ".csv"))
return std::make_unique<CSVSignatureDB>(); return std::make_unique<CSVSignatureDB>();
@ -31,7 +31,7 @@ bool SignatureDB::Load(const std::string& file_path)
return handler->Load(file_path, m_database); return handler->Load(file_path, m_database);
} }
bool SignatureDB::Save(const std::string& file_path) bool SignatureDB::Save(const std::string& file_path) const
{ {
auto handler = CreateFormatHandler(file_path); auto handler = CreateFormatHandler(file_path);
return handler->Save(file_path, m_database); return handler->Save(file_path, m_database);
@ -53,7 +53,7 @@ bool SignatureDB::Save(const std::string& file_path)
return hash; return hash;
}*/ }*/
void SignatureDB::List() void SignatureDB::List() const
{ {
for (const auto& entry : m_database) for (const auto& entry : m_database)
{ {
@ -68,7 +68,7 @@ void SignatureDB::Clear()
m_database.clear(); m_database.clear();
} }
void SignatureDB::Apply(PPCSymbolDB* symbol_db) void SignatureDB::Apply(PPCSymbolDB* symbol_db) const
{ {
for (const auto& entry : m_database) for (const auto& entry : m_database)
{ {
@ -92,13 +92,13 @@ void SignatureDB::Apply(PPCSymbolDB* symbol_db)
symbol_db->Index(); symbol_db->Index();
} }
void SignatureDB::Initialize(PPCSymbolDB* symbol_db, const std::string& prefix) void SignatureDB::Populate(const PPCSymbolDB* symbol_db, const std::string& filter)
{ {
for (const auto& symbol : symbol_db->Symbols()) for (const auto& symbol : symbol_db->Symbols())
{ {
if ((prefix.empty() && (!symbol.second.name.empty()) && if ((filter.empty() && (!symbol.second.name.empty()) &&
symbol.second.name.substr(0, 3) != "zz_" && symbol.second.name.substr(0, 1) != ".") || symbol.second.name.substr(0, 3) != "zz_" && symbol.second.name.substr(0, 1) != ".") ||
((!prefix.empty()) && symbol.second.name.substr(0, prefix.size()) == prefix)) ((!filter.empty()) && symbol.second.name.substr(0, filter.size()) == filter))
{ {
DBFunc temp_dbfunc; DBFunc temp_dbfunc;
temp_dbfunc.name = symbol.second.name; temp_dbfunc.name = symbol.second.name;

View File

@ -33,17 +33,17 @@ public:
// Does not clear. Remember to clear first if that's what you want. // Does not clear. Remember to clear first if that's what you want.
bool Load(const std::string& file_path); bool Load(const std::string& file_path);
bool Save(const std::string& file_path); bool Save(const std::string& file_path) const;
void List() const;
void Clear(); void Clear();
void List();
void Initialize(PPCSymbolDB* func_db, const std::string& prefix = ""); void Populate(const PPCSymbolDB* func_db, const std::string& filter = "");
void Apply(PPCSymbolDB* func_db); void Apply(PPCSymbolDB* func_db) const;
static u32 ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd); static u32 ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd);
private: private:
std::unique_ptr<SignatureDBFormatHandler> CreateFormatHandler(const std::string& file_path); std::unique_ptr<SignatureDBFormatHandler> CreateFormatHandler(const std::string& file_path) const;
// Map from signature to function. We store the DB in this map because it optimizes the // Map from signature to function. We store the DB in this map because it optimizes the
// most common operation - lookup. We don't care about ordering anyway. // most common operation - lookup. We don't care about ordering anyway.
FuncDB m_database; FuncDB m_database;

View File

@ -353,7 +353,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
if (!path.IsEmpty()) if (!path.IsEmpty())
{ {
SignatureDB db; SignatureDB db;
db.Initialize(&g_symbolDB, prefix); db.Populate(&g_symbolDB, prefix);
db.Save(WxStrToStr(path)); db.Save(WxStrToStr(path));
db.List(); db.List();
} }
@ -376,7 +376,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
if (!path.IsEmpty()) if (!path.IsEmpty())
{ {
SignatureDB db; SignatureDB db;
db.Initialize(&g_symbolDB, prefix); db.Populate(&g_symbolDB, prefix);
db.List(); db.List();
db.Load(WxStrToStr(path)); db.Load(WxStrToStr(path));
db.Save(WxStrToStr(path)); db.Save(WxStrToStr(path));