X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=symtable.cc;h=5d295d0be5aafacf5eb41d5f015b2385198e8d39;hb=4fac7cb7f554ad08c06225c985c7ddbcee1006dc;hp=8b87e2fc99a893130426f1075878963f2efbdce5;hpb=727cdcbadf23c1986b0aed547aa645c9813f351b;p=lilypond.git diff --git a/symtable.cc b/symtable.cc index 8b87e2fc99..5d295d0be5 100644 --- a/symtable.cc +++ b/symtable.cc @@ -6,6 +6,20 @@ #include "symtable.hh" #include "const.hh" +static Symbol unknown; + + +// scary! What if Symtable resizes on the fly...? +const Symbol * +Symtable::lookup(String s) const +{ + if (elt_query(s)) + return &(*this)[s]; + else { + WARN<<"Unknown symbol " << s <<'\n'; + return &unknown; + } +} Symtable* Symtables::operator()(String s) @@ -53,25 +67,22 @@ Symtables the_sym_tables("symbol.ini"); const Symbol* -Symbol::find_ball(int i) +Symbol::find_ball(int j) { - int j = intlog2(i)+1; if (j > 4) j = 4; Symtable * st = the_sym_tables("balls"); - return &(*st)[String(j)]; - + return st->lookup(String(j)); } const Symbol* -Symbol::find_rest(int i) +Symbol::find_rest(int j) { - int j = intlog2(i)+1; - return &(*the_sym_tables("rests"))[String(j)]; + return the_sym_tables("rests")->lookup(String(j)); } const Symbol* Symbol::find_bar(String s) { - return &(*the_sym_tables("bars"))[s]; + return the_sym_tables("bars")->lookup(s); } /****************************************************************/ // bare bones.