]> git.donarmstrong.com Git - lilypond.git/blob - lily/listener.cc
c8202a9d345d6ef8d9d0fabe066d688cd380a5e6
[lilypond.git] / lily / listener.cc
1 /*
2   listener.cc -- implement Listener and Listener_target
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Erik Sandberg  <mandolaerik@gmail.com>
7 */
8
9 #include "listener.hh"
10 #include "ly-smobs.icc"
11 #include "warn.hh"
12
13 Listener::Listener ()
14 {
15   target_ = 0;
16   type_ = 0;
17 }
18
19 Listener::Listener (const void *target, Listener_function_table *type)
20 {
21   target_ = (void *)target;
22   type_ = type;
23 }
24
25 Listener::Listener (Listener const &other)
26 {
27   target_ = other.target_;
28   type_ = other.type_; 
29 }
30
31 void Listener::listen (SCM ev) const {
32   (type_->listen_callback) (target_, ev);
33 }
34
35 SCM
36 Listener::mark_smob (SCM sm)
37 {
38   Listener *me = (Listener *) SCM_CELL_WORD_1 (sm);
39   if (me->type_)
40     (me->type_->mark_callback) (me->target_);
41   return SCM_EOL;
42 }
43
44 int
45 Listener::print_smob (SCM, SCM p, scm_print_state*)
46 {
47   scm_puts ("#<Listener>", p);
48   return 1;
49 }
50
51 SCM
52 Listener::equal_p (SCM a, SCM b)
53 {
54   Listener *l1 = unsmob_listener (a);
55   Listener *l2 = unsmob_listener (b);
56
57   return (*l1 == *l2) ? SCM_BOOL_T : SCM_BOOL_F;
58 }
59
60 IMPLEMENT_SIMPLE_SMOBS (Listener);
61 IMPLEMENT_TYPE_P (Listener, "listener");