2 virtual-methods.hh -- declare macros for our do-it-yourself RTTI
4 source file of the Flower Library
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #ifndef VIRTUAL_METHODS_HH
11 #define VIRTUAL_METHODS_HH
14 #include "stdlib.h" // size_t
16 #define classname(class_ptr) demangle_classname(typeid(*(class_ptr)).name())
19 demangle_classname (const char*);
23 Virtual copy constructor. Make up for C++'s lack of a standard
24 clone() function. Uses a typeof hack. Usage:
26 class Foo : Baseclass {
27 VIRTUAL_COPY_CONS(Baseclass);
32 // fix constness: gcc-2.95 is correct in defining
34 // in a const member function to be const
37 #define VIRTUAL_COPY_CONS(base) \
38 virtual base *clone () const \
40 return new typeof(*this) (*this); \
43 #define VIRTUAL_COPY_CONS(base) \
44 virtual base* clone_const_helper () \
46 return new typeof (*this) (*this); \
48 virtual base* clone () const \
50 base* urg = (base*)this; \
51 return urg->clone_const_helper (); \
55 #endif /* VIRTUAL_METHODS_HH */