]> www.ginac.de Git - cln.git/blob - include/cl_condition.h
ff17c89847505a0452d20fd01329bf3614e03fba
[cln.git] / include / cl_condition.h
1 // Conditions (a.k.a. exceptions)
2
3 #ifndef _CL_CONDITION_H
4 #define _CL_CONDITION_H
5
6 #include "cl_malloc.h"
7 #include "cl_io.h"
8
9 struct cl_condition {
10         // Allocation.
11         void* operator new (size_t size) { return cl_malloc_hook(size); }
12         // Deallocation.
13         void operator delete (void* ptr) { cl_free_hook(ptr); }
14         // Name.
15         virtual const char * name () const = 0;
16         // Print.
17         virtual void print (cl_ostream) const = 0;
18         // Virtual destructor.
19         virtual ~cl_condition ()
20         #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 8) // workaround gcc bug
21                 {}
22         #else
23                 = 0;
24         #endif
25 private:
26         virtual void dummy ();
27 };
28 #define SUBCLASS_cl_condition() \
29 public:                                                                   \
30         /* Allocation. */                                                 \
31         void* operator new (size_t size) { return cl_malloc_hook(size); } \
32         /* Deallocation. */                                               \
33         void operator delete (void* ptr) { cl_free_hook(ptr); }
34
35 // Functions which want to raise a condition return a `cl_condition*'.
36 // The caller checks this value. NULL means no condition. The one who
37 // disposes the condition (handles it without resignalling it) should
38 // call `delete' on the condition pointer.
39
40 #endif /* _CL_CONDITION_H */