Skip to content

Commit

Permalink
Merge pull request #5466 from lioncash/db
Browse files Browse the repository at this point in the history
SignatureDB: Minor cleanup
  • Loading branch information
lioncash committed May 23, 2017
2 parents 4bfd464 + c3bab0b commit 3f43733
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
27 changes: 13 additions & 14 deletions Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp
Expand Up @@ -5,7 +5,6 @@
#include <string>

#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/PowerPC/PPCAnalyst.h"
Expand All @@ -18,15 +17,9 @@
#include "Core/PowerPC/SignatureDB/DSYSignatureDB.h"
#include "Core/PowerPC/SignatureDB/MEGASignatureDB.h"

SignatureDB::SignatureDB(SignatureDB::HandlerType handler) : m_handler(CreateFormatHandler(handler))
namespace
{
}

SignatureDB::SignatureDB(const std::string& file_path) : SignatureDB(GetHandlerType(file_path))
{
}

SignatureDB::HandlerType SignatureDB::GetHandlerType(const std::string& file_path)
SignatureDB::HandlerType GetHandlerType(const std::string& file_path)
{
if (StringEndsWith(file_path, ".csv"))
return SignatureDB::HandlerType::CSV;
Expand All @@ -35,8 +28,7 @@ SignatureDB::HandlerType SignatureDB::GetHandlerType(const std::string& file_pat
return SignatureDB::HandlerType::DSY;
}

std::unique_ptr<SignatureDBFormatHandler>
SignatureDB::CreateFormatHandler(SignatureDB::HandlerType handler) const
std::unique_ptr<SignatureDBFormatHandler> CreateFormatHandler(SignatureDB::HandlerType handler)
{
switch (handler)
{
Expand All @@ -49,6 +41,15 @@ SignatureDB::CreateFormatHandler(SignatureDB::HandlerType handler) const
return std::make_unique<MEGASignatureDB>();
}
}
} // Anonymous namespace

SignatureDB::SignatureDB(HandlerType handler) : m_handler(CreateFormatHandler(handler))
{
}

SignatureDB::SignatureDB(const std::string& file_path) : SignatureDB(GetHandlerType(file_path))
{
}

void SignatureDB::Clear()
{
Expand Down Expand Up @@ -217,6 +218,4 @@ u32 HashSignatureDB::ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd)
return sum;
}

SignatureDBFormatHandler::~SignatureDBFormatHandler()
{
}
SignatureDBFormatHandler::~SignatureDBFormatHandler() = default;
16 changes: 6 additions & 10 deletions Source/Core/Core/PowerPC/SignatureDB/SignatureDB.h
Expand Up @@ -27,8 +27,6 @@ class SignatureDB
explicit SignatureDB(HandlerType handler);
explicit SignatureDB(const std::string& file_path);

static HandlerType GetHandlerType(const std::string& file_path);

void Clear();
// Does not clear. Remember to clear first if that's what you want.
bool Load(const std::string& file_path);
Expand All @@ -41,7 +39,6 @@ class SignatureDB
bool Add(u32 start_addr, u32 size, const std::string& name);

private:
std::unique_ptr<SignatureDBFormatHandler> CreateFormatHandler(HandlerType handler) const;
std::unique_ptr<SignatureDBFormatHandler> m_handler;
};

Expand All @@ -66,23 +63,22 @@ class HashSignatureDB : public SignatureDBFormatHandler
public:
struct DBFunc
{
u32 size;
u32 size = 0;
std::string name;
std::string object_name;
std::string object_location;
DBFunc() : size(0) {}
};
using FuncDB = std::map<u32, DBFunc>;

static u32 ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd);

virtual void Clear() override;
virtual void List() const override;
void Clear() override;
void List() const override;

virtual void Populate(const PPCSymbolDB* func_db, const std::string& filter = "") override;
virtual void Apply(PPCSymbolDB* func_db) const override;
void Populate(const PPCSymbolDB* func_db, const std::string& filter = "") override;
void Apply(PPCSymbolDB* func_db) const override;

virtual bool Add(u32 startAddr, u32 size, const std::string& name) override;
bool Add(u32 startAddr, u32 size, const std::string& name) override;

protected:
// Map from signature to function. We store the DB in this map because it optimizes the
Expand Down

0 comments on commit 3f43733

Please sign in to comment.