]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-handle.cc
Web-ja: update introduction
[lilypond.git] / lily / context-handle.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 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 "context-handle.hh"
21 #include "context.hh"
22
23 Context_handle::Context_handle ()
24 {
25   outlet_ = 0;
26 }
27
28 Context_handle::Context_handle (Context_handle const &s)
29 {
30   outlet_ = 0;
31   if (s.outlet_)
32     up (s.outlet_);
33 }
34
35 Context_handle::~Context_handle ()
36 {
37   /*
38     Don't do
39
40     if (outlet_)
41     down ();
42
43     with GC, this is asynchronous.
44   */
45 }
46
47 void
48 Context_handle::up (Context *t)
49 {
50   outlet_ = t;
51   t->client_count_++;
52 }
53
54 void
55 Context_handle::down ()
56 {
57   outlet_->client_count_--;
58   outlet_ = 0;
59 }
60
61 void
62 Context_handle::operator = (Context_handle const &s)
63 {
64   set_context (s.outlet_);
65 }
66
67 void
68 Context_handle::set_context (Context *trans)
69 {
70   if (outlet_ == trans)
71     return;
72   if (outlet_)
73     down ();
74   if (trans)
75     up (trans);
76 }
77
78 Context *
79 Context_handle::get_context () const
80 {
81
82   return outlet_;
83 }
84
85 int
86 Context_handle::get_count () const
87 {
88   return outlet_->client_count_;
89 }