lilypond-1.3.67
[lilypond.git] / lily / scm-hash.cc
blob98c430b3ebe7a3a3e9b788bf882f74016b40a241
1 /*
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>
8 */
9 #include <stdio.h>
11 #include "scm-hash.hh"
15 Scheme_hash_table::Scheme_hash_table ()
17 self_scm_ = SCM_EOL;
18 smobify_self ();
21 void
22 Scheme_hash_table::operator =(Scheme_hash_table const & src)
24 Scm_stl_map::operator = (src);
26 // we do not copy the self_scm_ field!
29 void
30 Scheme_hash_table::do_smobify_self ()
35 SCM
36 Scheme_hash_table::mark_smob (SCM s)
39 can't typecheck naively, since GC bit lives in CAR of S
42 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
44 for (Scm_stl_map::const_iterator i= me->begin (); i != me->end(); i++)
46 scm_gc_mark ((*i).first);
47 scm_gc_mark ((*i).second);
49 return SCM_EOL;
53 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
54 : Scm_stl_map (src)
56 self_scm_ = SCM_EOL;
57 smobify_self ();
60 int
61 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
63 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
64 char str[1000];
65 sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
66 scm_puts (str, p);
67 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
68 for (Scm_stl_map::const_iterator i = me->begin (); i != me->end(); i++)
70 scm_display ((*i).first, p);
71 scm_puts (" = ",p);
72 scm_display ((*i).second, p);
73 scm_puts ("\n",p);
75 scm_puts ("> ",p);
76 return 1;
79 bool
80 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
82 Scm_stl_map ::const_iterator i (find (k));
83 bool found = i != end ();
84 if (found)
85 *v = (*i).second;
86 return found;
89 bool
90 Scheme_hash_table::elem_b (SCM k) const
92 Scm_stl_map::const_iterator i (find (k));
93 return i != end ();
96 void
97 Scheme_hash_table::set (SCM k, SCM v)
99 (*this)[k] = v;
102 // UGH.
104 Scheme_hash_table::get (SCM k)const
106 return (*(Scheme_hash_table*)this)[k];
110 Scheme_hash_table::~Scheme_hash_table( )
112 unsmobify_self ();
116 Scheme_hash_table::to_alist () const
118 SCM l = SCM_EOL;
119 for (Scm_stl_map ::const_iterator i = begin (); i != end(); i++)
120 l = gh_cons (gh_cons ((*i).first, (*i).second), l);
121 return l;
125 #include "ly-smobs.icc"
126 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
127 IMPLEMENT_SMOBS(Scheme_hash_table);