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