]> git.donarmstrong.com Git - lilypond.git/blob - lily/lilypond-key.cc
* lily/include/object-key-undumper.hh (Module): new file.
[lilypond.git] / lily / lilypond-key.cc
1 /*
2   lilypond-key.cc --  implement Lilypond_{grob,context}_key
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10
11 #include "object-key.hh"
12 #include "lilypond-key.hh"
13
14 Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
15                                       Moment start,
16                                       String name,
17                                       int disambiguation_count)
18 {
19   context_ = context;
20   creation_moment_ = start;
21   grob_name_ = name;
22   disambiguation_count_ = disambiguation_count;
23 }
24
25 void
26 Lilypond_grob_key::derived_mark () const
27 {
28   scm_gc_mark (context_->self_scm ());
29 }
30
31 int
32 Lilypond_grob_key::do_compare (Object_key const* key) const
33 {
34   Lilypond_grob_key const * other = dynamic_cast<Lilypond_grob_key const*> (key); 
35   int c;
36
37   c = context_->compare (other->context_);
38   if (c)
39     return c;
40   
41   c = Moment::compare (creation_moment_, other->creation_moment_);
42   if (c)
43     return c;
44
45   c = String::compare (grob_name_, other->grob_name_);
46   if (c)
47     return c;
48
49   c = sign (disambiguation_count_ - other->disambiguation_count_); 
50   if (c)
51     return c;
52   
53   return 0;
54 }
55
56
57 int
58 Lilypond_grob_key::get_type () const
59 {
60   return GROB_KEY;
61 }
62
63
64 SCM
65 Lilypond_grob_key::as_scheme () const
66 {
67   return scm_list_4 (context_ ? context_->self_scm() : SCM_BOOL_F,
68                      creation_moment_.smobbed_copy(),
69                      scm_makfrom0str (grob_name_.to_str0()),
70                      scm_from_int (disambiguation_count_)); 
71 }
72
73
74 Object_key *
75 Lilypond_grob_key::from_scheme (SCM a) 
76 {
77   return new Lilypond_grob_key (unsmob_key (scm_car (a)),
78                                 *unsmob_moment (scm_cadr (a)),
79                                 ly_scm2string  (scm_caddr (a)),
80                                 scm_to_int (scm_cadddr (a)));
81 }
82
83
84 /****************************************************************/
85
86 void
87 Lilypond_context_key::derived_mark () const
88 {
89   if (parent_context_)
90     scm_gc_mark (parent_context_->self_scm ());
91 }
92
93 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
94                                             Moment start,
95                                             String type,
96                                             String id,
97                                             int count)
98 {
99   disambiguation_count_ = count;
100   parent_context_ = parent;
101   start_moment_ = start;
102   context_name_ = type;
103   id_ = id;
104 }
105
106
107 int
108 Lilypond_context_key::do_compare (Object_key const *key) const
109 {
110   Lilypond_context_key const * other
111     = dynamic_cast<Lilypond_context_key const*> (key); 
112
113   int c;
114   if (parent_context_ && other->parent_context_)
115     {
116       c = parent_context_->compare (other->parent_context_);
117       if (c)
118         return c;
119     }
120   else if (parent_context_)
121     return -1 ;
122   else if (other->parent_context_)
123     return 1;
124   
125   
126   c = Moment::compare (start_moment_, other->start_moment_);
127   if (c)
128     return c;
129
130   c = String::compare (context_name_, other->context_name_);
131   if (c)
132     return c;
133
134   c = String::compare (id_, other->id_);
135   if (c)
136     return c;
137
138   c = sign (disambiguation_count_ - other->disambiguation_count_);
139   if (c)
140     return c;
141   
142   return 0;
143 }
144
145 int
146 Lilypond_context_key::get_type () const
147 {
148   return CONTEXT_KEY;
149 }
150
151
152 SCM
153 Lilypond_context_key::as_scheme () const
154 {
155   return scm_list_5 (parent_context_ ? parent_context_->self_scm() : SCM_BOOL_F,
156                      start_moment_.smobbed_copy(),
157                      scm_makfrom0str (context_name_.to_str0()),
158                      scm_makfrom0str (id_.to_str0()),
159                      scm_from_int (disambiguation_count_)); 
160 }
161
162 Object_key *
163 Lilypond_context_key::from_scheme (SCM a) 
164 {
165   return new Lilypond_grob_key (unsmob_key (scm_car (a)),
166                                 *unsmob_moment (scm_cadr (a)),
167                                 ly_scm2string  (scm_list_ref (a, scm_from_int (2))),
168                                 scm_to_int  (scm_list_ref (a, scm_from_int (3))));
169 }
170
171
172 /****************************************************************/
173
174 int
175 Lilypond_general_key::get_type () const
176 {
177   return GENERAL_KEY;
178 }
179
180 void
181 Lilypond_general_key::derived_mark () const
182 {
183   if (parent_)
184     scm_gc_mark (parent_->self_scm ());
185 }
186
187 Lilypond_general_key::Lilypond_general_key (Object_key const*parent,
188                                             String name,
189                                             int count)
190 {
191   parent_ = parent;
192   name_ = name;
193   disambiguation_count_ = count; 
194 }
195
196
197 int
198 Lilypond_general_key::do_compare (Object_key const* key)const
199 {
200   Lilypond_general_key const* other
201     = dynamic_cast<Lilypond_general_key const*> (key);
202
203   if (parent_ && other->parent_)
204     parent_->compare (other->parent_);
205   else if (parent_)
206     return -1 ;
207   else if (other->parent_)
208     return 1;
209
210   int c = String::compare (name_, other->name_);
211   if (c)
212     return c;
213
214   
215   c = sign (disambiguation_count_ - other->disambiguation_count_);
216   if (c)
217     return c;
218
219   return 0;  
220 }
221
222 SCM
223 Lilypond_general_key::as_scheme () const
224 {
225   return scm_list_3 (parent_ ? parent_->self_scm() : SCM_BOOL_F,
226                      scm_makfrom0str (name_.to_str0()),
227                      scm_from_int (disambiguation_count_)); 
228 }
229
230 Object_key *
231 Lilypond_general_key::from_scheme (SCM a) 
232 {
233   return new Lilypond_general_key (unsmob_key (scm_car (a)),
234                                    ly_scm2string  (scm_list_ref (a, scm_from_int (1))),
235                                    scm_to_int  (scm_list_ref (a, scm_from_int (2))));
236 }