Oh I'm sorry, I think I cut too much code :P
Code:
if(type & C_TRAVAIL_NOTE)
{
CMP_FUNC cmp_func = TrouveCmpFunc(str);
if(cmp_func != 0)
{
if(cmp_func == FONCTION_NULLE)
if(ComparePPE(trav_it->NoteObtenue, a + b) && ComparePGE(trav_it->NoteObtenue, a - b))
ls_resultat.back().Travaux.push_back(*trav_it);
else
if(cmp_func(trav_it->NoteObtenue, donnee))
ls_resultat.back().Travaux.push_back(*trav_it);
}
}
// ...
CoursMgr::CMP_FUNC CoursMgr::TrouveCmpFunc(const std::string& critere)
{
CMP_FUNC func = 0;
// On regarde si on a ">=x"
boost::regex e_pge("^>=\\b[0-9]{1,2}\\b$");
if(boost::regex_match(critere, e_pge))
func = ComparePGE;
// On regarde si on a "<=x"
boost::regex e_ppe("^<=\\b[0-9]{1,2}\\b$");
if(boost::regex_match(critere, e_ppe))
func = ComparePPE;
// On regarde si on a "x"
boost::regex e_exact("^\\b[0-9]{1,2}\\b$");
if(boost::regex_match(critere, e_exact))
func = CompareExact;
// On regarde si on a "x+-y"
boost::regex e_pm("^\\+-\\b[0-9]{1,2}\\b$");
if(boost::regex_match(critere, e_pm))
func = FONCTION_NULLE;
return func;
}
About the FONCTION_NULLE thing: It's a hack because if TrouveCmpFunction() returns 0, it means that no match was found. However, since the last case of the TrouveCmpFunction() is a special case(i.e. it contains 2 numbers instead of only 1) I cannot assign a function to func, I have to treat this case apart but I cannot return -1 because CMP_FUNC cannot be assigned the value -1 so I made an empty function called FONCTION_NULLE().