Systematic use of tm_ostream class instead of ostream (removing dependency on std)
[texmacs.git] / src / src / Kernel / Containers / promise.hpp
blobe040fc9679b27af00497fb432895177db99c4337
2 /******************************************************************************
3 * MODULE : promise.hpp
4 * DESCRIPTION: promises
5 * COPYRIGHT : (C) 2007 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 #ifndef PROMISE_H
13 #define PROMISE_H
14 #include "tree.hpp"
16 class tree;
17 template<class T> class promise_rep;
18 template<class T> class promise;
19 template<class T> tm_ostream& operator << (tm_ostream& out, promise<T> cmd);
20 template<class T> bool is_nil (promise<T> l);
22 template<class T>
23 class promise_rep: public abstract_struct {
24 public:
25 inline promise_rep () {}
26 inline virtual ~promise_rep () {}
27 inline virtual tm_ostream& print (tm_ostream& out);
28 virtual T eval () = 0;
31 template<class T>
32 class promise {
33 public:
34 ABSTRACT_NULL_TEMPLATE(promise,T);
35 inline T operator () ();
36 friend tm_ostream& operator << LESSGTR (tm_ostream& out, promise<T> cmd);
38 ABSTRACT_NULL_TEMPLATE_CODE(promise,class,T);
40 #define TMPL template<class T>
41 TMPL inline tm_ostream& promise_rep<T>::print (tm_ostream& out) {
42 return out << "promise"; }
43 TMPL inline T promise<T>::operator () () {
44 return rep->eval (); }
45 TMPL inline bool operator == (promise<T> mw1, promise<T> mw2) {
46 return mw1.rep == mw2.rep; }
47 TMPL inline tm_ostream& operator << (tm_ostream& out, promise<T> cmd) {
48 if (is_nil (cmd)) return out << "(null)"; else return cmd->print(out); }
49 #undef TMPL
51 #endif // defined PROMISE_H