diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2021-05-08 12:27:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-08 12:27:38 -0400 |
| commit | a357277e412b5e8f0f2f0578c7d7d213e8744c8d (patch) | |
| tree | 353e7aa38aef392c6f337d6a1a04d3438f00def5 /ZAPD/ZFile.cpp | |
| parent | 547c9b200d1dff745dee694c20a9f9e8e409a11d (diff) | |
Add const to most functions that need it and remove all "using namespace std" (#132)
* started on basic type errors
* Done. For now
* remove libgfxd binary
* const
* no more namespace std
* revert alloca
* re add a few missing consts
Diffstat (limited to 'ZAPD/ZFile.cpp')
| -rw-r--r-- | ZAPD/ZFile.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index bfb76eb..ac56606 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -26,21 +26,20 @@ #include "ZVtx.h" using namespace tinyxml2; -using namespace std; ZFile::ZFile() { - resources = vector<ZResource*>(); + resources = std::vector<ZResource*>(); basePath = ""; outputPath = Directory::GetCurrentDirectory(); - declarations = map<uint32_t, Declaration*>(); + declarations = std::map<uint32_t, Declaration*>(); defines = ""; baseAddress = 0; rangeStart = 0x000000000; rangeEnd = 0xFFFFFFFF; } -ZFile::ZFile(const fs::path& nOutPath, string nName) : ZFile() +ZFile::ZFile(const fs::path& nOutPath, std::string nName) : ZFile() { outputPath = nOutPath; name = nName; @@ -91,11 +90,11 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b const char* gameStr = reader->Attribute("Game"); if (reader->Attribute("Game") != nullptr) { - if (string(gameStr) == "MM") + if (std::string(gameStr) == "MM") Globals::Instance->game = ZGame::MM_RETAIL; - else if (string(gameStr) == "SW97" || string(gameStr) == "OOTSW97") + else if (std::string(gameStr) == "SW97" || std::string(gameStr) == "OOTSW97") Globals::Instance->game = ZGame::OOT_SW97; - else if (string(gameStr) == "OOT") + else if (std::string(gameStr) == "OOT") Globals::Instance->game = ZGame::OOT_RETAIL; else throw std::runtime_error( @@ -126,7 +125,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b Globals::Instance->AddSegment(segment, this); } - string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string(); + std::string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string(); if (mode == ZFileMode::Extract) { @@ -188,7 +187,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b nameSet.insert(nameXml); } - string nodeName = string(child->Name()); + std::string nodeName = std::string(child->Name()); if (nodeMap.find(nodeName) != nodeMap.end()) { @@ -206,7 +205,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b rawDataIndex += nRes->GetRawDataSize(); } - else if (string(child->Name()) == "File") + else if (std::string(child->Name()) == "File") { throw std::runtime_error(StringHelper::Sprintf( "ZFile::ParseXML: Error in '%s'.\n\t Can't declare a File inside a File.\n", @@ -232,7 +231,7 @@ void ZFile::DeclareResourceSubReferences() void ZFile::BuildSourceFile(fs::path outputDir) { - string folderName = Path::GetFileNameWithoutExtension(outputPath.string()); + std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string()); if (!Directory::Exists(outputPath.string())) Directory::CreateDirectory(outputPath.string()); @@ -242,7 +241,7 @@ void ZFile::BuildSourceFile(fs::path outputDir) std::string ZFile::GetVarName(uint32_t address) { - for (pair<uint32_t, Declaration*> pair : declarations) + for (std::pair<uint32_t, Declaration*> pair : declarations) { if (pair.first == address) return pair.second->varName; @@ -251,7 +250,7 @@ std::string ZFile::GetVarName(uint32_t address) return ""; } -std::string ZFile::GetName() +std::string ZFile::GetName() const { return name; } @@ -268,7 +267,7 @@ const std::vector<uint8_t>& ZFile::GetRawData() const void ZFile::ExtractResources(fs::path outputDir) { - string folderName = Path::GetFileNameWithoutExtension(outputPath.string()); + std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string()); if (!Directory::Exists(outputPath.string())) Directory::CreateDirectory(outputPath.string()); @@ -334,8 +333,8 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm } Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, size_t size, string varType, - string varName, std::string body) + DeclarationPadding padding, size_t size, std::string varType, + std::string varName, std::string body) { AddDeclarationDebugChecks(address); @@ -378,8 +377,9 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a } Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, size_t size, string varType, - string varName, size_t arrayItemCnt, std::string body) + DeclarationPadding padding, size_t size, + std::string varType, std::string varName, + size_t arrayItemCnt, std::string body) { AddDeclarationDebugChecks(address); @@ -398,7 +398,7 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address) return declarations[address]; } -Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName) +Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, std::string varName) { AddDeclarationDebugChecks(address); @@ -409,8 +409,8 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName) return declarations[address]; } -Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, size_t size, - string varType, string varName) +Declaration* ZFile::AddDeclarationInclude(uint32_t address, std::string includePath, size_t size, + std::string varType, std::string varName) { AddDeclarationDebugChecks(address); @@ -547,15 +547,15 @@ void ZFile::GenerateSourceFiles(fs::path outputDir) for (size_t i = 0; i < resources.size(); i++) { ZResource* res = resources.at(i); - string resSrc = res->GetSourceOutputCode(name); + std::string resSrc = res->GetSourceOutputCode(name); if (res->IsExternalResource()) { - string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str(); + std::string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str(); - string assetOutDir = + std::string assetOutDir = (outputDir / Path::GetFileNameWithoutExtension(res->GetOutName())).string(); - string declType = res->GetSourceTypeName(); + std::string declType = res->GetSourceTypeName(); std::string incStr = StringHelper::Sprintf("%s.%s.inc", assetOutDir.c_str(), res->GetExternalExtension().c_str()); @@ -600,7 +600,7 @@ void ZFile::GenerateSourceFiles(fs::path outputDir) sourceOutput += ProcessDeclarations(); - string outPath = + std::string outPath = (Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c")) .string(); @@ -618,7 +618,7 @@ void ZFile::GenerateSourceHeaderFiles() for (ZResource* res : resources) { - string resSrc = res->GetSourceOutputHeader(""); + std::string resSrc = res->GetSourceOutputHeader(""); formatter.Write(resSrc); if (resSrc != "") @@ -695,9 +695,9 @@ void ZFile::RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc) (*nodeMap)[nodeName] = nodeFunc; } -string ZFile::ProcessDeclarations() +std::string ZFile::ProcessDeclarations() { - string output = ""; + std::string output = ""; if (declarations.size() == 0) return output; @@ -711,14 +711,14 @@ string ZFile::ProcessDeclarations() // printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd); // Optimization: See if there are any arrays side by side that can be merged... - std::vector<pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), - declarations.end()); + std::vector<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), + declarations.end()); - pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); + std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); for (size_t i = 1; i < declarationKeys.size(); i++) { - pair<int32_t, Declaration*> curItem = declarationKeys[i]; + std::pair<int32_t, Declaration*> curItem = declarationKeys[i]; if (curItem.second->isArray && lastItem.second->isArray) { @@ -747,10 +747,10 @@ string ZFile::ProcessDeclarations() lastItem = curItem; } - for (pair<uint32_t, Declaration*> item : declarations) + for (std::pair<uint32_t, Declaration*> item : declarations) ProcessDeclarationText(item.second); - for (pair<uint32_t, Declaration*> item : declarations) + for (std::pair<uint32_t, Declaration*> item : declarations) { while (item.second->size % 4 != 0) item.second->size++; @@ -875,7 +875,7 @@ string ZFile::ProcessDeclarations() int diff = currentAddress - unaccountedAddress; bool nonZeroUnaccounted = false; - string src = " "; + std::string src = " "; for (int i = 0; i < diff; i++) { @@ -937,7 +937,7 @@ string ZFile::ProcessDeclarations() // Go through include declarations // First, handle the prototypes (static only for now) int32_t protoCnt = 0; - for (pair<uint32_t, Declaration*> item : declarations) + for (std::pair<uint32_t, Declaration*> item : declarations) { if (StringHelper::StartsWith(item.second->varType, "static ") && !item.second->isUnaccounted) @@ -974,7 +974,7 @@ string ZFile::ProcessDeclarations() output += "\n"; // Next, output the actual declarations - for (pair<uint32_t, Declaration*> item : declarations) + for (std::pair<uint32_t, Declaration*> item : declarations) { if (item.first < rangeStart || item.first >= rangeEnd) { @@ -1161,11 +1161,11 @@ void ZFile::ProcessDeclarationText(Declaration* decl) } } -string ZFile::ProcessExterns() +std::string ZFile::ProcessExterns() { - string output = ""; + std::string output = ""; - for (pair<uint32_t, Declaration*> item : declarations) + for (std::pair<uint32_t, Declaration*> item : declarations) { if (item.first < rangeStart || item.first >= rangeEnd) { @@ -1205,8 +1205,8 @@ std::string ZFile::ProcessTextureIntersections(std::string prefix) return ""; std::string defines = ""; - vector<pair<uint32_t, ZTexture*>> texturesSorted(texturesResources.begin(), - texturesResources.end()); + std::vector<std::pair<uint32_t, ZTexture*>> texturesSorted(texturesResources.begin(), + texturesResources.end()); for (size_t i = 0; i < texturesSorted.size() - 1; i++) { |
