]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.3.93
[lilypond.git] / lily / identifier.cc
1 /*
2   identifier.cc -- implement identifier and derived classes
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 /*
11   JUNKTHIS!
12  */
13 #include <assert.h>
14
15 #include "music-output-def.hh"
16 #include "score.hh"
17 #include "identifier.hh"
18 #include "my-lily-lexer.hh"
19 #include "debug.hh"
20 #include "ly-smobs.icc"
21
22
23 IMPLEMENT_UNSMOB(Identifier, identifier);
24 IMPLEMENT_SMOBS(Identifier);
25 IMPLEMENT_DEFAULT_EQUAL_P(Identifier);
26
27 Identifier::Identifier (int code)
28 {
29   token_code_i_ = code;
30   accessed_b_ = 0;
31   smobify_self ();
32 }
33
34 Identifier::Identifier (Identifier const&s)
35   : Input (s)
36 {
37   smobify_self ();  
38   token_code_i_ = s.token_code_i_;
39   accessed_b_ = s.accessed_b_;
40 }
41
42 Identifier::~Identifier()
43 {
44 }
45
46 void
47 Identifier::error (String expect) const
48 {
49   ::error (_f ("wrong identifier type, expected: `%s'", expect));
50 }
51
52 String
53 Identifier::str () const
54 {
55   return do_str ();
56 }
57
58 String
59 Identifier::do_str () const
60 {
61   return "";
62 }
63
64
65 /* ugh. */
66 #define DUMMY_STR(Class) \
67 String \
68 Class ## _identifier::do_str () const { \
69   return String (#Class); \
70 }
71
72 DUMMY_STR(Score);
73 DUMMY_STR(Music_output_def);
74 DUMMY_STR(Duration);
75
76   
77 #define DEFAULT_STR(Class) \
78 String \
79 Class ## _identifier::do_str () const\
80 {\
81   return to_str (*data_p_);\
82 }
83
84   
85
86 /*
87   fucking C++ blows me.
88  */
89
90 #define DEFAULT_ACCESSOR(Class)\
91 Class*\
92 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
93   ((Class ## _identifier*)this)->accessed_b_ = true;\
94   return copy_b ? new Class (*data_p_) : data_p_;\
95 }
96
97 #define VIRTUAL_ACCESSOR(Class)\
98 Class*\
99 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
100   ((Class ## _identifier*)this)->accessed_b_ = true;\
101   return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
102 }
103
104 #define IMPLEMENT_ID_CLASS(Class)       \
105         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
106         Class ## _identifier::Class ## _identifier (Class*st, int code) \
107           :Identifier (code)\
108         {\
109           data_p_ = st;\
110         }\
111 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
112   : Identifier (s)\
113 {\
114    data_p_ = s.access_content_ ## Class (true);\
115
116
117
118 IMPLEMENT_ID_CLASS(Duration);
119 IMPLEMENT_ID_CLASS(Score);
120 IMPLEMENT_ID_CLASS(Music_output_def);
121 VIRTUAL_ACCESSOR(Music_output_def);
122 DEFAULT_ACCESSOR(Duration);
123 DEFAULT_ACCESSOR(Score);
124
125
126 int
127 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
128 {
129  return 1;  
130 }
131
132 SCM
133 Identifier::mark_smob (SCM s)
134 {
135   return SCM_EOL;
136 }
137
138
139