void Invocateur::lire(){ for(auto it = Commande::mapCommandes().cbegin(); it != Commande::mapCommandes().cend(); ++it){ listeCommande.push_back(it->first); } cout << "--- SIMULATEUR DE ROBOT ---" << endl << "Commande AIDE pour avoir la liste des commandes. Elles ne sont pas sensibles à la casse." << endl; while(true){ string rep; cout << "Entrer une commande :" << endl; cin >> rep; transform(rep.begin(), rep.end(),rep.begin(), ::toupper); if (!isCommande(rep)) { cout << "Commande inconnue. Veuillez réessayer." << endl; } else { Commande* com = Commande::nouvelleCommande(rep, this); try { com->executer(); } catch(EtatRobot::Bad_State){ cout << "Erreur: action impossible dans cet état !" << endl; if (com->reversible()){ Commande::pileCommandes().pop(); // pour enlever la mauvaise action de la pile } } } cin.clear(); cin.ignore(10000, '\n'); } }
void CommandeMacro::executer() { Commande* commande; while(!_macros.empty()) { commande = _macros.front(); _macros.pop_front(); commande->executer(); } }