]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-hash.cc
lilypond-1.3.29
[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
35 SCM
36 Scheme_hash_table::mark_smob (SCM s)
37 {
38   /*
39     can't typecheck naively, since GC bit lives in CAR of S
40    */
41   //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
42   
43   Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
44   for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
45     {
46       scm_gc_mark (i.key());
47       scm_gc_mark (i.val ());
48     }
49   return SCM_EOL;
50 }
51
52
53 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
54   : Hash_table<SCM,SCM> (src)
55 {
56   hash_func_ = src.hash_func_;
57   self_scm_ = SCM_EOL;
58   smobify_self ();
59 }
60
61 int
62 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
63 {
64   assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
65   char str[1000];
66   sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
67   scm_puts (str, p);      
68   Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
69   for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
70     {
71       scm_display (i.key(), p);
72       scm_puts (" = ",p);      
73       scm_display (i.val (), p);
74       scm_puts ("\n",p);            
75     }
76   scm_puts ("> ",p);        
77   return 1;
78 }
79
80
81 void
82 Scheme_hash_table::set (SCM k, SCM v)
83 {
84   elem (k ) = v; 
85   scm_unprotect_object (v);
86 }
87
88 SCM
89 Scheme_hash_table::get (SCM k)const
90 {
91   return const_elem (k);
92 }
93
94
95 Scheme_hash_table::~Scheme_hash_table( )
96 {
97   unsmobify_self ();
98 }
99
100 SCM
101 Scheme_hash_table::to_alist () const
102 {
103   SCM l = SCM_EOL;
104   for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
105     l = gh_cons (gh_cons (i.key (), i.val()), l);
106   return l;  
107 }
108
109
110 #include "ly-smobs.icc"
111 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
112 IMPLEMENT_SMOBS(Scheme_hash_table);