1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <EventSystem/EventSystem.hpp>
#include <ctime>
using namespace std::placeholders;
class Exemple : public ES::Emittable<Exemple>
{
private :
std::map<int, std::string> Commentaires;
public :
void ShowCommentaire(std::clock_t deb, std::clock_t fin)
{
int sec=(fin-deb)/CLOCKS_PER_SEC;
auto it=Commentaires.find(sec);
if(it==Commentaires.end())
std::cout<<"\nVous etes lamentablement long a taper au clavier";
else
std::cout<<"\n"<<it->second;
}
Exemple() : Commentaires{std::make_pair(0,"Remarquable"),std::make_pair(1,"Remarquable"),std::make_pair(2,"Remarquable"),
std::make_pair(3,"Tres Bien"), std::make_pair(4,"Tres Bien"),std::make_pair(5,"Tres Bien"),
std::make_pair(6,"Bien"),std::make_pair(7,"Bien"),std::make_pair(8,"Bien"),
std::make_pair(9,"Moyen"),std::make_pair(10,"Moyen"),std::make_pair(11,"Moyen"),
std::make_pair(12,"Mauvais"),std::make_pair(13,"Mauvais"),std::make_pair(14,"Mauvais")}
{}
};
void ShowTime(std::clock_t deb, std::clock_t timefin)
{
std::cout<<"\nVous avez mis "<<static_cast<float>(timefin-deb)/CLOCKS_PER_SEC<<" secondes a taper votre chaine de caractere";
}
int main()
{
unsigned deb=clock();
std::string EstValide;
Exemple e;
e.Connect("Fini",ES::Event<std::clock_t>::MakeCallback(ShowTime, deb, _1));
e.Connect("Fini",ES::Event<std::clock_t>::MakeCallback(ES::MakeMember(e, &Exemple::ShowCommentaire), deb, _1));
do
{
std::cout<<"Ce programme vous affichera le temps mis a taper la chaine de caractere avec un systeme evenementiel. Veuillez taper \"Bonjour Bienvenu dans un nouveau monde.\".\n";
getline(std::cin, EstValide);
std::cout<<"\n\n";
std::cin.clear();
}while(EstValide!="Bonjour Bienvenu dans un nouveau monde.");
std::cout<<"\nOK Vous avez reussi a taper la chaine.";
e.Emit("Fini", ES::Event<std::clock_t>(clock()));
return 0;
} |