]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
Update.
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #ifndef VIRTUAL_METHODS_HH
10 #define VIRTUAL_METHODS_HH
11
12 #include <typeinfo>
13
14 #define classname(class_ptr) demangle_classname (typeid (* (class_ptr)))
15
16 const char *
17 demangle_classname (std::type_info const &);
18
19 /* Virtual copy constructor.  Make up for C++'s lack of a standard
20    factory or clone () function.  Uses a typeof hack.  Usage:
21
22    class Foo : Baseclass
23    {
24    VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo);
25    }; */
26
27 #define VIRTUAL_COPY_CONSTRUCTOR(Base, name)                    \
28   /* Hack to fix constness: gcc >= 2.95 is correct in defining  \
29      typeof (*this) in a const member function to be const.  */ \
30   virtual Base *clone_const_helper ()                           \
31   {                                                             \
32     return new name (*this);                                    \
33   }                                                             \
34   virtual Base *clone () const                                  \
35   {                                                             \
36     /* return new name (*this); */                              \
37     Base *urg = (Base *) this;                                  \
38     return urg->clone_const_helper ();                          \
39   }
40
41 #endif /* VIRTUAL_METHODS_HH */