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
13 #include "stdlib.h" // size_t
15 /** Declare the classes name as a static and virtual function.
16 The static_name() can *not* be inlined (this might have the effect that
17 s->name() != S::static_name (). Overlapping strings need not be merged in C++
19 #define DECLARE_MY_RUNTIME_TYPEINFO \
20 static bool static_is_type_b (const char*s);\
21 virtual bool is_type_b (const char *s) const { return static_is_type_b (s); } \
22 virtual char const *name() const{ return static_name (); } \
23 virtual size_t class_size () const { return static_class_size (); }\
24 static size_t static_class_size (); \
25 static char const *static_name()
27 #define IMPLEMENT_STATIC_NAME(c)\
28 char const *c::static_name() { return #c; } \
29 size_t c::static_class_size () { return sizeof (c); }
33 #define VIRTUAL_COPY_CONS(T, R)\
34 virtual R *clone() const { return new T(*this); } \
35 int yet_another_stupid_function_to_allow_semicolon()
38 #define DECLARE_VIRTUAL_COPY_CONS(T,R)\
39 virtual R *clone() const
40 #define IMPLEMENT_VIRTUAL_COPY_CONS(T,R)\
41 R *T::clone() const { return new T(*this); } \
43 #define IMPLEMENT_IS_TYPE_B(D) \
44 IMPLEMENT_STATIC_NAME(D)\
45 bool D::static_is_type_b (const char *s) \
47 return s == static_name(); \
50 #define IMPLEMENT_IS_TYPE_B1(D,B) \
51 IMPLEMENT_STATIC_NAME(D)\
52 bool D::static_is_type_b (const char *s) \
54 return s == static_name() || B::static_is_type_b (s); \
56 #define IMPLEMENT_IS_TYPE_B2(D, BA, BB) \
57 IMPLEMENT_STATIC_NAME(D)\
58 bool D::static_is_type_b (const char *s) \
60 return s == static_name() || BA::static_is_type_b (s) || BB::static_is_type_b (s); \