Back to index

texmacs  1.0.7.15
promise.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : promise.hpp
00004 * DESCRIPTION: promises
00005 * COPYRIGHT  : (C) 2007  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 PROMISE_H
00013 #define PROMISE_H
00014 #include "tree.hpp"
00015 
00016 class tree;
00017 template<class T> class promise_rep;
00018 template<class T> class promise;
00019 template<class T> tm_ostream& operator << (tm_ostream& out, promise<T> cmd);
00020 template<class T> bool is_nil (promise<T> l);
00021 
00022 template<class T>
00023 class promise_rep: public abstract_struct {
00024 public:
00025   inline promise_rep () {}
00026   inline virtual ~promise_rep () {}
00027   inline virtual tm_ostream& print (tm_ostream& out);
00028   virtual T eval () = 0;
00029 };
00030 
00031 template<class T>
00032 class promise {
00033 public:
00034 ABSTRACT_NULL_TEMPLATE(promise,T);
00035   inline T operator () ();
00036   friend tm_ostream& operator << LESSGTR (tm_ostream& out, promise<T> cmd);
00037 };
00038 ABSTRACT_NULL_TEMPLATE_CODE(promise,class,T);
00039 
00040 #define TMPL template<class T>
00041 TMPL inline tm_ostream& promise_rep<T>::print (tm_ostream& out) {
00042   return out << "promise"; }
00043 TMPL inline T promise<T>::operator () () {
00044   return rep->eval (); }
00045 TMPL inline bool operator == (promise<T> mw1, promise<T> mw2) {
00046   return mw1.rep == mw2.rep; }
00047 TMPL inline tm_ostream& operator << (tm_ostream& out, promise<T> cmd) {
00048   if (is_nil (cmd)) return out << "(null)"; else return cmd->print(out); }
00049 #undef TMPL
00050 
00051 #endif // defined PROMISE_H