2 identifier.cc -- implement identifier and derived classes
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "midi-def.hh"
15 #include "paper-def.hh"
17 #include "identifier.hh"
18 #include "my-lily-lexer.hh"
21 #include "translator-group.hh"
22 #include "ly-smobs.icc"
24 IMPLEMENT_UNSMOB(Identifier, identifier);
25 IMPLEMENT_SMOBS(Identifier);
27 Identifier::Identifier (int code)
34 Identifier::Identifier (Identifier const&s)
38 token_code_i_ = s.token_code_i_;
39 accessed_b_ = s.accessed_b_;
42 Identifier::~Identifier()
47 Identifier::error (String expect) const
49 ::error (_f ("wrong identifier type, expected: `%s'", expect));
53 Identifier::str () const
59 Identifier::do_str () const
65 Identifier::print () const
67 DEBUG_OUT << "identifier ";
71 Identifier::do_print () const
76 #define DEFAULT_PRINT(Class) \
78 Class ## _identifier::do_print () const { \
79 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
85 DEFAULT_PRINT(Translator_group);
87 DEFAULT_PRINT(Request);
89 DEFAULT_PRINT(Midi_def);
90 DEFAULT_PRINT(Paper_def);
93 #define DUMMY_STR(Class) \
95 Class ## _identifier::do_str () const { \
96 return String (#Class); \
100 DUMMY_STR(Translator_group);
105 DUMMY_STR(Paper_def);
108 #define STRING_PRINT(Class) \
110 Class ## _identifier::do_print () const\
112 DEBUG_OUT << do_str () << '\n';\
116 STRING_PRINT(Duration);
119 STRING_PRINT(String);
121 #define DEFAULT_STR(Class) \
123 Class ## _identifier::do_str () const\
125 return to_str (*data_p_);\
134 fucking C++ blows me.
137 #define DEFAULT_ACCESSOR(Class)\
139 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
140 ((Class ## _identifier*)this)->accessed_b_ = true;\
141 return copy_b ? new Class (*data_p_) : data_p_;\
144 #define VIRTUAL_ACCESSOR(Class)\
146 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
147 ((Class ## _identifier*)this)->accessed_b_ = true;\
148 return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
151 #define IMPLEMENT_ID_CLASS(Class) \
152 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
153 Class ## _identifier::Class ## _identifier (Class*st, int code) \
158 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
161 data_p_ = s.access_content_ ## Class (true);\
165 IMPLEMENT_ID_CLASS(Duration);
166 IMPLEMENT_ID_CLASS(Translator_group);
167 IMPLEMENT_ID_CLASS(int);
168 IMPLEMENT_ID_CLASS(Real);
169 IMPLEMENT_ID_CLASS(String);
170 IMPLEMENT_ID_CLASS(Music);
171 IMPLEMENT_ID_CLASS(Score);
172 IMPLEMENT_ID_CLASS(Request);
173 IMPLEMENT_ID_CLASS(Midi_def);
174 IMPLEMENT_ID_CLASS(Paper_def);
175 VIRTUAL_ACCESSOR(Music);
176 VIRTUAL_ACCESSOR(Request);
177 VIRTUAL_ACCESSOR(Translator_group);
178 DEFAULT_ACCESSOR(Duration);
179 DEFAULT_ACCESSOR(int);
180 DEFAULT_ACCESSOR(Real);
181 DEFAULT_ACCESSOR(String);
182 DEFAULT_ACCESSOR(Score);
183 DEFAULT_ACCESSOR(Midi_def);
184 DEFAULT_ACCESSOR(Paper_def);
187 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
193 Identifier::mark_smob (SCM s)
201 Identifier::do_smobify_self ()