]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.3.107
[lilypond.git] / lily / identifier.cc
1 /*
2   identifier.cc -- implement identifier and derived classes
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 /*
11   JUNKTHIS!
12  */
13 #include <assert.h>
14
15 #include "music-output-def.hh"
16 #include "score.hh"
17 #include "identifier.hh"
18 #include "my-lily-lexer.hh"
19 #include "debug.hh"
20 #include "ly-smobs.icc"
21
22
23 IMPLEMENT_UNSMOB(Identifier, identifier);
24 IMPLEMENT_SMOBS(Identifier);
25 IMPLEMENT_DEFAULT_EQUAL_P(Identifier);
26
27 Identifier::Identifier (int code)
28 {
29   token_code_i_ = code;
30   accessed_b_ = 0;
31   smobify_self ();
32 }
33
34 Identifier::Identifier (Identifier const&s)
35   : Input (s)
36 {
37   smobify_self ();  
38   token_code_i_ = s.token_code_i_;
39   accessed_b_ = s.accessed_b_;
40 }
41
42 Identifier::~Identifier()
43 {
44 }
45
46 void
47 Identifier::error (String expect) const
48 {
49   ::error (_f ("wrong identifier type, expected: `%s'", expect));
50 }
51
52 String
53 Identifier::str () const
54 {
55   return do_str ();
56 }
57
58 String
59 Identifier::do_str () const
60 {
61   return "";
62 }
63
64
65 /* ugh. */
66 #define DUMMY_STR(Class) \
67 String \
68 Class ## _identifier::do_str () const { \
69   return String (#Class); \
70 }
71
72 DUMMY_STR(Score);
73 DUMMY_STR(Music_output_def);
74
75   
76 #define DEFAULT_STR(Class) \
77 String \
78 Class ## _identifier::do_str () const\
79 {\
80   return to_str (*data_p_);\
81 }
82
83   
84
85 /*
86   fucking C++ blows me.
87  */
88
89 #define DEFAULT_ACCESSOR(Class)\
90 Class*\
91 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
92   ((Class ## _identifier*)this)->accessed_b_ = true;\
93   return copy_b ? new Class (*data_p_) : data_p_;\
94 }
95
96 #define VIRTUAL_ACCESSOR(Class)\
97 Class*\
98 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
99   ((Class ## _identifier*)this)->accessed_b_ = true;\
100   return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
101 }
102
103 #define IMPLEMENT_ID_CLASS(Class)       \
104         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
105         Class ## _identifier::Class ## _identifier (Class*st, int code) \
106           :Identifier (code)\
107         {\
108           data_p_ = st;\
109         }\
110 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
111   : Identifier (s)\
112 {\
113    data_p_ = s.access_content_ ## Class (true);\
114
115
116
117 IMPLEMENT_ID_CLASS(Score);
118 IMPLEMENT_ID_CLASS(Music_output_def);
119 VIRTUAL_ACCESSOR(Music_output_def);
120 DEFAULT_ACCESSOR(Score);
121
122
123 int
124 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
125 {
126  return 1;  
127 }
128
129 SCM
130 Identifier::mark_smob (SCM s)
131 {
132   return SCM_EOL;
133 }
134
135
136