]> git.donarmstrong.com Git - lilypond.git/blob - lily/listener.cc
Imported Upstream version 2.14.2
[lilypond.git] / lily / listener.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005 Erik Sandberg  <mandolaerik@gmail.com>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "listener.hh"
21 #include "ly-smobs.icc"
22 #include "warn.hh"
23
24 Listener::Listener ()
25 {
26   target_ = 0;
27   type_ = 0;
28 }
29
30 Listener::Listener (const void *target, Listener_function_table *type)
31 {
32   target_ = (void *)target;
33   type_ = type;
34 }
35
36 Listener::Listener (Listener const &other)
37 {
38   target_ = other.target_;
39   type_ = other.type_; 
40 }
41
42 void Listener::listen (SCM ev) const {
43   (type_->listen_callback) (target_, ev);
44 }
45
46 SCM
47 Listener::mark_smob (SCM sm)
48 {
49   Listener *me = (Listener *) SCM_CELL_WORD_1 (sm);
50   if (me->type_)
51     (me->type_->mark_callback) (me->target_);
52   return SCM_EOL;
53 }
54
55 int
56 Listener::print_smob (SCM, SCM p, scm_print_state*)
57 {
58   scm_puts ("#<Listener>", p);
59   return 1;
60 }
61
62 SCM
63 Listener::equal_p (SCM a, SCM b)
64 {
65   Listener *l1 = unsmob_listener (a);
66   Listener *l2 = unsmob_listener (b);
67
68   return (*l1 == *l2) ? SCM_BOOL_T : SCM_BOOL_F;
69 }
70
71 IMPLEMENT_SIMPLE_SMOBS (Listener);
72 IMPLEMENT_TYPE_P (Listener, "ly:listener?");