]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
release: 1.1.1
[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--1998 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 /**  Declare the classes name as a static and virtual function.
17   The static_name() can *not* be inlined (this might have the effect that 
18   s->name() != S::static_name (). Overlapping strings need not be merged in C++
19  */
20 #define DECLARE_MY_RUNTIME_TYPEINFO     \
21 virtual char const *name() const{ return static_name (); }\
22 static char const *static_name()
23
24
25 #if 0
26   /*
27     oops.  before() has nothing to do with inheritance
28    */
29 inline bool operator > (type_info const &a1, type_info const &a2)
30 {
31   return a2.before (a1);
32 }
33
34 inline bool operator < (type_info const &a1, type_info const &a2)
35 {
36   return a1.before (a2);
37 }
38
39 inline bool operator <= (type_info const &a1, type_info const &a2)
40 {
41   return a1 == a2 ||  a1 < a2;
42 }
43
44 inline bool operator >= (type_info const &a1, type_info const &a2)
45 {
46   return a1 == a2 ||  a1 > a2;
47 }
48 #endif
49
50 #define IMPLEMENT_STATIC_NAME(c)\
51     char const *c::static_name() { return #c; }
52
53      /*
54     size_t c::static_class_size () { return sizeof (c); }
55     */
56
57 #define VIRTUAL_COPY_CONS(T, R)\
58   virtual R *clone() const { return  new T(*this); } 
59
60 #define DECLARE_VIRTUAL_COPY_CONS(T, R)\
61       virtual R *clone() const
62
63 #define IMPLEMENT_VIRTUAL_COPY_CONS(T, R)\
64         R *T::clone() const { return  new T(*this); }\
65
66     
67 #define IMPLEMENT_IS_TYPE_B(D)\
68   IMPLEMENT_STATIC_NAME(D)
69
70 /*
71   bool D::static_is_type_b (const char *s)\
72 {\
73   return s == static_name();\
74 }*/
75
76 #define IMPLEMENT_IS_TYPE_B1(D, B)\
77   IMPLEMENT_STATIC_NAME(D)
78 /*
79   bool D::static_is_type_b (const char *s)\
80 {\
81   return s == static_name() || B::static_is_type_b (s);\
82 }
83 */
84
85 #define IMPLEMENT_IS_TYPE_B2(D, BA, BB)\
86   IMPLEMENT_STATIC_NAME(D)
87
88 /*
89      
90   bool D::static_is_type_b (const char *s)\
91 {\
92   return s == static_name() || BA::static_is_type_b (s) || BB::static_is_type_b (s);\
93 }
94 */
95
96 #endif