]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-hash.cc
patch::: 1.3.26.hwn3
[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 #include <stdio.h>
10
11 #include "scm-hash.hh"
12 #include "hash-table-iter.hh"
13
14 Scheme_hash_table::Scheme_hash_table ()
15 {
16   hash_func_ = ly_scm_hash;
17   self_scm_ = SCM_EOL;
18   smobify_self ();
19 }
20
21 void
22 Scheme_hash_table::operator =(Scheme_hash_table const & src)
23 {
24   Hash_table<SCM,SCM>::operator = (src);
25         
26   // we do not copy the self_scm_ field!
27 }
28
29 void
30 Scheme_hash_table::do_smobify_self ()
31 {
32 }
33
34 #include "ly-smobs.icc"
35 IMPLEMENT_SMOBS(Scheme_hash_table);
36
37 SCM
38 Scheme_hash_table::mark_smob (SCM s)
39 {
40   /*
41     can't typecheck naively, since GC bit lives in CAR of S
42    */
43   //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
44   
45   Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
46   for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
47     {
48       scm_gc_mark (i.key());
49       scm_gc_mark (i.val ());
50     }
51   return SCM_EOL;
52 }
53
54
55 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
56   : Hash_table<SCM,SCM> (src)
57 {
58   hash_func_ = src.hash_func_;
59   self_scm_ = SCM_EOL;
60   smobify_self ();
61 }
62
63 int
64 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
65 {
66   assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
67   char str[1000];
68   sprintf (str, "#<Scheme_hash_table 0x%0ulx ", 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++)
72     {
73       scm_display (i.key(), p);
74       scm_puts (" = ",p);      
75       scm_display (i.val (), p);
76       scm_puts ("\n",p);            
77     }
78   scm_puts ("> ",p);        
79   return 1;
80 }
81
82
83 void
84 Scheme_hash_table::set (SCM k, SCM v)
85 {
86   elem (k ) = v; 
87   scm_unprotect_object (v);
88 }
89
90 SCM
91 Scheme_hash_table::get (SCM k)
92 {
93   return elem (k);
94 }
95
96
97 Scheme_hash_table::~Scheme_hash_table( )
98 {
99   unsmobify_self ();
100 }
101
102 SCM
103 Scheme_hash_table::to_alist () const
104 {
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;  
109 }
110