#include "translator-group.hh"
#include "translator.hh"
#include "debug.hh"
-#include "pcursor.hh"
-#include "rational.hh"
+#include "moment.hh"
#include "dictionary-iter.hh"
+#include "killing-cons.tcc"
+
Translator_group::Translator_group (Translator_group const&s)
: Translator(s)
{
consists_str_arr_ = s.consists_str_arr_;
+ consists_end_str_arr_ = s.consists_end_str_arr_;
accepts_str_arr_ = s.accepts_str_arr_;
iterator_count_ =0;
properties_dict_ = s.properties_dict_;
-
}
Translator_group::~Translator_group ()
{
assert (removable_b());
+ trans_p_list_.junk ();
}
}
}
-
-
-
-
void
Translator_group::add_translator (Translator *trans_p)
{
- trans_p_list_.bottom().add (trans_p);
+ trans_p_list_.append (new Killing_cons<Translator> (trans_p,0));
+
trans_p->daddy_trans_l_ = this;
trans_p->output_def_l_ = output_def_l_;
trans_p->add_processing ();
accepts_str_arr_.del (i);
}
+void
+Translator_group::add_last_element (String s)
+{
+ if (!get_translator_l (s))
+ error (_ ("Program has no such type"));
+
+ for (int i=consists_end_str_arr_.size (); i--; )
+ if (consists_end_str_arr_[i] == s)
+ warning (_f ("Already contains: `%s'", s));
+
+ consists_end_str_arr_.push (s);
+}
+
void
Translator_group::set_element (String s, bool add)
{
if (!get_translator_l (s))
- error ("Program has no such type");
+ error (_ ("Program has no such type"));
if (add)
- consists_str_arr_.push (s);
+ {
+ for (int i=consists_str_arr_.size (); i--; )
+ if (consists_str_arr_[i] == s)
+ warning (_f("Already contains: `%s'", s));
+
+ consists_str_arr_.push (s);
+ }
else
- for (int i=consists_str_arr_.size (); i--; )
- if (consists_str_arr_[i] == s)
- consists_str_arr_.del (i);
+ {
+ for (int i=consists_str_arr_.size (); i--; )
+ if (consists_str_arr_[i] == s)
+ consists_str_arr_.del (i);
+ for (int i=consists_end_str_arr_.size (); i--; )
+ if (consists_end_str_arr_[i] == s)
+ consists_end_str_arr_.del (i);
+ }
}
-
bool
Translator_group::removable_b() const
{
- for (PCursor<Translator*> i (trans_p_list_.top ()); i.ok (); i++)
+ for (Cons<Translator> *p = trans_p_list_.head_; p; p = p->next_)
{
- if (dynamic_cast <Translator_group *> (i.ptr ()))
+ if (dynamic_cast <Translator_group *> (p->car_))
return false;
}
ret = daddy_trans_l_->find_create_translator_l (n,id);
else
{
- warning (_f ("can't find or create `%s\' called `%s\'", n, id));
+ warning (_f ("Can't find or create `%s' called `%s'", n, id));
ret =0;
}
return ret;
}
-
bool
-Translator_group::do_try_music (Music* req_l)
+Translator_group::try_music_on_nongroup_children (Music *m)
{
bool hebbes_b =false;
Link_array<Translator> nongroups (nongroup_l_arr ());
for (int i =0; !hebbes_b && i < nongroups.size() ; i++)
- hebbes_b =nongroups[i]->try_music (req_l);
+ hebbes_b =nongroups[i]->try_music (m);
+ return hebbes_b;
+}
+
+bool
+Translator_group::do_try_music (Music* m)
+{
+ bool hebbes_b = try_music_on_nongroup_children (m);
+
if (!hebbes_b && daddy_trans_l_)
- hebbes_b = daddy_trans_l_->try_music (req_l);
+ hebbes_b = daddy_trans_l_->try_music (m);
return hebbes_b ;
}
Translator_group::group_l_arr () const
{
Link_array<Translator_group> groups;
- for (PCursor<Translator*> i (trans_p_list_.top ()); i.ok (); i++)
+ for (Cons<Translator> *p = trans_p_list_.head_; p; p = p->next_)
{
- if (dynamic_cast <Translator_group *> (i.ptr ()))
- groups.push (dynamic_cast <Translator_group *> (i.ptr ()));
+ if (dynamic_cast <Translator_group *> (p->car_))
+ groups.push (dynamic_cast <Translator_group *> (p->car_));
}
return groups;
}
Translator_group::nongroup_l_arr () const
{
Link_array<Translator> groups;
- for (PCursor<Translator*> i (trans_p_list_.top ()); i.ok (); i++)
+ for (Cons<Translator> *p = trans_p_list_.head_; p; p = p->next_)
{
- if (!dynamic_cast <Translator_group *> (i.ptr ()))
- groups.push (i.ptr ());
+ if (!dynamic_cast <Translator_group *> (p->car_))
+ groups.push (p->car_);
}
return groups;
}
+/**
+ End translator: call "destructor", remove from hierarchy, and delete
+ */
void
Translator_group::terminate_translator (Translator*r_l)
{
- DOUT << "Removing " << classname (r_l) << " at " << now_mom () << '\n';
+ DEBUG_OUT << "Removing " << classname (r_l) << " at " << now_mom () << '\n';
r_l->removal_processing();
Translator * trans_p =remove_translator_p (r_l);
delete trans_p;
}
+
+/**
+ Remove a translator from the hierarchy.
+ */
Translator *
Translator_group::remove_translator_p (Translator*trans_l)
{
assert (trans_l);
- PCursor<Translator*> trans_cur (trans_p_list_.find (trans_l));
- Translator * t = trans_cur.remove_p();
- /*
- For elegant design, we would do this too. Alas, it does not work yet..
+ for (Cons<Translator> **pp = &trans_p_list_.head_; *pp; pp = &(*pp)->next_)
+ if ((*pp)->car_ == trans_l)
+ {
+ Cons<Translator> *r = trans_p_list_.remove_cons (pp);
+ r->car_ =0;
+ trans_l->daddy_trans_l_ =0;
+ delete r;
+ return trans_l;
+ }
- t-> removal_processing ();
- */
- t-> daddy_trans_l_ = 0;
- return t;
+ return 0;
}
Translator*t = output_def_l ()->find_translator_l (accepts_str_arr_[0]);
if (!t)
{
- warning (_f ("can't find or create `%s\'", accepts_str_arr_[0]));
+ warning (_f ("Can't find or create: `%s'", accepts_str_arr_[0]));
t = this;
}
Translator_group * g= dynamic_cast <Translator_group*>(t->clone ());
void
Translator_group::each (Method_pointer method)
{
- for (PCursor<Translator*> i (trans_p_list_.top ()); i.ok (); i++)
- (i.ptr()->*method) ();
+ for (Cons<Translator> *p = trans_p_list_.head_; p; p = p->next_)
+ (p->car_->*method) ();
}
+
void
Translator_group::each (Const_method_pointer method) const
{
- for (PCursor<Translator*> i (trans_p_list_.top ()); i.ok (); i++)
- (i.ptr()->*method) ();
+ for (Cons<Translator> *p = trans_p_list_.head_; p; p = p->next_)
+ (p->car_->*method) ();
}
void
Translator_group::do_print() const
{
#ifndef NPRINT
- if (!check_debug)
+ if (!flower_dstream)
return ;
- for (Dictionary_iter<Scalar> i (properties_dict_); i.ok (); i++)
- {
- DOUT << i.key () << "=" << i.val () << '\n';
- }
+
+ gh_display (properties_dict_.self_scm_);
if (status == ORPHAN)
{
- DOUT << "consists of: ";
+ DEBUG_OUT << "consists of: ";
for (int i=0; i < consists_str_arr_.size (); i++)
- DOUT << consists_str_arr_[i] << ", ";
- DOUT << "\naccepts: ";
+ DEBUG_OUT << consists_str_arr_[i] << ", ";
+ DEBUG_OUT << "\naccepts: ";
for (int i=0; i < accepts_str_arr_.size (); i++)
- DOUT << accepts_str_arr_[i] << ", ";
+ DEBUG_OUT << accepts_str_arr_[i] << ", ";
}
else
{
if (id_str_.length_i ())
- DOUT << "ID: " << id_str_ ;
- DOUT << " iterators: " << iterator_count_<< '\n';
+ DEBUG_OUT << "ID: " << id_str_ ;
+ DEBUG_OUT << " iterators: " << iterator_count_<< '\n';
}
each (&Translator::print);
#endif
{
for (int i=0; i < consists_str_arr_.size(); i++)
{
- Translator * t = output_def_l ()->find_translator_l (consists_str_arr_[i]);
+ String s = consists_str_arr_[i];
+ Translator * t = output_def_l ()->find_translator_l (s);
if (!t)
- warning (_f ("can't find `%s\'", consists_str_arr_[i]));
+ warning (_f ("Can't find: `%s'", s));
else
add_translator (t->clone ());
}
+ for (int i=0; i-- < consists_end_str_arr_.size (); i++)
+ {
+ String s = consists_end_str_arr_[i];
+ Translator * t = output_def_l ()->find_translator_l (s);
+ if (!t)
+ warning (_f ("Can't find: `%s'", s));
+ else
+ add_translator (t->clone ());
+ }
}
-Scalar
-Translator_group::get_property (String id, Translator_group **where_l) const
+SCM
+Translator_group::get_property (String id,
+ Translator_group **where_l) const
{
- if (properties_dict_.elem_b (id))
+ SCM sym = ly_symbol (id);
+ if (properties_dict_.elem_b (sym))
{
if (where_l)
- *where_l = this;
- return properties_dict_[id];
+ *where_l = (Translator_group*) this; // ugh
+ return properties_dict_[sym];
}
-
+
if (daddy_trans_l_)
return daddy_trans_l_->get_property (id, where_l);
-
+
if (where_l)
*where_l = 0;
- return "";
+
+ return SCM_UNDEFINED;
}
void
-Translator_group::set_property (String id, Scalar val)
+Translator_group::set_property (String id, SCM val)
{
- properties_dict_[id] = val;
+ properties_dict_[ly_symbol (id)] = val;
}