lilypond-1.3.28
[lilypond.git] / lily / scm-hash.cc
blobe864d60875993f4168232cf5fcdff9e931211c20
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 */
9 #include <stdio.h>
11 #include "scm-hash.hh"
12 #include "hash-table-iter.hh"
14 Scheme_hash_table::Scheme_hash_table ()
16 hash_func_ = ly_scm_hash;
17 self_scm_ = SCM_EOL;
18 smobify_self ();
21 void
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!
29 void
30 Scheme_hash_table::do_smobify_self ()
34 #include "ly-smobs.icc"
35 IMPLEMENT_SMOBS(Scheme_hash_table);
37 SCM
38 Scheme_hash_table::mark_smob (SCM s)
41 can't typecheck naively, since GC bit lives in CAR of S
43 //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
45 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
46 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
48 scm_gc_mark (i.key());
49 scm_gc_mark (i.val ());
51 return SCM_EOL;
55 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
56 : Hash_table<SCM,SCM> (src)
58 hash_func_ = src.hash_func_;
59 self_scm_ = SCM_EOL;
60 smobify_self ();
63 int
64 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
66 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
67 char str[1000];
68 sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
69 scm_puts (str, p);
70 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
71 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
73 scm_display (i.key(), p);
74 scm_puts (" = ",p);
75 scm_display (i.val (), p);
76 scm_puts ("\n",p);
78 scm_puts ("> ",p);
79 return 1;
83 void
84 Scheme_hash_table::set (SCM k, SCM v)
86 elem (k ) = v;
87 scm_unprotect_object (v);
90 SCM
91 Scheme_hash_table::get (SCM k)const
93 return const_elem (k);
97 Scheme_hash_table::~Scheme_hash_table( )
99 unsmobify_self ();
103 Scheme_hash_table::to_alist () const
105 SCM l = SCM_EOL;
106 for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
107 l = gh_cons (gh_cons (i.key (), i.val()), l);
108 return l;