]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/virtual-methods.hh
patch::: 1.0.15.jcn2: pl2 voor riel
[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 "stdlib.h"             // size_t
14
15 /**  Declare the classes name as a static and virtual function.
16   The static_name() can *not* be inlined (this might have the effect that 
17   s->name() != S::static_name (). Overlapping strings need not be merged in C++
18  */
19 #define DECLARE_MY_RUNTIME_TYPEINFO     \
20 static bool static_is_type_b (const char*s);\
21 virtual bool is_type_b (const char *s) const { return static_is_type_b (s); } \
22 virtual char const *name() const{ return static_name (); } \
23 virtual size_t class_size () const { return static_class_size (); }\
24 static size_t static_class_size (); \
25 static char const *static_name()
26
27 #define IMPLEMENT_STATIC_NAME(c)\
28     char const *c::static_name() { return #c; } \
29     size_t c::static_class_size () { return sizeof (c); }
30
31
32
33 #define VIRTUAL_COPY_CONS(T, R)\
34   virtual R *clone() const { return  new T(*this); } \
35   int  yet_another_stupid_function_to_allow_semicolon()
36
37
38 #define DECLARE_VIRTUAL_COPY_CONS(T, R)\
39       virtual R *clone() const
40 #define IMPLEMENT_VIRTUAL_COPY_CONS(T, R)\
41         R *T::clone() const { return  new T(*this); }\
42
43     
44 #define IMPLEMENT_IS_TYPE_B(D)\
45   IMPLEMENT_STATIC_NAME(D)\
46   bool D::static_is_type_b (const char *s)\
47 {\
48   return s == static_name();\
49 }
50
51 #define IMPLEMENT_IS_TYPE_B1(D, B)\
52   IMPLEMENT_STATIC_NAME(D)\
53   bool D::static_is_type_b (const char *s)\
54 {\
55   return s == static_name() || B::static_is_type_b (s);\
56 }
57
58 #define IMPLEMENT_IS_TYPE_B2(D, BA, BB)\
59   IMPLEMENT_STATIC_NAME(D)\
60   bool D::static_is_type_b (const char *s)\
61 {\
62   return s == static_name() || BA::static_is_type_b (s) || BB::static_is_type_b (s);\
63 }
64
65 #endif