2 scm-hash.cc -- implement Scheme_hash_table
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "scm-hash.hh"
12 #include "hash-table-iter.hh"
14 Scheme_hash_table::Scheme_hash_table ()
16 hash_func_ = ly_scm_hash;
22 Scheme_hash_table::operator =(Scheme_hash_table const & src)
24 Hash_table<SCM,SCM>::operator = (src);
26 // we do not copy the self_scm_ field!
30 Scheme_hash_table::do_smobify_self ()
36 Scheme_hash_table::mark_smob (SCM s)
39 can't typecheck naively, since GC bit lives in CAR of S
41 //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
43 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
44 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
46 scm_gc_mark (i.key());
47 scm_gc_mark (i.val ());
53 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
54 : Hash_table<SCM,SCM> (src)
56 hash_func_ = src.hash_func_;
62 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
64 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
66 sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
68 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
69 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
71 scm_display (i.key(), p);
73 scm_display (i.val (), p);
82 Scheme_hash_table::set (SCM k, SCM v)
85 scm_unprotect_object (v);
89 Scheme_hash_table::get (SCM k)const
91 return const_elem (k);
95 Scheme_hash_table::~Scheme_hash_table( )
101 Scheme_hash_table::to_alist () const
104 for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
105 l = gh_cons (gh_cons (i.key (), i.val()), l);
110 #include "ly-smobs.icc"
111 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
112 IMPLEMENT_SMOBS(Scheme_hash_table);