Exemple #1
0
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 CommandeEval::Do(){
    pile->pop();
    for (int i = 0; i < pCommande.size(); i++){
       Commande * c =  pCommande.at(i);
       c->Do();
    }
}
void CommandeEval::Undo(){
    for (int i =  pCommande.size()-1; i >=0 ; i--){
       Commande * c =  pCommande.at(i);
       c->Undo();
    }
    pile->push(expression);
}
Exemple #4
0
void* DISTRIBUTEUR(void* param)
{
	//Permettre l'arrêt du thread depuis un autre
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

	while(true)
	{
		pthread_mutex_lock(&mutex);
		//On attend que le thread VENDEUR donne le signal de la distribution de la bouteille
		pthread_cond_wait(&distribuer, &mutex);

		//On récupère le paramètre
		Commande* ach = (Commande*)param;

		system("CLS");
		cout << "Monnaie restante : " << ach->getSolde() << endl;
		//Si une bouteille a été achetée (c-à-d que le solde est suffisant et qu'il reste au moins 1 bouteille
		if(ach->getBouteille())
			cout << "Vous recevez 1 bouteille." << endl;
		else
			cout << "Vous ne recevez aucune bouteille." << endl;
		system("PAUSE");

		//On annonce au thread VENDEUR que l'action est terminée
		pthread_cond_signal(&vendeur);
		pthread_mutex_unlock(&mutex);
	}
	return NULL;
}
void CommandeMacro::executer() {
	Commande* commande;
	while(!_macros.empty())
	{
		commande = _macros.front();
		_macros.pop_front();
		commande->executer();
	}
}
void CommandeManager::redo()throw (LogMessage){
    if(!_listRedoableCommand->isEmpty()){
        Commande * cmd = _listRedoableCommand->pop();
        cmd->redo();
        _listUndoableCommand->push(cmd);
    }
    else
        throw LogMessage("redo(): Aucune commande a rétablir",1);
}
Exemple #7
0
void Pile::retablir(){
    if(posCommande !=0){ //== 0 pas de commande a retablir
        executionCommande = 1;//On empeche de nouvelle commande de s'enregistrer pendant l'execution d'une commande
        posCommande --;
        Commande * c = listeCommande.at(listeCommande.size()-1-posCommande);
        c->Do();
        executionCommande = 0;

    }
}
void CommandeManager::multiplication()throw(LogMessage){
    Commande * cmd = new CommandeMultiplication(_pile,_utilisateur);
    try{
        cmd->execute();
        _listUndoableCommand->push(cmd);
    }
    catch(LogMessage& msg){
        throw;
    }
}
void CommandeManager::drop()throw(LogMessage){
    Commande * cmd = new CommandeDrop(_pile);
    try{
        cmd->execute();
        _listUndoableCommand->push(cmd);
    }
    catch(LogMessage& msg){
        throw;
    }
}
void CommandeManager::mean(int fin)throw(LogMessage){
    Commande * cmd = new CommandeMean(_pile,_utilisateur,fin);
    try{
        cmd->execute();
        _listUndoableCommand->push(cmd);
    }
    catch(LogMessage& msg){
        throw;
    }
}
void CommandeManager::swap(int x, int y)throw(LogMessage){
    Commande * cmd = new CommandeSwap(_pile,x,y);
    try{
        cmd->execute();
        _listUndoableCommand->push(cmd);
    }
    catch(LogMessage& msg){
        throw;
    }
}
void CommandeManager::eval()throw(LogMessage){
    Commande * cmd = new CommandeEval(_pile,_utilisateur,this);
    try{
        cmd->execute();
        _listUndoableCommand->push(cmd);
    }
    catch(LogMessage& msg){
        throw;
    }
}
Exemple #13
0
void Pile::annuler()
{
    if(posCommande <=listeCommande.size()-1){//verification si commande a retablir
        executionCommande = 1;//On empeche de nouvelle commande de s'enregistrer pendant l'execution d'une commande
        Commande * c = listeCommande.at(listeCommande.size()-1-posCommande);
        c->Undo();
        posCommande ++;
        executionCommande = 0;
    }

}
Exemple #14
0
int main () {

	string entreeClavier;
	Commande *commande = new Commande();
	
	while(true) {
		getline(cin, entreeClavier);
		vector<string> requetes;
		requetes.push_back(entreeClavier);

		if(!commande->execute(requetes, false, false))
			break;
	}
	delete commande;
	return 0;
}
Exemple #15
0
int main()
{
	Robot r;
	string ligne;

	AfficheurText aft;
	r.attacherAfficheur(aft);

	cout << Console::getCommandes();

	while(1){
		string commandeString;
		cout << "Que faire ? : ";
		cin >> commandeString;

		Commande *com =  CommandeRobot::nouvelleCommandeRobot(commandeString, r);
		com->execute();
	}
}
	Commande::Commande(Commande &c)
	{
		p = c.getProduit();
		date = c.getDate();
	}