lilypond-1.3.12
[lilypond.git] / lily / identifier.cc
blobe8421fb70db9a435634d3c2fc5f5b6730dbe9cdc
1 /*
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>
7 */
9 #include <assert.h>
10 #include "midi-def.hh"
11 #include "paper-def.hh"
12 #include "score.hh"
13 #include "identifier.hh"
14 #include "my-lily-lexer.hh"
15 #include "debug.hh"
16 #include "request.hh"
17 #include "translator-group.hh"
18 #include "notename-table.hh"
22 Identifier::Identifier (int code)
24 token_code_i_ = code;
25 accessed_b_ = 0;
26 init_b_ = 0;
31 Identifier::Identifier (Identifier const&s)
32 : Input (s)
34 token_code_i_ = s.token_code_i_;
35 accessed_b_ = s.accessed_b_;
36 init_b_ = s.init_b_;
39 Identifier::~Identifier()
43 void
44 Identifier::error (String expect) const
46 ::error (_f ("wrong identifier type, expected: `%s'", expect));
49 String
50 Identifier::str () const
52 return do_str ();
55 String
56 Identifier::do_str () const
58 return "";
61 void
62 Identifier::print () const
64 DEBUG_OUT << "identifier ";
65 do_print ();
67 void
68 Identifier::do_print () const
72 /* ugh. */
73 #define DEFAULT_PRINT(Class) \
74 void \
75 Class ## _identifier::do_print () const { \
76 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
77 cl->print (); \
82 DEFAULT_PRINT(Translator_group);
83 DEFAULT_PRINT(Music);
84 DEFAULT_PRINT(Request);
85 DEFAULT_PRINT(Score);
86 DEFAULT_PRINT(Midi_def);
87 DEFAULT_PRINT(Paper_def);
89 /* ugh. */
90 #define DUMMY_STR(Class) \
91 String \
92 Class ## _identifier::do_str () const { \
93 return String (#Class); \
97 DUMMY_STR(Notename_table);
98 DUMMY_STR(Translator_group);
99 DUMMY_STR(Music);
100 DUMMY_STR(Request);
101 DUMMY_STR(Score);
102 DUMMY_STR(Midi_def);
103 DUMMY_STR(Paper_def);
104 DUMMY_STR(Duration);
106 #define STRING_PRINT(Class) \
107 void \
108 Class ## _identifier::do_print () const\
110 DEBUG_OUT << do_str () << '\n';\
114 STRING_PRINT(Duration);
115 STRING_PRINT(Real);
116 STRING_PRINT(int);
117 STRING_PRINT(String);
118 STRING_PRINT(Notename_table);
120 #define DEFAULT_STR(Class) \
121 String \
122 Class ## _identifier::do_str () const\
124 return to_str (*data_p_);\
127 DEFAULT_STR(int);
128 DEFAULT_STR(Real);
129 DEFAULT_STR(String);
133 fucking C++ blows me.
136 #define DEFAULT_ACCESSOR(Class)\
137 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)\
144 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) \
153 :Identifier (code)\
155 data_p_ = st;\
157 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
158 : Identifier (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);