]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
7c97716e4229f573836e28140e6dd1811d363df4
[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--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef VIRTUAL_METHODS_HH
10 #define VIRTUAL_METHODS_HH
11
12 #include <typeinfo>
13 using namespace std;
14
15 #define classname(class_ptr) demangle_classname (typeid (* (class_ptr)))
16
17 char const *
18 demangle_classname (type_info const &);
19
20 /*
21
22 Virtual copy constructor.  Make up for C++'s lack of a standard
23 factory or clone () function.  Usage:
24
25 class Foo : Baseclass
26 {
27 VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo);
28 };
29
30 */
31
32 #define DECLARE_CLASSNAME(name) \
33   virtual const char *class_name () const {     \
34     return #name; \
35 }
36
37 #define VIRTUAL_COPY_CONSTRUCTOR(Base, name)    \
38   DECLARE_CLASSNAME(name);\
39   virtual Base *clone () const                  \
40   {                                             \
41     return new name (*this);                    \
42   }
43
44 #endif /* VIRTUAL_METHODS_HH */