From c7cc895c69532ddb9390534feb4fa360ae38000e Mon Sep 17 00:00:00 2001 From: Jean-Philip Desjardins Date: Wed, 28 Dec 2016 11:23:32 -0500 Subject: [PATCH] Cleanup. --- Source/MIPSInstructionFactory.cpp | 6 -- Source/MIPSInstructionFactory.h | 15 ++--- Source/MIPSTags.cpp | 99 +++++++++++++------------------ Source/MIPSTags.h | 20 +++---- 4 files changed, 56 insertions(+), 84 deletions(-) diff --git a/Source/MIPSInstructionFactory.cpp b/Source/MIPSInstructionFactory.cpp index 62f011cc..5f3024c6 100644 --- a/Source/MIPSInstructionFactory.cpp +++ b/Source/MIPSInstructionFactory.cpp @@ -2,7 +2,6 @@ #include #include "MIPSInstructionFactory.h" #include "MIPS.h" -#include "PtrMacro.h" #include "offsetof_def.h" CMIPSInstructionFactory::CMIPSInstructionFactory(MIPS_REGSIZE nRegSize) @@ -15,11 +14,6 @@ CMIPSInstructionFactory::CMIPSInstructionFactory(MIPS_REGSIZE nRegSize) } -CMIPSInstructionFactory::~CMIPSInstructionFactory() -{ - -} - void CMIPSInstructionFactory::SetupQuickVariables(uint32 nAddress, CMipsJitter* codeGen, CMIPS* pCtx) { m_pCtx = pCtx; diff --git a/Source/MIPSInstructionFactory.h b/Source/MIPSInstructionFactory.h index 00c6a344..4036496f 100644 --- a/Source/MIPSInstructionFactory.h +++ b/Source/MIPSInstructionFactory.h @@ -1,5 +1,4 @@ -#ifndef _MIPSINSTRUCTIONFACTORY_H_ -#define _MIPSINSTRUCTIONFACTORY_H_ +#pragma once #include "Types.h" #include "MipsJitter.h" @@ -23,7 +22,7 @@ class CMIPSInstructionFactory { public: CMIPSInstructionFactory(MIPS_REGSIZE); - virtual ~CMIPSInstructionFactory(); + virtual ~CMIPSInstructionFactory() = default; virtual void CompileInstruction(uint32, CMipsJitter*, CMIPS*) = 0; protected: @@ -34,11 +33,9 @@ protected: void Illegal(); void SetupQuickVariables(uint32, CMipsJitter*, CMIPS*); - CMipsJitter* m_codeGen; - CMIPS* m_pCtx; - uint32 m_nOpcode; - uint32 m_nAddress; + CMipsJitter* m_codeGen; + CMIPS* m_pCtx; + uint32 m_nOpcode; + uint32 m_nAddress; MIPS_REGSIZE m_regSize; }; - -#endif diff --git a/Source/MIPSTags.cpp b/Source/MIPSTags.cpp index edbd9dec..ab42f6b4 100644 --- a/Source/MIPSTags.cpp +++ b/Source/MIPSTags.cpp @@ -1,5 +1,4 @@ #include "MIPSTags.h" -#include "PtrMacro.h" #include "StdStream.h" #include "lexical_cast_ex.h" #include "xml/FilteringNodeIterator.h" @@ -8,23 +7,10 @@ #define TAG_ELEMENT_ATTRIBUTE_ADDRESS ("address") #define TAG_ELEMENT_ATTRIBUTE_VALUE ("value") -using namespace Framework; -using namespace std; - -CMIPSTags::CMIPSTags() -{ - -} - -CMIPSTags::~CMIPSTags() -{ - RemoveTags(); -} - void CMIPSTags::InsertTag(uint32 nAddress, const char* sTag) { bool nErase = false; - if(sTag == NULL) + if(sTag == nullptr) { nErase = true; } @@ -35,46 +21,44 @@ void CMIPSTags::InsertTag(uint32 nAddress, const char* sTag) if(nErase) { - TagMap::iterator itTag(m_Tags.find(nAddress)); - - if(itTag != m_Tags.end()) + auto tagIterator = m_tags.find(nAddress); + if(tagIterator != m_tags.end()) { - m_Tags.erase(itTag); + m_tags.erase(tagIterator); } } else { - m_Tags[nAddress] = sTag; + m_tags[nAddress] = sTag; } } void CMIPSTags::RemoveTags() { - m_Tags.clear(); + m_tags.clear(); } -const char* CMIPSTags::Find(uint32 nAddress) +const char* CMIPSTags::Find(uint32 nAddress) const { - TagMap::const_iterator itTag(m_Tags.find(nAddress)); - return (itTag != m_Tags.end()) ? (itTag->second.c_str()) : (NULL); + auto tagIterator = m_tags.find(nAddress); + return (tagIterator != m_tags.end()) ? (tagIterator->second.c_str()) : nullptr; } -void CMIPSTags::Serialize(const char* sPath) +void CMIPSTags::Serialize(const char* sPath) const { - CStdStream Stream(fopen(sPath, "wb")); + Framework::CStdStream stream(fopen(sPath, "wb")); - Stream.Write32(static_cast(m_Tags.size())); + stream.Write32(static_cast(m_tags.size())); - for(TagMap::const_iterator itTag(m_Tags.begin()); - itTag != m_Tags.end(); itTag++) + for(const auto& tagPair : m_tags) { - const string& sTag = itTag->second; + const auto& sTag = tagPair.second; - uint8 nLength = static_cast(min(sTag.length(), 255)); + uint8 nLength = static_cast(std::min(sTag.length(), 255)); - Stream.Write32(itTag->first); - Stream.Write8(nLength); - Stream.Write(sTag.c_str(), nLength); + stream.Write32(tagPair.first); + stream.Write8(nLength); + stream.Write(sTag.c_str(), nLength); } } @@ -82,7 +66,7 @@ void CMIPSTags::Unserialize(const char* sPath) { try { - CStdStream Stream(fopen(sPath, "rb")); + Framework::CStdStream Stream(fopen(sPath, "rb")); RemoveTags(); uint32 nCount = Stream.Read32(); @@ -106,52 +90,51 @@ void CMIPSTags::Unserialize(const char* sPath) } } -void CMIPSTags::Serialize(Xml::CNode* parentNode, const char* sectionName) +void CMIPSTags::Serialize(Framework::Xml::CNode* parentNode, const char* sectionName) const { - Xml::CNode* section = new Xml::CNode(sectionName, true); - Serialize(section); - parentNode->InsertNode(section); + auto section = new Framework::Xml::CNode(sectionName, true); + Serialize(section); + parentNode->InsertNode(section); } -void CMIPSTags::Unserialize(Xml::CNode* parentNode, const char* sectionName) +void CMIPSTags::Unserialize(Framework::Xml::CNode* parentNode, const char* sectionName) { - Xml::CNode* section = parentNode->Select(sectionName); - if(!section) return; - Unserialize(section); + auto section = parentNode->Select(sectionName); + if(!section) return; + Unserialize(section); } -void CMIPSTags::Serialize(Xml::CNode* parentNode) +void CMIPSTags::Serialize(Framework::Xml::CNode* parentNode) const { - for(TagMap::const_iterator itTag(m_Tags.begin()); - itTag != m_Tags.end(); itTag++) + for(const auto& tagPair : m_tags) { - Xml::CNode* node = new Xml::CNode(TAG_ELEMENT_NAME, true); - node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, lexical_cast_hex(itTag->first, 8).c_str()); - node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE, itTag->second.c_str()); - parentNode->InsertNode(node); + auto node = new Framework::Xml::CNode(TAG_ELEMENT_NAME, true); + node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, lexical_cast_hex(tagPair.first, 8).c_str()); + node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE, tagPair.second.c_str()); + parentNode->InsertNode(node); } } -void CMIPSTags::Unserialize(Xml::CNode* parentNode) +void CMIPSTags::Unserialize(Framework::Xml::CNode* parentNode) { - for(Xml::CFilteringNodeIterator nodeIterator(parentNode, TAG_ELEMENT_NAME); + for(Framework::Xml::CFilteringNodeIterator nodeIterator(parentNode, TAG_ELEMENT_NAME); !nodeIterator.IsEnd(); nodeIterator++) { - Xml::CNode* node = *nodeIterator; - const char* addressText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS); - const char* valueText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE); + auto node = *nodeIterator; + auto addressText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS); + auto valueText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE); if(!addressText || !valueText) continue; - uint32 address = lexical_cast_hex(addressText); + uint32 address = lexical_cast_hex(addressText); InsertTag(address, valueText); } } CMIPSTags::TagIterator CMIPSTags::GetTagsBegin() const { - return m_Tags.begin(); + return m_tags.begin(); } CMIPSTags::TagIterator CMIPSTags::GetTagsEnd() const { - return m_Tags.end(); + return m_tags.end(); } diff --git a/Source/MIPSTags.h b/Source/MIPSTags.h index 4f2836b1..6d8f04bb 100644 --- a/Source/MIPSTags.h +++ b/Source/MIPSTags.h @@ -1,5 +1,4 @@ -#ifndef _MIPSTAGS_H_ -#define _MIPSTAGS_H_ +#pragma once #include "Types.h" #include "xml/Node.h" @@ -15,23 +14,22 @@ public: boost::signals2::signal OnTagListChange; - CMIPSTags(); - ~CMIPSTags(); void InsertTag(uint32, const char*); void RemoveTags(); - const char* Find(uint32); - void Serialize(Framework::Xml::CNode*, const char*); + const char* Find(uint32) const; + + void Serialize(Framework::Xml::CNode*, const char*) const; void Unserialize(Framework::Xml::CNode*, const char*); - void Serialize(Framework::Xml::CNode*); + + void Serialize(Framework::Xml::CNode*) const; void Unserialize(Framework::Xml::CNode*); - void Serialize(const char*); + + void Serialize(const char*) const; void Unserialize(const char*); TagIterator GetTagsBegin() const; TagIterator GetTagsEnd() const; private: - TagMap m_Tags; + TagMap m_tags; }; - -#endif