2 virtual-methods.hh -- declare macros for our do-it-yourself RTTI
4 source file of the Flower Library
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #ifndef VIRTUAL_METHODS_HH
11 #define VIRTUAL_METHODS_HH
14 #include "stdlib.h" // size_t
16 /** Declare the classes name as a static and virtual function.
17 The static_name() can *not* be inlined (this might have the effect that
18 s->name() != S::static_name (). Overlapping strings need not be merged in C++
20 #define DECLARE_MY_RUNTIME_TYPEINFO \
21 virtual char const *name() const{ return static_name (); }\
22 static char const *static_name()
27 oops. before() has nothing to do with inheritance
29 inline bool operator > (type_info const &a1, type_info const &a2)
31 return a2.before (a1);
34 inline bool operator < (type_info const &a1, type_info const &a2)
36 return a1.before (a2);
39 inline bool operator <= (type_info const &a1, type_info const &a2)
41 return a1 == a2 || a1 < a2;
44 inline bool operator >= (type_info const &a1, type_info const &a2)
46 return a1 == a2 || a1 > a2;
50 #define IMPLEMENT_STATIC_NAME(c)\
51 char const *c::static_name() { return #c; }
54 size_t c::static_class_size () { return sizeof (c); }
57 #define VIRTUAL_COPY_CONS(T, R)\
58 virtual R *clone() const { return new T(*this); }
60 #define DECLARE_VIRTUAL_COPY_CONS(T, R)\
61 virtual R *clone() const
63 #define IMPLEMENT_VIRTUAL_COPY_CONS(T, R)\
64 R *T::clone() const { return new T(*this); }\
67 #define IMPLEMENT_IS_TYPE_B(D)\
68 IMPLEMENT_STATIC_NAME(D)
71 bool D::static_is_type_b (const char *s)\
73 return s == static_name();\
76 #define IMPLEMENT_IS_TYPE_B1(D, B)\
77 IMPLEMENT_STATIC_NAME(D)
79 bool D::static_is_type_b (const char *s)\
81 return s == static_name() || B::static_is_type_b (s);\
85 #define IMPLEMENT_IS_TYPE_B2(D, BA, BB)\
86 IMPLEMENT_STATIC_NAME(D)
90 bool D::static_is_type_b (const char *s)\
92 return s == static_name() || BA::static_is_type_b (s) || BB::static_is_type_b (s);\