]> git.donarmstrong.com Git - lilypond.git/blob - lily/protected-scm.cc
147b83fefdaac6b1d2de6aef92353667f890d5bb
[lilypond.git] / lily / protected-scm.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--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 "protected-scm.hh"
21
22 Protected_scm::Protected_scm ()
23 {
24   object_ = SCM_UNDEFINED;
25 }
26
27 Protected_scm::Protected_scm (SCM s)
28 {
29   object_ = SCM_NIMP (s) ? scm_gc_protect_object (s) : s;
30 }
31
32 Protected_scm::Protected_scm (Protected_scm const &s)
33 {
34   object_ = (SCM_NIMP (s.object_) ? scm_gc_protect_object (s.object_)
35              : s.object_);
36 }
37
38 Protected_scm::~Protected_scm ()
39 {
40   if (SCM_NIMP (object_))
41     scm_gc_unprotect_object (object_);
42 }
43
44 Protected_scm &
45 Protected_scm::operator = (SCM s)
46 {
47   if (object_ == s)
48     return *this;
49
50   if (SCM_NIMP (object_))
51     scm_gc_unprotect_object (object_);
52
53   object_ = SCM_NIMP (s) ? scm_gc_protect_object (s) : s;
54   return *this;
55 }
56
57 Protected_scm &
58 Protected_scm::operator = (Protected_scm const &s)
59 {
60   return operator = (s.object_);
61 }
62
63 Protected_scm::operator SCM () const
64 {
65   return object_;
66 }
67
68 SCM
69 Protected_scm::to_SCM () const
70 {
71   return object_;
72 }