lilypond-1.3.15
[lilypond.git] / lily / scm-hash.cc
blob4d417416f15ca4226394d99bb8292a8e29dd23d4
1 /*
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>
8 */
10 #include "scm-hash.hh"
11 #include "hash-table-iter.hh"
13 Scheme_hash_table::Scheme_hash_table ()
15 hash_func_ = ly_scm_hash;
16 self_scm_ = SCM_EOL;
17 smobify_self ();
20 void
21 Scheme_hash_table::operator =(Scheme_hash_table const & src)
23 Hash_table<SCM,SCM>::operator = (src);
25 // we do not copy the self_scm_ field!
28 void
29 Scheme_hash_table::do_smobify_self ()
33 #include "ly-smobs.icc"
34 IMPLEMENT_SMOBS(Scheme_hash_table);
36 SCM
37 Scheme_hash_table::mark_smob (SCM s)
40 can't typecheck naively, since GC bit lives in CAR of S
42 //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
44 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
45 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
47 scm_gc_mark (i.key());
48 scm_gc_mark (i.val ());
50 return SCM_EOL;
54 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
55 : Hash_table<SCM,SCM> (src)
57 hash_func_ = src.hash_func_;
58 self_scm_ = SCM_EOL;
59 smobify_self ();
62 int
63 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
65 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
66 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
67 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
69 scm_display (i.key(), p);
70 scm_puts (" = ",p);
71 scm_display (i.val (), p);
72 scm_puts ("\n",p);
74 return 1;
80 Scheme_hash_table::~Scheme_hash_table( )
82 unsmobify_self ();
85 SCM
86 Scheme_hash_table::to_alist () const
88 SCM l = SCM_EOL;
89 for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
90 l = gh_cons (gh_cons (i.key (), i.val()), l);
91 return l;