2 scm-hash.cc -- implement Scheme_hash_table
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "scm-hash.hh"
12 #include "ly-smobs.icc"
15 Scheme_hash_table::Scheme_hash_table ()
21 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
28 Scheme_hash_table::operator =(Scheme_hash_table const & src)
30 Scm_stl_map::operator = (src);
32 // we do not copy the self_scm () field!
39 Scheme_hash_table::mark_smob (SCM s)
42 can't typecheck naively, since GC bit lives in CAR of S
45 Scheme_hash_table *me = (Scheme_hash_table*) SCM_CELL_WORD_1(s);
47 for (Scm_stl_map::const_iterator i= me->begin (); i != me->end(); i++)
49 scm_gc_mark ((*i).first);
50 scm_gc_mark ((*i).second);
56 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
60 sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
62 Scheme_hash_table *me = unsmob(s);
63 for (Scm_stl_map::const_iterator i = me->begin (); i != me->end(); i++)
65 scm_display ((*i).first, p);
67 scm_display ((*i).second, p);
75 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
77 Scm_stl_map ::const_iterator i (find (k));
78 bool found = i != end ();
85 Scheme_hash_table::elem_b (SCM k) const
87 Scm_stl_map::const_iterator i (find (k));
92 Scheme_hash_table::set (SCM k, SCM v)
99 Scheme_hash_table::get (SCM k)const
101 return (*(Scheme_hash_table*)this)[k];
105 Scheme_hash_table::~Scheme_hash_table( )
110 Scheme_hash_table::to_alist () const
113 for (Scm_stl_map ::const_iterator i = begin (); i != end(); i++)
114 l = gh_cons (gh_cons ((*i).first, (*i).second), l);
120 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
121 IMPLEMENT_SMOBS(Scheme_hash_table);
122 IMPLEMENT_DEFAULT_EQUAL_P(Scheme_hash_table);