2 context-selector.cc -- implement Context selection.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "context-selector.hh"
11 #include "scm-hash.hh"
13 Scheme_hash_table *Context_selector::contexts_ = 0;
16 Context_selector::register_context (Context *context)
19 contexts_ = new Scheme_hash_table ();
21 if (Context *first = retrieve_context (identify_context (context, 0)))
23 count = robust_scm2int (first->get_property ("max"), 0);
25 SCM s = scm_int2num (count);
26 first->set_property ("max", s);
27 context->set_property ("count", s);
29 /* FIXME: must alway set count, for get_property () not to segfault. */
30 context->set_property ("count", scm_int2num (count));
31 store_context (identify_context (context, count), context);
35 Context_selector::identify_context (Context *context, int count)
37 /* TODO: start time, parent-context-at-start */
38 return scm_list_3 (scm_makfrom0str (context->context_name ().to_str0 ()),
39 scm_makfrom0str (context->id_string ().to_str0 ()),
44 Context_selector::identify_context (Context *context)
47 identify_context (context,
48 robust_scm2int (context->get_property ("count"), 0));
52 Context_selector::store_context (SCM context_id, Context *context)
54 contexts_->set (ly_to_symbol (context_id), context->self_scm ());
58 Context_selector::retrieve_context (SCM context_id)
60 return unsmob_context (contexts_->get (ly_to_symbol (context_id)));