From 3a95c8efa973eec5d989449ca823e16844bbf286 Mon Sep 17 00:00:00 2001 From: Matthew McGill <mhollismcgill@gmail.com> Date: Mon, 5 Nov 2018 16:13:40 +0000 Subject: [PATCH] Refactoring Former-commit-id: 12c1163de790ed7611be9642046bc122a4a50d06 --- libIRDB/include/core/IRDB_Objects.hpp | 7 +++-- libIRDB/src/core/IRDB_Objects.cpp | 40 +++++++++++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/libIRDB/include/core/IRDB_Objects.hpp b/libIRDB/include/core/IRDB_Objects.hpp index c0caee3ca..96da68b33 100644 --- a/libIRDB/include/core/IRDB_Objects.hpp +++ b/libIRDB/include/core/IRDB_Objects.hpp @@ -50,8 +50,11 @@ class IRDBObjects_t // type aliases of maps. maps allow speed of finding needed files, file IRs // and/or variants that have already been read from the DB using IdToVariantMap_t = std::map<db_id_t, const std::shared_ptr<VariantID_t>>; - - using FileIRInfo_t = std::pair<File_t *const, std::shared_ptr<FileIR_t>>; + struct FileIRInfo_t + { + File_t *const file; + std::shared_ptr<FileIR_t> fileIR; + }; using IdToFileIRInfoMap_t = std::map<db_id_t, FileIRInfo_t>; IdToVariantMap_t variant_map; diff --git a/libIRDB/src/core/IRDB_Objects.cpp b/libIRDB/src/core/IRDB_Objects.cpp index 42ea86789..2d13be1ad 100644 --- a/libIRDB/src/core/IRDB_Objects.cpp +++ b/libIRDB/src/core/IRDB_Objects.cpp @@ -28,21 +28,23 @@ shared_ptr<FileIR_t> IRDBObjects_t::addFileIR(db_id_t variant_id, db_id_t file_i return null_fileIR; } else - { - if(it->second.second == NULL) + { + File_t *const & the_file = (it->second).file; + shared_ptr<FileIR_t> & the_fileIR = (it->second).fileIR; + + if(the_fileIR == NULL) { - File_t *const the_file = it->second.first; assert(the_file != NULL); assert(variant_map.find(variant_id) != variant_map.end()); VariantID_t& the_variant = *(variant_map.at(variant_id).get()); - it->second.second = make_shared<FileIR_t>(the_variant, the_file); - assert(it->second.second != NULL); + the_fileIR = make_shared<FileIR_t>(the_variant, the_file); + assert(the_fileIR != NULL); } // make sure static variable is set in the calling module -- IMPORTANT - (it->second.second)->SetArchitecture(); - return it->second.second; + the_fileIR->SetArchitecture(); + return the_fileIR; } } @@ -53,15 +55,16 @@ int IRDBObjects_t::writeBackFileIR(db_id_t file_id) if(it != file_IR_map.end()) { - File_t *const the_file = it->second.first; + File_t *const & the_file = (it->second).file; assert(the_file != NULL); try { cout<<"Writing changes for "<<the_file->GetURL()<<endl; // make sure static variable is set in the calling module -- IMPORTANT - (it->second.second)->SetArchitecture(); - (it->second.second)->WriteToDB(); + shared_ptr<FileIR_t> & the_fileIR = (it->second).fileIR; + the_fileIR->SetArchitecture(); + the_fileIR->WriteToDB(); } catch (DatabaseError_t pnide) { @@ -89,10 +92,11 @@ void IRDBObjects_t::deleteFileIR(db_id_t file_id) if(it != file_IR_map.end()) { - if(it->second.second != NULL) + shared_ptr<FileIR_t> & the_fileIR = (it->second).fileIR; + if(the_fileIR != NULL) { - assert(it->second.second.use_count() <= 2); - (it->second.second).reset(); + assert(the_fileIR.use_count() <= 2); + the_fileIR.reset(); } } } @@ -143,8 +147,8 @@ shared_ptr<VariantID_t> IRDBObjects_t::addVariant(db_id_t variant_id) File_t *const curr_file = *it; shared_ptr<FileIR_t> curr_file_IR; - auto file_IR_pair = make_pair(curr_file, curr_file_IR); - auto file_map_pair = make_pair((*it)->GetBaseID(), file_IR_pair); + FileIRInfo_t file_IR_info = {curr_file, curr_file_IR}; + auto file_map_pair = make_pair((*it)->GetBaseID(), file_IR_info); file_IR_map.insert(file_map_pair); } @@ -161,8 +165,8 @@ bool IRDBObjects_t::filesBeingShared(const shared_ptr<VariantID_t>& the_variant) ) { assert(file_IR_map.find((*file_it)->GetBaseID()) != file_IR_map.end()); - const pair<File_t*, shared_ptr<FileIR_t>> file_IR_pair = file_IR_map.at((*file_it)->GetBaseID()); - if(file_IR_pair.second.use_count() > 2) + const auto file_IR_info = file_IR_map.at((*file_it)->GetBaseID()); + if(file_IR_info.fileIR.use_count() > 2) { return true; } @@ -239,7 +243,7 @@ int IRDBObjects_t::writeBackAll(void) ++file_it ) { - const int result = IRDBObjects_t::writeBackFileIR((file_it->second.first)->GetBaseID()); + const int result = IRDBObjects_t::writeBackFileIR((file_it->second.file)->GetBaseID()); if(result != 0) { ret_status = -1; -- GitLab