]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 1.1.29
[lilypond.git] / lily / atom.cc
1 /*
2   atom.cc -- implement Atom
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "atom.hh"
10 #include "interval.hh"
11 #include "string.hh"
12 #include "array.hh"
13 #include "debug.hh"
14 #include "dimensions.hh"
15 #include "lookup.hh"
16 #include "main.hh"
17 #include "global-ctor.hh"
18
19 Atom::Atom(SCM s)
20 {
21   func_ = s;
22 }
23
24
25 #if 0
26 int
27 Atom::smob_display (SCM smob, SCM port, scm_print_state*)
28 {
29   Atom* a =(Atom*) SCM_CDR(smob);
30   String i (a->off_.str ());
31   
32   scm_puts ("#<Atom ", port);
33   scm_puts (i.ch_C(), port);
34   gh_display (a->func_);
35   scm_puts (">", port);
36
37   /* non-zero means success */
38   return 1;
39 }
40
41
42 scm_sizet
43 Atom::smob_free (SCM smob)
44 {
45   Atom * a= (Atom*) SCM_CDR(smob);
46   delete a;
47   return sizeof (Atom);
48 }
49
50 SCM
51 Atom::smob_mark (SCM smob) 
52 {
53   Atom * a= (Atom*) SCM_CDR(smob);
54   scm_gc_mark (a->func_);
55   return a->font_;
56 }
57
58 long Atom::smob_tag_;
59
60 void
61 Atom::init_smob ()
62 {
63   static scm_smobfuns type_rec;
64
65   type_rec.mark = smob_mark;
66   type_rec.free = smob_free;
67   type_rec.print = smob_display;
68   type_rec.equalp = 0;
69
70   smob_tag_ = scm_newsmob (&type_rec);
71 }
72
73
74 SCM
75 Atom::make_smob () const
76 {
77   SCM smob;
78   SCM_NEWCELL (smob);
79   SCM_SETCAR (smob, smob_tag_);
80   SCM_SETCDR (smob, this);
81   return smob;
82 }
83
84 SCM
85 Atom::make_atom (SCM outputfunc)
86 {
87   Atom * a= new Atom(outputfunc);
88   return a->make_smob ();
89 }
90
91 SCM
92 Atom::copy_self () const
93 {
94   return (new Atom (*this))->make_smob ();
95 }
96
97 bool
98 Atom::Atom_b (SCM obj)
99 {
100   return(SCM_NIMP(obj) && SCM_CAR(obj) == smob_tag_);
101 }
102
103 Atom* 
104 Atom::atom_l (SCM a)
105 {
106   assert (Atom_b (a));
107   return (Atom*) SCM_CDR(a);
108 }
109
110
111 ADD_GLOBAL_CTOR_WITHNAME(atomsmob, Atom::init_smob);
112 #endif
113
114