]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-hash.cc
release: 1.3.0
[lilypond.git] / lily / scm-hash.cc
1 /*   
2   scm-hash.cc --  implement Scheme_hash_table
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "scm-hash.hh"
11 #include "hash-table-iter.hh"
12
13 Scheme_hash_table::Scheme_hash_table ()
14 {
15   hash_func_ = ly_scm_hash;
16   self_scm_ = SCM_EOL;
17   smobify_self ();
18 }
19
20 void
21 Scheme_hash_table::operator =(Scheme_hash_table const & src)
22 {
23   Hash_table<SCM,SCM>::operator = (src);
24         
25   // we do not copy the self_scm_ field!
26 }
27
28 void
29 Scheme_hash_table::do_smobify_self ()
30 {
31 }
32
33 #include "ly-smobs.icc"
34 IMPLEMENT_SMOBS(Scheme_hash_table);
35
36 SCM
37 Scheme_hash_table::mark_smob (SCM s)
38 {
39   /*
40     can't typecheck naively, since GC bit lives in CAR of S
41    */
42   //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
43   
44   Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
45   for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
46     {
47       scm_gc_mark (i.key());
48       scm_gc_mark (i.val ());
49     }
50   return SCM_EOL;
51 }
52
53
54 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
55   : Hash_table<SCM,SCM> (src)
56 {
57   hash_func_ = src.hash_func_;
58   self_scm_ = SCM_EOL;
59   smobify_self ();
60 }
61
62 int
63 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*ps)
64 {
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++)
68     {
69       scm_display (i.key(), p);
70       scm_puts (" = ",p);      
71       scm_display (i.val (), p);
72       scm_puts ("\n",p);            
73     }
74   return 1;
75 }
76
77
78
79
80 Scheme_hash_table::~Scheme_hash_table( )
81 {
82   unsmobify_self ();
83 }
84
85 SCM
86 Scheme_hash_table::to_alist () const
87 {
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;  
92 }
93