TODO update
[supertux.git] / src / musicref.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 #include "musicref.h"
21
22 MusicRef::MusicRef()
23   : music(0)
24 {
25 }
26
27 MusicRef::MusicRef(MusicManager::MusicResource* newmusic)
28   : music(newmusic)
29 {
30   if(music)
31     music->refcount++;
32 }
33
34 MusicRef::~MusicRef()
35 {
36   if(music) {
37     music->refcount--;
38     if(music->refcount == 0)
39       music->manager->free_music(music);
40   }
41 }
42
43 MusicRef::MusicRef(const MusicRef& other)
44   : music(other.music)
45 {
46   if(music)
47     music->refcount++;
48 }
49
50 MusicRef&
51 MusicRef::operator =(const MusicRef& other)
52 {
53   MusicManager::MusicResource* oldres = music;
54   music = other.music;
55   if(music)
56     music->refcount++;
57   if(oldres) {
58     oldres->refcount--;
59     if(oldres->refcount == 0)
60       music->manager->free_music(music);
61   }
62
63   return *this;
64 }
65