Skip to content

Commit

Permalink
Check if file exists while loading VCPU genome
Browse files Browse the repository at this point in the history
  • Loading branch information
FergusonAJ committed Jul 7, 2022
1 parent 399535c commit b4b2024
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion include/emp/hardware/VirtualCPU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,22 @@ namespace emp{
file.RemoveComments("//"); // Remove all C++ style comments
file.RemoveComments("#"); // Remove all bash/Python/R style comments
file.CompressWhitespace(); // Trim down remaining whitespace.
file.RemoveEmpty();
if(file.GetNumLines() == 0){
emp_error("Error! VirtualCPU trying to load a genome from an empty stream!");
}
file.Apply( [this](std::string & info){ PushInst(info); } );
nops_need_curated = true;
return true;
}
/// Load instructions from file
bool Load(const std::string & filename) {
std::ifstream is(filename);
return Load(is);
if(is.is_open()){
return Load(is);
}
emp_error("Error! VirtualCPU genome file is either empty or missing: ", filename);
return false;
}
/// Add a new instruction to the end of the genome, by index in the instruction library
void PushInst(size_t idx){
Expand Down

0 comments on commit b4b2024

Please sign in to comment.