]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
release: 0.1.8
[lilypond.git] / flower / include / virtual-methods.hh
1 /*
2   virtual-methods.hh -- declare 
3
4   source file of the Flower Library
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef VIRTUAL_METHODS_HH
11 #define VIRTUAL_METHODS_HH
12
13 /** a macro to declare the classes name as a static and virtual function.
14   The static_name() can *not* be inlined (this might have the effect that 
15   s->name() != S::static_name (). Overlapping strings need not be merged in C++
16  */
17 #define DECLARE_MY_RUNTIME_TYPEINFO     \
18 static char const *static_name();\
19 static bool static_is_type_b (const char*s);\
20 virtual bool is_type_b (const char *s)const { return static_is_type_b (s); } \
21 virtual char const *name() const{ return static_name (); } \
22 int a_stupid_nonexistent_function_to_allow_the_semicolon_come_out()
23
24 #define IMPLEMENT_STATIC_NAME(c)\
25     char const *c::static_name() { return #c; } 
26
27
28
29 #define VIRTUAL_COPY_CONS(T, R)\
30   virtual R *clone() const { return  new T(*this); } \
31   int  yet_another_stupid_function_to_allow_semicolon()
32
33
34 #define DECLARE_VIRTUAL_COPY_CONS(T,R)\
35       virtual R *clone() const
36 #define IMPLEMENT_VIRTUAL_COPY_CONS(T,R)\
37         R *T::clone() const { return  new T(*this); } \
38     
39 #define IMPLEMENT_IS_TYPE_B(D)                                                     \
40     IMPLEMENT_STATIC_NAME(D)\
41   bool D::static_is_type_b (const char *s)                                         \
42 {                                                                                  \
43     return s == static_name();                                                     \
44 }                                                                                  
45                                                                                    
46 #define IMPLEMENT_IS_TYPE_B1(D,B)                                                  \
47         IMPLEMENT_STATIC_NAME(D)\
48   bool D::static_is_type_b (const char *s)                                                 \
49 {                                                                                  \
50     return s == static_name() || B::static_is_type_b (s);                                  \
51 }                                                                                  
52 #define IMPLEMENT_IS_TYPE_B2(D, BA, BB)                                                    \
53         IMPLEMENT_STATIC_NAME(D)\
54   bool D::static_is_type_b (const char *s)                                                 \
55 {                                                                                  \
56     return s == static_name() || BA::static_is_type_b (s) || BB::static_is_type_b (s); \
57 }
58
59 #endif