]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-hash.cc
patch::: 1.3.74.gp1
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include <stdio.h>
10
11 #include "scm-hash.hh"
12 #include "ly-smobs.icc"
13
14
15
16 Scheme_hash_table::Scheme_hash_table ()
17 {
18   smobify_self ();
19 }
20
21
22 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
23   : Scm_stl_map (src)
24 {
25   smobify_self ();
26 }
27
28 void
29 Scheme_hash_table::operator =(Scheme_hash_table const & src)
30 {
31   Scm_stl_map::operator = (src);
32         
33   // we do not copy the self_scm () field!
34 }
35
36
37
38
39 SCM
40 Scheme_hash_table::mark_smob (SCM s)
41 {
42   /*
43     can't typecheck naively, since GC bit lives in CAR of S
44    */
45   
46   Scheme_hash_table *me = (Scheme_hash_table*) SCM_CELL_WORD_1(s);
47
48   for (Scm_stl_map::const_iterator i= me->begin (); i != me->end(); i++)
49     {
50       scm_gc_mark ((*i).first);
51       scm_gc_mark ((*i).second);
52     }
53   return SCM_EOL;
54 }
55
56 int
57 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
58 {
59   assert (unsmob (s));
60   char str[1000];
61   sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
62   scm_puts (str, p);      
63   Scheme_hash_table *me = unsmob(s);
64   for (Scm_stl_map::const_iterator i = me->begin (); i != me->end(); i++)
65     {
66       scm_display ((*i).first, p);
67       scm_puts (" = ",p);      
68       scm_display ((*i).second, p);
69       scm_puts ("\n",p);            
70     }
71   scm_puts ("> ",p);        
72   return 1;
73 }
74
75 bool
76 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
77 {
78   Scm_stl_map ::const_iterator i (find (k));
79   bool found = i != end ();
80   if (found)
81     *v = (*i).second;
82   return found;
83 }
84
85 bool
86 Scheme_hash_table::elem_b (SCM k) const
87 {
88   Scm_stl_map::const_iterator i (find (k));
89   return i != end ();
90 }
91
92 void
93 Scheme_hash_table::set (SCM k, SCM v)
94 {
95   (*this)[k] = v;
96 }
97
98 // UGH. 
99 SCM
100 Scheme_hash_table::get (SCM k)const
101 {
102   return (*(Scheme_hash_table*)this)[k]; 
103 }
104
105
106 Scheme_hash_table::~Scheme_hash_table( )
107 {
108 }
109
110 SCM
111 Scheme_hash_table::to_alist () const
112 {
113   SCM l = SCM_EOL;
114   for (Scm_stl_map ::const_iterator i = begin (); i != end(); i++)
115     l = gh_cons (gh_cons ((*i).first, (*i).second), l);
116   return l;  
117 }
118
119
120 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
121 IMPLEMENT_SMOBS(Scheme_hash_table);
122 IMPLEMENT_DEFAULT_EQUAL_P(Scheme_hash_table);
123
124