]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
* scripts/lilypond-book.py (compose_ly): bugfix for relative < 0.
[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--2004 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
15 #define classname(class_ptr)   demangle_classname (typeid (* (class_ptr)))
16
17 const char *
18 demangle_classname (std::type_info const &);
19
20 /* Virtual copy constructor.  Make up for C++'s lack of a standard
21    factory or clone () function.  Uses a typeof hack.  Usage:
22
23    class Foo : Baseclass
24    {
25       VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo);
26    }; */
27
28 Base *clone () const { return new Name (*this); }
29
30 #define VIRTUAL_COPY_CONSTRUCTOR(base, name) \
31   /* Hack to fix constness: gcc >= 2.95 is correct in defining \
32      typeof (*this) in a const member function to be const.  */ \
33   virtual base* clone_const_helper () \
34     { \
35       return new name (*this); \
36     } \
37   virtual base *clone () const \
38     { \
39       /* return new name (*this); */ \
40       base *urg = (base*) this; \
41       return urg->clone_const_helper (); \
42     }
43
44 #endif /* VIRTUAL_METHODS_HH */