Skip to content
Snippets Groups Projects
Commit 3a95c8ef authored by Matthew McGill's avatar Matthew McGill
Browse files

Refactoring

Former-commit-id: 12c1163de790ed7611be9642046bc122a4a50d06
parent 3480b045
Branches
Tags
No related merge requests found
...@@ -50,8 +50,11 @@ class IRDBObjects_t ...@@ -50,8 +50,11 @@ class IRDBObjects_t
// type aliases of maps. maps allow speed of finding needed files, file IRs // type aliases of maps. maps allow speed of finding needed files, file IRs
// and/or variants that have already been read from the DB // 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 IdToVariantMap_t = std::map<db_id_t, const std::shared_ptr<VariantID_t>>;
struct FileIRInfo_t
using FileIRInfo_t = std::pair<File_t *const, std::shared_ptr<FileIR_t>>; {
File_t *const file;
std::shared_ptr<FileIR_t> fileIR;
};
using IdToFileIRInfoMap_t = std::map<db_id_t, FileIRInfo_t>; using IdToFileIRInfoMap_t = std::map<db_id_t, FileIRInfo_t>;
IdToVariantMap_t variant_map; IdToVariantMap_t variant_map;
......
...@@ -28,21 +28,23 @@ shared_ptr<FileIR_t> IRDBObjects_t::addFileIR(db_id_t variant_id, db_id_t file_i ...@@ -28,21 +28,23 @@ shared_ptr<FileIR_t> IRDBObjects_t::addFileIR(db_id_t variant_id, db_id_t file_i
return null_fileIR; return null_fileIR;
} }
else 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(the_file != NULL);
assert(variant_map.find(variant_id) != variant_map.end()); assert(variant_map.find(variant_id) != variant_map.end());
VariantID_t& the_variant = *(variant_map.at(variant_id).get()); VariantID_t& the_variant = *(variant_map.at(variant_id).get());
it->second.second = make_shared<FileIR_t>(the_variant, the_file); the_fileIR = make_shared<FileIR_t>(the_variant, the_file);
assert(it->second.second != NULL); assert(the_fileIR != NULL);
} }
// make sure static variable is set in the calling module -- IMPORTANT // make sure static variable is set in the calling module -- IMPORTANT
(it->second.second)->SetArchitecture(); the_fileIR->SetArchitecture();
return it->second.second; return the_fileIR;
} }
} }
...@@ -53,15 +55,16 @@ int IRDBObjects_t::writeBackFileIR(db_id_t file_id) ...@@ -53,15 +55,16 @@ int IRDBObjects_t::writeBackFileIR(db_id_t file_id)
if(it != file_IR_map.end()) 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); assert(the_file != NULL);
try try
{ {
cout<<"Writing changes for "<<the_file->GetURL()<<endl; cout<<"Writing changes for "<<the_file->GetURL()<<endl;
// make sure static variable is set in the calling module -- IMPORTANT // make sure static variable is set in the calling module -- IMPORTANT
(it->second.second)->SetArchitecture(); shared_ptr<FileIR_t> & the_fileIR = (it->second).fileIR;
(it->second.second)->WriteToDB(); the_fileIR->SetArchitecture();
the_fileIR->WriteToDB();
} }
catch (DatabaseError_t pnide) catch (DatabaseError_t pnide)
{ {
...@@ -89,10 +92,11 @@ void IRDBObjects_t::deleteFileIR(db_id_t file_id) ...@@ -89,10 +92,11 @@ void IRDBObjects_t::deleteFileIR(db_id_t file_id)
if(it != file_IR_map.end()) 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); assert(the_fileIR.use_count() <= 2);
(it->second.second).reset(); the_fileIR.reset();
} }
} }
} }
...@@ -143,8 +147,8 @@ shared_ptr<VariantID_t> IRDBObjects_t::addVariant(db_id_t variant_id) ...@@ -143,8 +147,8 @@ shared_ptr<VariantID_t> IRDBObjects_t::addVariant(db_id_t variant_id)
File_t *const curr_file = *it; File_t *const curr_file = *it;
shared_ptr<FileIR_t> curr_file_IR; shared_ptr<FileIR_t> curr_file_IR;
auto file_IR_pair = make_pair(curr_file, curr_file_IR); FileIRInfo_t file_IR_info = {curr_file, curr_file_IR};
auto file_map_pair = make_pair((*it)->GetBaseID(), file_IR_pair); auto file_map_pair = make_pair((*it)->GetBaseID(), file_IR_info);
file_IR_map.insert(file_map_pair); file_IR_map.insert(file_map_pair);
} }
...@@ -161,8 +165,8 @@ bool IRDBObjects_t::filesBeingShared(const shared_ptr<VariantID_t>& the_variant) ...@@ -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()); 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()); const auto file_IR_info = file_IR_map.at((*file_it)->GetBaseID());
if(file_IR_pair.second.use_count() > 2) if(file_IR_info.fileIR.use_count() > 2)
{ {
return true; return true;
} }
...@@ -239,7 +243,7 @@ int IRDBObjects_t::writeBackAll(void) ...@@ -239,7 +243,7 @@ int IRDBObjects_t::writeBackAll(void)
++file_it ++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) if(result != 0)
{ {
ret_status = -1; ret_status = -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment