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