Back to index

texmacs  1.0.7.15
command.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : command.cpp
00004 * DESCRIPTION: Abstract dynamic commands
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "command.hpp"
00013 #include "scheme.hpp"
00014 
00015 /******************************************************************************
00016 * default implementation of command application with arguments
00017 ******************************************************************************/
00018 
00019 void
00020 command_rep::apply (object args) {
00021   (void) args;
00022   apply ();
00023 }
00024 
00025 void
00026 command::operator () (object args) {
00027   rep->apply (args);
00028 }
00029 
00030 /******************************************************************************
00031 * standard commands without arguments
00032 ******************************************************************************/
00033 
00034 class std_command_rep: public command_rep {
00035   void (*routine) (void);
00036 public:
00037   std_command_rep (void (*routine) (void));
00038   void apply ();
00039 };
00040 
00041 std_command_rep::std_command_rep (void (*routine2) (void)):
00042   routine (routine2) {}
00043 void std_command_rep::apply () { routine (); }
00044 
00045 command::command (void (*routine) (void)) :
00046   rep (tm_new<std_command_rep> (routine)) { INC_COUNT(rep); }
00047 
00048 
00049 /******************************************************************************
00050 * callbacks
00051 ******************************************************************************/
00052 
00053 class generic_command_rep: public command_rep {
00054   void (*callback) (void*, void*); // callback
00055   void *obj; // argument for callback
00056   void *info; // additional info
00057   
00058 public:
00059   generic_command_rep (void (*_callback) (void*, void*), void *_obj, void *_info) 
00060     : callback (_callback), obj (_obj), info (_info) {}
00061   void apply () { if (callback) callback (obj, info); }
00062   tm_ostream& print (tm_ostream& out) { return out << "generic_command_rep"; }
00063 };
00064 
00065 command::command (void (*_callback) (void*, void*), void *_obj, void *_info) :
00066   rep (tm_new<generic_command_rep> (_callback, _obj, _info)) { INC_COUNT(rep); }
00067 
00068