]> git.donarmstrong.com Git - lilypond.git/blob - lily/lilypond-key.cc
48f4daa446640cb8f1ee7bef021474defe9ef306
[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 ambiguity_count,
18 {
19   context_ = context;
20   creation_moment_ = start;
21   grob_name_ = name;
22   //  ambiguity_count_ = ambiguity_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 #if 0
49   c = sign (ambiguity_count_ - other->ambiguity_count_); 
50   if (c)
51     return c;
52 #endif
53   
54   return 0;
55 }
56
57
58 int
59 Lilypond_grob_key::get_type () const
60 {
61   return GROB_KEY;
62 }
63
64 /****************************************************************/
65
66
67 void
68 Lilypond_context_key::derived_mark () const
69 {
70   if (parent_context_)
71     scm_gc_mark (parent_context_->self_scm ());
72 }
73
74 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
75                                             Moment start,
76                                             String type,
77                                             String id
78                                             // int count
79                                             )
80 {
81   parent_context_ = parent;
82   start_moment_ = start;
83   context_name_ = type;
84   id_ = id;
85 }
86
87
88 int
89 Lilypond_context_key::do_compare (Object_key const *key) const
90 {
91   Lilypond_context_key const * other
92     = dynamic_cast<Lilypond_context_key const*> (key); 
93
94   int c;
95   if (parent_context_)
96     {
97       c = parent_context_->compare (other->parent_context_);
98       if (c)
99         return c;
100     }
101   
102   c = Moment::compare (start_moment_, other->start_moment_);
103   if (c)
104     return c;
105
106   c = String::compare (context_name_, other->context_name_);
107   if (c)
108     return c;
109
110   c = String::compare (id_, other->id_);
111   if (c)
112     return c;
113
114 #if 0
115   c = sign (ambiguity_count_ - other->ambiguity_count_);
116   if (c)
117     return c;
118 #endif
119   
120   return 0;
121 }
122
123 int
124 Lilypond_context_key::get_type () const
125 {
126   return CONTEXT_KEY;
127 }