please teach me how to get rid of those if statements by using functors (or any other better methods) inside the following loop:
//Loop over each atom
std::string temp_name ;
float dst;
for (pdb::pdb_vector:: size_type i=0; i < data.size(); ++i)
{
if (type == 0)
{
//choose by residue name
temp_name = data[i].residue_name;
} else {
//choose by atom name
temp_name = data[i].atom_name;
}
//compare the name and extract position if matched
if (temp_name.compare(name) == 0)
{
if (direction.compare("x") == 0)
{
dst = ::atof(data[i].x_coord.c_str());
} else if ((direction.compare("y") == 0)) {
dst = ::atof(data[i].y_coord.c_str());
} else {
dst = ::atof(data[i].z_coord.c_str());
}
}
}
Aucun commentaire:
Enregistrer un commentaire