]> git.donarmstrong.com Git - lilypond.git/blob - lily/lilypond-key.cc
* lily/context.cc (Context): take key argument in ctor.
[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
65
66 void
67 Lilypond_context_key::derived_mark () const
68 {
69   if (parent_context_)
70     scm_gc_mark (parent_context_->self_scm ());
71 }
72
73 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
74                                             Moment start,
75                                             String type,
76                                             String id,
77                                             int count)
78 {
79   disambiguation_count_ = count;
80   parent_context_ = parent;
81   start_moment_ = start;
82   context_name_ = type;
83   id_ = id;
84 }
85
86
87 int
88 Lilypond_context_key::do_compare (Object_key const *key) const
89 {
90   Lilypond_context_key const * other
91     = dynamic_cast<Lilypond_context_key const*> (key); 
92
93   int c;
94   if (parent_context_)
95     {
96       c = parent_context_->compare (other->parent_context_);
97       if (c)
98         return c;
99     }
100   
101   c = Moment::compare (start_moment_, other->start_moment_);
102   if (c)
103     return c;
104
105   c = String::compare (context_name_, other->context_name_);
106   if (c)
107     return c;
108
109   c = String::compare (id_, other->id_);
110   if (c)
111     return c;
112
113   c = sign (disambiguation_count_ - other->disambiguation_count_);
114   if (c)
115     return c;
116   
117   return 0;
118 }
119
120 int
121 Lilypond_context_key::get_type () const
122 {
123   return CONTEXT_KEY;
124 }