/*************************************************************************** * Copyright (C) 2007 by Miguel Tadeu * * mtadeunet@fusemail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include using namespace std; // // Some macros to make things easier to use // #define BIND_TO_VECTOR( type, position ) boost::bind( extractor_any(), _1 ) #define BIND_EVENT0(event) boost::bind( &event, this ) #define BIND_EVENT1(event, type1) boost::bind( &event, this, BIND_TO_VECTOR( type1, 0 ) ) #define BIND_EVENT2(event, type1, type2) boost::bind( &event, this, BIND_TO_VECTOR( type1, 0 ), BIND_TO_VECTOR( type2, 1 ) ) #define BIND_EVENT3(event, type1, type2, type3) boost::bind( &event, this, BIND_TO_VECTOR( type1, 0 ), BIND_TO_VECTOR( type2, 1 ), BIND_TO_VECTOR( type3, 2 ) ) #define BIND_EVENT4(event, type1, type2, type3, type4) boost::bind( &event, this, BIND_TO_VECTOR( type1, 0 ), BIND_TO_VECTOR( type2, 1 ), BIND_TO_VECTOR( type3, 2 ), BIND_TO_VECTOR( type4, 3 ) ) typedef boost::function< boost::any ( const vector & ) > call_type_regular; typedef boost::function< void ( const vector & ) > call_type_no_return; struct call_wraper { virtual boost::any call( const vector & ) { return boost::any(); } }; class call_regular : public call_wraper { call_type_regular m_function; public: call_regular( const call_type_regular &function ) : m_function( function ) { } boost::any call( const vector &vect ) { return m_function( vect ); } }; struct call_no_return : public call_wraper { call_type_no_return m_function; public: call_no_return( const call_type_no_return &function ) : m_function( function ) { } boost::any call( const vector &vect ) { m_function( vect ); return boost::any(); } }; template _Result *create_call_wraper( const _BoundType &bind_function ) { return new _Result( bind_function ); } template struct extractor_any : public unary_function< vector, _Result > { _Result operator () ( const vector &vect ) { return boost::any_cast<_Result>( vect[ index ] ); } };