]> git.donarmstrong.com Git - lilypond.git/blob - lily/protected-scm.cc
nu wel 58
[lilypond.git] / lily / protected-scm.cc
1 /*   
2   protected-scm.cc --  implement Protected_scm
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include "protected-scm.hh"
10 #include "lily-guile.hh"
11 #include "main.hh"
12
13 Protected_scm::Protected_scm ()
14 {
15   object_ = SCM_UNDEFINED;
16 }
17
18 Protected_scm::Protected_scm (SCM s)
19 {
20   object_ = SCM_NIMP (s)  ? scm_gc_protect_object (s): s;
21 }
22
23 Protected_scm::Protected_scm (Protected_scm const &s)
24 {
25   object_ = SCM_NIMP (s.object_) ? scm_gc_protect_object (s.object_) : s.object_;
26 }
27
28 Protected_scm & 
29 Protected_scm::operator = (SCM s)
30 {
31   if (object_ == s)
32     return *this;
33   
34   if (SCM_NIMP (object_))
35     scm_gc_unprotect_object (object_);
36
37   object_ =  SCM_NIMP (s) ? scm_gc_protect_object (s): s;
38   return *this;
39 }
40
41 Protected_scm&
42 Protected_scm::operator = (Protected_scm const &s)
43 {
44   return operator= (s.object_);
45 }
46
47
48 Protected_scm::~Protected_scm ()
49 {
50   if (SCM_NIMP (object_))
51     {
52       scm_gc_unprotect_object (object_);
53     }
54 }
55
56 Protected_scm::operator SCM () const
57 {
58   return object_;
59 }
60
61 SCM 
62 Protected_scm::to_SCM () const
63 {
64   return object_;
65 }