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
| #include <iostream>
#include <string>
#include <map>
using namespace std;
class Test
{
public:
void function1()
{
cout << "function1()" << endl;
};
void function2()
{
cout << "function2()" << endl;
};
private:
typedef void (Test::* TMembreFnc)();
typedef map<string,TMembreFnc> TMapFnc;
static TMapFnc CreateMap()
{
TMapFnc Result;
Result["function1"] = &function1;
Result["function2"] = &function2;
return Result;
}
static TMapFnc & GetMap()
{
static TMapFnc MapFnc = CreateMap();
return MapFnc;
}
public:
void Invoque ( const string & NomFunction)
{
TMapFnc & MapFnc = GetMap();
TMapFnc::iterator iter = MapFnc.find( NomFunction );
if( iter != MapFnc.end() )
{
(this->*(iter->second))();
}
};
}; |
Partager