]> git.donarmstrong.com Git - lilypond.git/blob - lily/object-key.cc
* lily/context.cc (Context): take key argument in ctor.
[lilypond.git] / lily / object-key.cc
1 /*
2   object-key.cc --  implement Object_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 "ly-smobs.icc"
13
14 SCM
15 Object_key::mark_smob (SCM key)
16 {
17   Object_key* k = (Object_key*) SCM_CELL_WORD_1 (key);
18   k->derived_mark();
19   return SCM_EOL;
20 }
21
22 void
23 Object_key::derived_mark () const
24 {
25   
26 }
27
28 Object_key::~Object_key()
29 {
30 }
31
32 int
33 Object_key::get_type () const
34 {
35   return GENERAL_KEY;
36 }
37
38 int
39 Object_key::print_smob (SCM smob, SCM port, scm_print_state*)
40 {
41   return 1;
42 }
43
44 Object_key::Object_key ()
45 {
46   smobify_self ();
47 }
48
49 int
50 Object_key::compare (Object_key const *other) const
51 {
52   if (this == other)
53     return 0;
54   
55   int c = sign (get_type () -  other->get_type());
56   if (c)
57     return c;
58   else
59     return do_compare (other);
60 }
61
62 IMPLEMENT_SMOBS (Object_key);
63
64 SCM
65 Object_key::equal_p (SCM a , SCM b) 
66 {
67   Object_key *ka = unsmob_key (a);
68   Object_key *kb = unsmob_key (b);
69   
70   return (ka->compare (kb)) ? SCM_BOOL_F : SCM_BOOL_T;
71 }
72
73 int
74 Object_key::do_compare (Object_key const *other) const
75 {
76   return 0;
77 }
78
79 /****************************************************************/
80
81 Copied_key::Copied_key (Object_key const* key, int count)
82 {
83   copy_count_ = count;
84   original_ = key;
85 }
86
87 int
88 Copied_key::get_type () const
89 {
90   return COPIED_KEY;
91 }
92
93 int
94 Copied_key::do_compare (Object_key const *key) const
95 {
96   Copied_key const *other = dynamic_cast<Copied_key const*> (key);
97   
98   int c = original_->compare (other->original_);
99   if (c)
100     return c;
101
102   return sign (copy_count_ - other->copy_count_);
103 }
104
105 void
106 Copied_key::derived_mark () const
107 {
108   scm_gc_mark (original_->self_scm ());
109 }