Lolly 1.4.27
Loading...
Searching...
No Matches
promise.hpp
Go to the documentation of this file.
1
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 ******************************************************************************/
11
12#ifndef PROMISE_H
13#define PROMISE_H
14
15#include "basic.hpp"
16#include "tm_ostream.hpp"
17
18template <class T> class promise_rep;
19template <class T> class promise;
20template <class T> tm_ostream& operator<< (tm_ostream& out, promise<T> cmd);
21template <class T> bool is_nil (promise<T> l);
22
23template <class T> class promise_rep : public abstract_struct {
24public:
25 inline promise_rep () {}
26 inline virtual ~promise_rep () {}
27 inline virtual tm_ostream& print (tm_ostream& out);
28 virtual T eval ()= 0;
29};
30
31template <class T> class promise {
32public:
34 inline T operator() ();
35 friend tm_ostream& operator<< LESSGTR (tm_ostream& out, promise<T> cmd);
36};
38
39#define TMPL template <class T>
40TMPL inline tm_ostream&
42 return out << "promise";
43}
44TMPL inline T
46 return rep->eval ();
47}
48TMPL inline bool
50 return mw1.rep == mw2.rep;
51}
54 if (is_nil (cmd)) return out << "(null)";
55 else return cmd->print (out);
56}
57#undef TMPL
58
59#endif // defined PROMISE_H
#define LESSGTR
Macro used for template specialization of less than and greater than operators.
Definition basic.hpp:22
#define ABSTRACT_NULL_TEMPLATE_CODE(PTR, TT, T)
Macro for abstract null indirect structure template code definition.
Definition classdef.hpp:493
The list class represents a linked list.
Definition list.hpp:48
virtual T eval()=0
virtual ~promise_rep()
Definition promise.hpp:26
virtual tm_ostream & print(tm_ostream &out)
Definition promise.hpp:41
T operator()()
Definition promise.hpp:45
ABSTRACT_NULL_TEMPLATE(promise, T)
bool operator==(promise< T > mw1, promise< T > mw2)
Definition promise.hpp:49
bool is_nil(promise< T > l)
#define TMPL
Definition promise.hpp:39
tm_ostream & operator<<(tm_ostream &out, promise< T > cmd)
Definition promise.hpp:53
Structure representing an abstract object with a reference count.
Definition classdef.hpp:49
base class of resources
Definition resource.hpp:23