]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
patch::: 1.2.0.jcn1
[lilypond.git] / flower / include / virtual-methods.hh
1 /*
2   virtual-methods.hh -- declare macros for our do-it-yourself RTTI
3
4   source file of the Flower Library
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef VIRTUAL_METHODS_HH
11 #define VIRTUAL_METHODS_HH
12
13 #include <typeinfo>
14 #include "stdlib.h"             // size_t
15
16 #define classname(class_ptr)   demangle_classname(typeid(*(class_ptr)).name())
17
18 const char *
19 demangle_classname (const char*);
20
21 /**
22
23    Virtual copy constructor. Make up for C++'s lack of a standard
24    clone() function.  Uses a typeof hack.  Usage:
25
26    class Foo : Baseclass {
27         VIRTUAL_COPY_CONS(Baseclass);
28    };
29    
30  */
31
32 // fix constness: gcc-2.95 is correct in defining
33 //    typeof (*this)
34 // in a const member function to be const
35
36 #if 0
37 #define VIRTUAL_COPY_CONS(base) \
38   virtual base *clone () const \
39   { \
40     return new typeof(*this) (*this); \
41   }
42 #else
43 #define VIRTUAL_COPY_CONS(base) \
44   virtual base* clone_const_helper () \
45     { \
46       return new typeof (*this) (*this); \
47     } \
48   virtual base* clone () const \
49     { \
50       base* urg = (base*)this; \
51       return urg->clone_const_helper (); \
52     }
53 #endif 
54
55 #endif /* VIRTUAL_METHODS_HH */