Back to index

texmacs  1.0.7.15
command.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : command.hpp
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 #ifndef COMMAND_H
00013 #define COMMAND_H
00014 #include "tree.hpp"
00015 struct object;
00016 
00017 extern int command_count;
00018 class command_rep: public abstract_struct {
00019 public:
00020   inline command_rep () { TM_DEBUG(command_count++); }
00021   inline virtual ~command_rep () { TM_DEBUG(command_count--); }
00022   inline virtual tm_ostream& print (tm_ostream& out);
00023   virtual void apply () = 0;
00024   virtual void apply (object args);
00025 };
00026 
00027 class command {
00028 public:
00029   ABSTRACT_NULL(command);
00030   command (void (*routine) (void));
00031   command (void (*_callback) (void*, void*), void *_obj, void *_info = NULL);
00032 
00033   inline void operator () (void);
00034   void operator () (object args);
00035   inline friend tm_ostream& operator << (tm_ostream& out, command cmd);
00036 };
00037 ABSTRACT_NULL_CODE(command);
00038 
00039 inline tm_ostream& command_rep::print (tm_ostream& out) { return out << "command"; }
00040 inline void command::operator () (void) { rep->apply(); }
00041 inline bool operator == (command cmd1, command cmd2) {
00042   return cmd1.rep == cmd2.rep; }
00043 inline tm_ostream& operator << (tm_ostream& out, command cmd) {
00044   if (is_nil(cmd)) return out << "(null)"; else return cmd->print(out); }
00045 
00046 #endif // defined COMMAND_H