- Voici le programme de test lié à cette classe.
-
- #include "interpret.hpp"
-
- #include<iostream>
- using namespace std;
-
- // Quelques fonctions libres et functor de traitement
- // (arguments passés en chaine de caractère)
- void f_traitement1( string const & args ) { cout << "Appel de T1 (" << args << ")" << endl; }
- void f_traitement2( string const & args ) { cout << "Appel de T2 (" << args << ")" << endl; }
- void f_traitement3( string const & args ) { cout << "Appel de T3 (" << args << ")" << endl; }
-
- struct f_traitement4 : t_functor {
- void operator()(std::string const & args) const { cout << "Appel de T4 (" << args << ")" << endl; }
- };
-
- struct f_traitement5 : t_functor {
- void operator()(std::string const & args) const { cout << "Appel de T5 (" << args << ")" << endl; }
- };
-
- struct f_traitement6 : t_functor {
- void operator()(std::string const & args) const { cout << "Appel de T6 (" << args << ")" << endl; }
- };
-
- // programme de test
- int main()
- {
- // Instanciation des functors
- f_traitement4 f_inst_traitement4;
- f_traitement5 f_inst_traitement5;
- f_traitement6 f_inst_traitement6;
-
- // Instanciation de l'interpreteur
- t_interpreteur it(' ','\n');
-
- // Initialisation de l'interpreteur
- it.lier( "t1", &f_traitement1 );
- it.lier( "t2", &f_traitement2 );
- it.lier( "t3", &f_traitement3 );
- it.lier( "t4", &f_inst_traitement4 );
- it.lier( "t5", &f_inst_traitement5 );
- it.lier( "t6", &f_inst_traitement6 );
- it.lier( "t1+4", &f_traitement1 );
- it.lier( "t1+4", &f_inst_traitement4 );
-
- // Serie de tests
-
- it( "" );
- // rien
-
- it( "t1\n" );
- // Appel de T1 ()
-
- it( "t2 a b c d\n" );
- // Appel de T2 (a b c d)
-
- it( "t1\nt2 a b c d\n" );
- // Appel de T1 ()
- // Appel de T2 (a b c d)
-
- it( "t1\nt2 a b c d\nt4\nt3 d f e\nt6\nt6\n" );
- // Appel de T1 ()
- // Appel de T2 (a b c d)
- // Appel de T4 ()
- // Appel de T3 (d f e)
- // Appel de T6 ()
- // Appel de T6 ()
-
- it( "t1+4 x y z\nt1\n" );
- // Appel de T1 (x y z)
- // Appel de T4 (x y z)
- // Appel de T1 ()
-
- // Cas d'erreur
- try
- {
- it( "t6\nt0\n" );
- }
- catch( t_interpreteur::ex_interpreteur & e )
- {
- cout << e.what() << " " << e.ligne_commande_erronee << endl;
- }
- // Appel de T6 ()
- // exception interpreteur : commande inconnue t0
-
- try
- {
- it( "t1" );
- }
- catch( t_interpreteur::ex_interpreteur & e )
- {
- cout << e.what() << " " << e.ligne_commande_erronee << endl;
- }
- // exception interpreteur : commande inconplete t1
-
- }
-
Voici le programme de test lié à cette classe.
#include "interpret.hpp"
#include<iostream>
using namespace std;
// Quelques fonctions libres et functor de traitement
// (arguments passés en chaine de caractère)
void f_traitement1( string const & args ) { cout << "Appel de T1 (" << args << ")" << endl; }
void f_traitement2( string const & args ) { cout << "Appel de T2 (" << args << ")" << endl; }
void f_traitement3( string const & args ) { cout << "Appel de T3 (" << args << ")" << endl; }
struct f_traitement4 : t_functor {
void operator()(std::string const & args) const { cout << "Appel de T4 (" << args << ")" << endl; }
};
struct f_traitement5 : t_functor {
void operator()(std::string const & args) const { cout << "Appel de T5 (" << args << ")" << endl; }
};
struct f_traitement6 : t_functor {
void operator()(std::string const & args) const { cout << "Appel de T6 (" << args << ")" << endl; }
};
// programme de test
int main()
{
// Instanciation des functors
f_traitement4 f_inst_traitement4;
f_traitement5 f_inst_traitement5;
f_traitement6 f_inst_traitement6;
// Instanciation de l'interpreteur
t_interpreteur it(' ','\n');
// Initialisation de l'interpreteur
it.lier( "t1", &f_traitement1 );
it.lier( "t2", &f_traitement2 );
it.lier( "t3", &f_traitement3 );
it.lier( "t4", &f_inst_traitement4 );
it.lier( "t5", &f_inst_traitement5 );
it.lier( "t6", &f_inst_traitement6 );
it.lier( "t1+4", &f_traitement1 );
it.lier( "t1+4", &f_inst_traitement4 );
// Serie de tests
it( "" );
// rien
it( "t1\n" );
// Appel de T1 ()
it( "t2 a b c d\n" );
// Appel de T2 (a b c d)
it( "t1\nt2 a b c d\n" );
// Appel de T1 ()
// Appel de T2 (a b c d)
it( "t1\nt2 a b c d\nt4\nt3 d f e\nt6\nt6\n" );
// Appel de T1 ()
// Appel de T2 (a b c d)
// Appel de T4 ()
// Appel de T3 (d f e)
// Appel de T6 ()
// Appel de T6 ()
it( "t1+4 x y z\nt1\n" );
// Appel de T1 (x y z)
// Appel de T4 (x y z)
// Appel de T1 ()
// Cas d'erreur
try
{
it( "t6\nt0\n" );
}
catch( t_interpreteur::ex_interpreteur & e )
{
cout << e.what() << " " << e.ligne_commande_erronee << endl;
}
// Appel de T6 ()
// exception interpreteur : commande inconnue t0
try
{
it( "t1" );
}
catch( t_interpreteur::ex_interpreteur & e )
{
cout << e.what() << " " << e.ligne_commande_erronee << endl;
}
// exception interpreteur : commande inconplete t1
}