Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(291)

Unified Diff: lily/translator-ctors.cc

Issue 298830043: Create Translator_creator class (Closed)
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lily/translator.cc ('k') | lily/translator-group.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lily/translator-ctors.cc
diff --git a/lily/translator-ctors.cc b/lily/translator-ctors.cc
index 67fa95a610b139608d94482ae54d6afb202221b3..2ff3e5418ab22a61b151bb93b72567d674d2eb0b 100644
--- a/lily/translator-ctors.cc
+++ b/lily/translator-ctors.cc
@@ -24,9 +24,30 @@
#include "warn.hh"
#include "protected-scm.hh"
-/*
- should delete these after exit.
-*/
+const char * const Translator_creator::type_p_name_ = 0;
+
+SCM
+Translator_creator::mark_smob () const
+{
+ scm_gc_mark (name_);
+ scm_gc_mark (description_);
+ return listener_list_;
+}
+
+Translator *
+Translator_creator::get_translator (Context *c)
+{
+ return allocate_ (this, c);
+}
+
+Translator_creator::Translator_creator (SCM name, SCM description, SCM listener_list,
+ Translator * (*allocate)
+ (Translator_creator const *, Context *))
+ : name_ (name), description_ (description), listener_list_ (listener_list),
+ allocate_ (allocate)
+{
+ smobify_self ();
+}
Protected_scm global_translator_dict;
@@ -37,14 +58,18 @@ LY_DEFINE (get_all_translators, "ly:get-all-translators", 0, 0, 0, (),
Scheme_hash_table *dict = unsmob<Scheme_hash_table> (global_translator_dict);
SCM l = dict ? dict->to_alist () : SCM_EOL;
+ // Ok, this is a bit of a crutch: so far, the Scheme code base has
+ // no idea about the Translator_creator type and uses of
+ // ly:get-all-translators rely on the output being translators.
for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
- scm_set_car_x (s, scm_cdar (s));
+ scm_set_car_x (s, unsmob <Translator_creator> (scm_cdar (s))
+ ->get_translator (0)->unprotect ());
return l;
}
void
-add_translator (Translator *t)
+add_translator_creator (Translator_creator *t)
{
Scheme_hash_table *dict = unsmob<Scheme_hash_table> (global_translator_dict);
if (!dict)
@@ -53,12 +78,11 @@ add_translator (Translator *t)
dict = unsmob<Scheme_hash_table> (global_translator_dict);
}
- SCM k = ly_symbol2scm (t->class_name ());
- dict->set (k, t->unprotect ());
+ dict->set (t->get_name (), t->unprotect ());
}
-Translator *
-get_translator (SCM sym)
+Translator_creator *
+get_translator_creator (SCM sym)
{
SCM v = SCM_BOOL_F;
Scheme_hash_table *dict = unsmob<Scheme_hash_table> (global_translator_dict);
@@ -71,5 +95,5 @@ get_translator (SCM sym)
return 0;
}
- return unsmob<Translator> (v);
+ return unsmob<Translator_creator> (v);
}
« no previous file with comments | « lily/translator.cc ('k') | lily/translator-group.cc » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b