]> git.donarmstrong.com Git - lilypond.git/blob - lily/protected-scm.cc
release: 1.2.13
[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--1999 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 #ifdef LYPROT
14 #define PROTECT   ly_protect_scm
15 #define UNPROTECT ly_unprotect_scm
16 #else
17 #define PROTECT   scm_protect_object 
18 #define UNPROTECT scm_unprotect_object
19 #endif
20
21 Protected_scm::Protected_scm ()
22 {
23   object_ = 0;
24 }
25
26 Protected_scm::Protected_scm (SCM s)
27 {
28   object_ = s  ? PROTECT (s): 0;
29 }
30
31 Protected_scm::Protected_scm (Protected_scm const &s)
32 {
33   object_ = s.object_ ? PROTECT (s.object_) : 0;
34 }
35
36 Protected_scm & 
37 Protected_scm::operator =(SCM s)
38 {
39   if (object_ == s)
40     return *this;
41   if (object_)
42     UNPROTECT(object_);
43
44   object_ =  s ? PROTECT (s): 0;
45   return *this;
46 }
47
48 Protected_scm&
49 Protected_scm::operator = (Protected_scm const &s)
50 {
51   return operator= (s.object_);
52 }
53
54
55 Protected_scm::~Protected_scm ()
56 {
57   if  (object_)
58     {
59       UNPROTECT (object_);
60       object_ =0L;              // be nice to conservative GC
61     }
62 }
63
64 Protected_scm::operator SCM () const
65 {
66   return object_;
67 }
68
69 SCM 
70 Protected_scm::to_SCM () const
71 {
72   return object_;
73 }