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
|
typedef boost::function<void (long, std::string)> m_function;
class Control
{
map<int,m_function> m_mappage; // int est un code qui correspond a une méthode
public:
inline void add_command(int c, m_function function)
{
m_mappage[c] = function;
}
inline m_function get_command (int c)
{
return m_mappage[c];
}
};
class Service
{
public:
void affiche (int a, std::string b)
{
std::cout << a << " " << b << std::endl;
}
};
void blabla(long c, std::string bla)
{
std::cout << c << " " << bla << std::endl;
}
int main()
{
Control c;
Service b;
c.add_command(1,boost::bind(&Service::affiche,boost::ref(b),_1,_2));
c.add_command(2,boost::bind(&blabla,_1,_2));
c.get_command (1)(12, "blabla");
c.get_command (2)(25, "reblabla");
} |
Partager