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"
16 #include "script-def.hh"
18 #include "translator.hh"
19 #include "notename-table.hh"
23 Identifier::Identifier (int code)
32 Identifier::Identifier (Identifier const&s)
35 token_code_i_ = s.token_code_i_;
36 accessed_b_ = s.accessed_b_;
40 Identifier::~Identifier()
45 Identifier::error (String expect) const
47 String e (_("Wrong identifier type: "));
48 e += _f ("%s expected", expect);
53 Identifier::str () const
59 Identifier::do_str () const
65 Identifier::print () const
67 DOUT << "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(General_script_def);
86 DEFAULT_PRINT(Translator);
88 DEFAULT_PRINT(Request);
90 DEFAULT_PRINT(Midi_def);
91 DEFAULT_PRINT(Paper_def);
94 #define DUMMY_STR(Class) \
96 Class ## _identifier::do_str () const { \
97 return String (#Class); \
101 DUMMY_STR(Notename_table);
102 DUMMY_STR(General_script_def);
103 DUMMY_STR(Translator);
108 DUMMY_STR(Paper_def);
111 #define STRING_PRINT(Class) \
113 Class ## _identifier::do_print () const\
115 DOUT << do_str () << '\n';\
119 STRING_PRINT(Duration);
122 STRING_PRINT(String);
123 STRING_PRINT(Notename_table);
125 #define DEFAULT_STR(Class) \
127 Class ## _identifier::do_str () const\
129 return to_str (*data_p_);\
138 fucking C++ blows me.
141 #define DEFAULT_ACCESSOR(Class)\
143 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
144 ((Class ## _identifier*)this)->accessed_b_ = true;\
145 return copy_b ? new Class (*data_p_) : data_p_;\
148 #define VIRTUAL_ACCESSOR(Class)\
150 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
151 ((Class ## _identifier*)this)->accessed_b_ = true;\
152 return copy_b ? (Class*)data_p_->clone() : data_p_;\
155 #define IMPLEMENT_ID_CLASS(Class) \
156 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
157 Class ## _identifier::Class ## _identifier (Class*st, int code) \
162 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
165 data_p_ = s.access_content_ ## Class (true);\
169 IMPLEMENT_ID_CLASS(Duration);
170 IMPLEMENT_ID_CLASS(Translator);
171 IMPLEMENT_ID_CLASS(int);
172 IMPLEMENT_ID_CLASS(Real);
173 IMPLEMENT_ID_CLASS(String);
174 IMPLEMENT_ID_CLASS(General_script_def);
175 IMPLEMENT_ID_CLASS(Music);
176 IMPLEMENT_ID_CLASS(Score);
177 IMPLEMENT_ID_CLASS(Request);
178 IMPLEMENT_ID_CLASS(Midi_def);
179 IMPLEMENT_ID_CLASS(Paper_def);
180 IMPLEMENT_ID_CLASS(Notename_table);
181 VIRTUAL_ACCESSOR(Music);
182 VIRTUAL_ACCESSOR(Request);
183 VIRTUAL_ACCESSOR(Translator);
184 VIRTUAL_ACCESSOR(General_script_def);
185 DEFAULT_ACCESSOR(Notename_table);
186 DEFAULT_ACCESSOR(Duration);
187 DEFAULT_ACCESSOR(int);
188 DEFAULT_ACCESSOR(Real);
189 DEFAULT_ACCESSOR(String);
190 DEFAULT_ACCESSOR(Score);
191 DEFAULT_ACCESSOR(Midi_def);
192 DEFAULT_ACCESSOR(Paper_def);