]> git.donarmstrong.com Git - lilypond.git/blob - lily/undead.cc
Issue 4135/2: Replace mark_smob static member functions with non-static members
[lilypond.git] / lily / undead.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 "smobs.hh"
21
22 class Undead : public Simple_smob<Undead>
23 {
24 public:
25   static int print_smob (SCM, SCM, scm_print_state *);
26   SCM mark_smob ();
27   static const char type_p_name_[];
28 private:
29   SCM object_;
30 public:
31   SCM object () { return object_; }
32   Undead (SCM object = SCM_UNDEFINED) : object_ (object) { };
33 };
34
35 SCM
36 Undead::mark_smob ()
37 {
38   bool saved = parsed_objects_should_be_dead;
39   parsed_objects_should_be_dead = false;
40   scm_gc_mark (object ());
41   parsed_objects_should_be_dead = saved;
42   return SCM_UNDEFINED;
43 }
44
45 int
46 Undead::print_smob (SCM undead,
47                     SCM port,
48                     scm_print_state *)
49 {
50   scm_puts ("#<Undead ", port);
51   scm_display (Undead::unsmob (undead)->object (), port);
52   scm_puts (" >", port);
53   return 1;
54 }
55
56 const char Undead::type_p_name_[] = "ly:undead?";
57
58 LY_DEFINE (ly_make_undead, "ly:make-undead",
59            1, 0, 0, (SCM object),
60            "This packages @var{object} in a manner that keeps it from"
61            " triggering \"Parsed object should be dead\" messages.")
62 {
63   Undead undead (object);
64   return undead.smobbed_copy ();
65 }
66
67 LY_DEFINE (ly_get_undead, "ly:get-undead",
68            1, 0, 0, (SCM undead),
69            "Get back object from @var{undead}.")
70 {
71   LY_ASSERT_SMOB (Undead, undead, 1);
72   return Undead::unsmob (undead)->object ();
73 }
74
75 // '
76 // These are not protected since the means of protecting them would be
77 // problematic to trigger during the mark pass where the array element
78 // references get set.  However, they get set only when in the mark
79 // pass when checking for parsed elements that should be dead, and we
80 // query and clear them immediately afterwards.  So there should be no
81 // way in which the references would have become unprotected in the
82 // mean time.
83
84 vector<parsed_dead *> parsed_dead::elements;
85
86 SCM
87 parsed_dead::readout ()
88 {
89   SCM result = SCM_EOL;
90   for (vsize i = 0; i < elements.size (); i++)
91     {
92       SCM elt = elements[i]->readout_one ();
93       if (!SCM_UNBNDP (elt))
94         result = scm_cons (elt, result);
95     }
96   return result;
97 }
98
99 LY_DEFINE (ly_parsed_undead_list_x, "ly:parsed-undead-list!",
100            0, 0, 0, (),
101            "Return the list of objects that have been found live"
102            " that should have been dead, and clear that list.")
103 {
104   return parsed_dead::readout ();
105 }