2 /******************************************************************************
4 * DESCRIPTION: Abstract dynamic commands
5 * COPYRIGHT : (C) 1999 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
12 #include "command.hpp"
14 /******************************************************************************
15 * standard commands without arguments
16 ******************************************************************************/
18 class std_command_rep
: public command_rep
{
19 void (*routine
) (void);
21 std_command_rep (void (*routine
) (void));
25 std_command_rep::std_command_rep (void (*routine2
) (void)):
27 void std_command_rep::apply () { routine (); }
29 command::command (void (*routine
) (void)) :
30 rep (tm_new
<std_command_rep
> (routine
)) { INC_COUNT(rep
); }
33 class generic_command_rep
: public command_rep
{
34 void (*callback
) (void*, void*); // callback
35 void *obj
; // argument for callback
36 void *info
; // additional info
39 generic_command_rep (void (*_callback
) (void*, void*), void *_obj
, void *_info
)
40 : callback (_callback
), obj (_obj
), info (_info
) {}
41 void apply () { if (callback
) callback (obj
, info
); }
42 tm_ostream
& print (tm_ostream
& out
) { return out
<< "generic_command_rep"; }
45 command::command (void (*_callback
) (void*, void*), void *_obj
, void *_info
) :
46 rep (tm_new
<generic_command_rep
> (_callback
, _obj
, _info
)) { INC_COUNT(rep
); }