]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-key-manager.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[lilypond.git] / lily / context-key-manager.cc
1 /*
2   context-key-manager.cc -- implement Context_key_manager 
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "context-key-manager.hh"
11 #include "object-key.hh"
12 #include "lilypond-key.hh"
13 #include "main.hh"
14
15 Context_key_manager::Context_key_manager (Object_key const *key)
16 {
17   key_ = key;
18 }
19
20 void
21 Context_key_manager::unprotect () const
22 {
23   if (key_)
24     ((Object_key *)key_)->unprotect ();
25 }
26
27
28 Object_key const *
29 Context_key_manager::get_context_key (Moment now, string type, string id)
30 {
31   if (!use_object_keys)
32     return 0;
33
34   string now_key = type + "@" + id;
35
36   int disambiguation_count = 0;
37   if (context_counts_.find (now_key) != context_counts_.end ())
38     disambiguation_count = context_counts_[now_key];
39
40   context_counts_[now_key] = disambiguation_count + 1;
41
42   return new Lilypond_context_key (key (),
43                                    now,
44                                    type, id,
45                                    disambiguation_count);
46 }
47
48
49 Object_key const *
50 Context_key_manager::get_grob_key (Moment m, string name)
51 {
52   if (!use_object_keys)
53     return 0;
54
55   return create_grob_key (m, name);
56 }
57
58 /*
59   We want to have a key for some objects anyway, so we can invent a
60   unique identifier for each (book,score) tuple.
61 */
62 Object_key const *
63 Context_key_manager::create_grob_key (Moment now, string name)
64 {
65   int disambiguation_count = 0;
66   if (grob_counts_.find (name) != grob_counts_.end ())
67     disambiguation_count = grob_counts_[name];
68   grob_counts_[name] = disambiguation_count + 1;
69
70   Object_key *k = new Lilypond_grob_key (key (),
71                                          now,
72                                          name,
73                                          disambiguation_count);
74
75   return k;
76 }
77
78 void
79 Context_key_manager::gc_mark () const
80 {
81   if (key_)
82     scm_gc_mark (key_->self_scm ());
83
84 }
85
86 void
87 Context_key_manager::clear ()
88 {
89   if (!use_object_keys)
90     return;
91
92   grob_counts_.clear ();
93   context_counts_.clear ();
94 }
95
96 Context_key_manager::Context_key_manager (Context_key_manager const &src)
97 {
98   (void)src;
99   assert (false);
100 }