]> git.donarmstrong.com Git - lilypond.git/blob - lily/listener.cc
Issue 4360: Reorganize smob initialization to make it more reliable
[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 "warn.hh"
22
23 ADD_SMOB_INIT (Listener);
24
25 Listener::Listener ()
26 {
27   target_ = 0;
28   type_ = 0;
29 }
30
31 Listener::Listener (const void *target, Listener_function_table *type)
32 {
33   target_ = (void *)target;
34   type_ = type;
35 }
36
37 Listener::Listener (Listener const &other)
38 {
39   target_ = other.target_;
40   type_ = other.type_;
41 }
42
43 void Listener::listen (SCM ev) const
44 {
45   (type_->listen_callback) (target_, ev);
46 }
47
48 SCM
49 Listener::mark_smob ()
50 {
51   if (type_)
52     (type_->mark_callback) (target_);
53   return SCM_EOL;
54 }
55
56 SCM
57 Listener::equal_p (SCM a, SCM b)
58 {
59   Listener *l1 = Listener::unsmob (a);
60   Listener *l2 = Listener::unsmob (b);
61
62   return (*l1 == *l2) ? SCM_BOOL_T : SCM_BOOL_F;
63 }
64
65 const char Listener::type_p_name_[] = "ly:listener?";