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"
24 Identifier::Identifier (int code)
30 Identifier::Identifier (Identifier const&s)
33 token_code_i_ = s.token_code_i_;
34 accessed_b_ = s.accessed_b_;
37 Identifier::~Identifier()
42 Identifier::error (String expect) const
44 ::error (_f ("wrong identifier type, expected: `%s'", expect));
48 Identifier::str () const
54 Identifier::do_str () const
60 Identifier::print () const
62 DEBUG_OUT << "identifier ";
66 Identifier::do_print () const
71 #define DEFAULT_PRINT(Class) \
73 Class ## _identifier::do_print () const { \
74 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
80 DEFAULT_PRINT(Translator_group);
82 DEFAULT_PRINT(Request);
84 DEFAULT_PRINT(Midi_def);
85 DEFAULT_PRINT(Paper_def);
88 #define DUMMY_STR(Class) \
90 Class ## _identifier::do_str () const { \
91 return String (#Class); \
95 DUMMY_STR(Translator_group);
100 DUMMY_STR(Paper_def);
103 #define STRING_PRINT(Class) \
105 Class ## _identifier::do_print () const\
107 DEBUG_OUT << do_str () << '\n';\
111 STRING_PRINT(Duration);
114 STRING_PRINT(String);
116 #define DEFAULT_STR(Class) \
118 Class ## _identifier::do_str () const\
120 return to_str (*data_p_);\
129 fucking C++ blows me.
132 #define DEFAULT_ACCESSOR(Class)\
134 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
135 ((Class ## _identifier*)this)->accessed_b_ = true;\
136 return copy_b ? new Class (*data_p_) : data_p_;\
139 #define VIRTUAL_ACCESSOR(Class)\
141 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
142 ((Class ## _identifier*)this)->accessed_b_ = true;\
143 return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
146 #define IMPLEMENT_ID_CLASS(Class) \
147 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
148 Class ## _identifier::Class ## _identifier (Class*st, int code) \
153 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
156 data_p_ = s.access_content_ ## Class (true);\
160 IMPLEMENT_ID_CLASS(Duration);
161 IMPLEMENT_ID_CLASS(Translator_group);
162 IMPLEMENT_ID_CLASS(int);
163 IMPLEMENT_ID_CLASS(Real);
164 IMPLEMENT_ID_CLASS(String);
165 IMPLEMENT_ID_CLASS(Music);
166 IMPLEMENT_ID_CLASS(Score);
167 IMPLEMENT_ID_CLASS(Request);
168 IMPLEMENT_ID_CLASS(Midi_def);
169 IMPLEMENT_ID_CLASS(Paper_def);
170 VIRTUAL_ACCESSOR(Music);
171 VIRTUAL_ACCESSOR(Request);
172 VIRTUAL_ACCESSOR(Translator_group);
173 DEFAULT_ACCESSOR(Duration);
174 DEFAULT_ACCESSOR(int);
175 DEFAULT_ACCESSOR(Real);
176 DEFAULT_ACCESSOR(String);
177 DEFAULT_ACCESSOR(Score);
178 DEFAULT_ACCESSOR(Midi_def);
179 DEFAULT_ACCESSOR(Paper_def);