2 identifier.cc -- implement identifier and derived classes
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "midi-def.hh"
11 #include "paper-def.hh"
13 #include "identifier.hh"
14 #include "my-lily-lexer.hh"
17 #include "translator-group.hh"
18 #include "notename-table.hh"
22 Identifier::Identifier (int code
)
31 Identifier::Identifier (Identifier
const&s
)
34 token_code_i_
= s
.token_code_i_
;
35 accessed_b_
= s
.accessed_b_
;
39 Identifier::~Identifier()
44 Identifier::error (String expect
) const
46 ::error (_f ("wrong identifier type, expected: `%s'", expect
));
50 Identifier::str () const
56 Identifier::do_str () const
62 Identifier::print () const
64 DEBUG_OUT
<< "identifier ";
68 Identifier::do_print () const
73 #define DEFAULT_PRINT(Class) \
75 Class ## _identifier::do_print () const { \
76 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
82 DEFAULT_PRINT(Translator_group
);
84 DEFAULT_PRINT(Request
);
86 DEFAULT_PRINT(Midi_def
);
87 DEFAULT_PRINT(Paper_def
);
90 #define DUMMY_STR(Class) \
92 Class ## _identifier::do_str () const { \
93 return String (#Class); \
97 DUMMY_STR(Notename_table
);
98 DUMMY_STR(Translator_group
);
103 DUMMY_STR(Paper_def
);
106 #define STRING_PRINT(Class) \
108 Class ## _identifier::do_print () const\
110 DEBUG_OUT << do_str () << '\n';\
114 STRING_PRINT(Duration);
117 STRING_PRINT(String
);
118 STRING_PRINT(Notename_table
);
120 #define DEFAULT_STR(Class) \
122 Class ## _identifier::do_str () const\
124 return to_str (*data_p_);\
133 fucking C++ blows me.
136 #define DEFAULT_ACCESSOR(Class)\
138 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
139 ((Class ## _identifier*)this)->accessed_b_ = true;\
140 return copy_b ? new Class (*data_p_) : data_p_;\
143 #define VIRTUAL_ACCESSOR(Class)\
145 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
146 ((Class ## _identifier*)this)->accessed_b_ = true;\
147 return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
150 #define IMPLEMENT_ID_CLASS(Class) \
151 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
152 Class ## _identifier::Class ## _identifier (Class*st, int code) \
157 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
160 data_p_ = s.access_content_ ## Class (true);\
164 IMPLEMENT_ID_CLASS(Duration
);
165 IMPLEMENT_ID_CLASS(Translator_group
);
166 IMPLEMENT_ID_CLASS(int);
167 IMPLEMENT_ID_CLASS(Real
);
168 IMPLEMENT_ID_CLASS(String
);
169 IMPLEMENT_ID_CLASS(Music
);
170 IMPLEMENT_ID_CLASS(Score
);
171 IMPLEMENT_ID_CLASS(Request
);
172 IMPLEMENT_ID_CLASS(Midi_def
);
173 IMPLEMENT_ID_CLASS(Paper_def
);
174 IMPLEMENT_ID_CLASS(Notename_table
);
175 VIRTUAL_ACCESSOR(Music
);
176 VIRTUAL_ACCESSOR(Request
);
177 VIRTUAL_ACCESSOR(Translator_group
);
178 DEFAULT_ACCESSOR(Notename_table
);
179 DEFAULT_ACCESSOR(Duration
);
180 DEFAULT_ACCESSOR(int);
181 DEFAULT_ACCESSOR(Real
);
182 DEFAULT_ACCESSOR(String
);
183 DEFAULT_ACCESSOR(Score
);
184 DEFAULT_ACCESSOR(Midi_def
);
185 DEFAULT_ACCESSOR(Paper_def
);