OpenTTD Source: src/misc/countedobj.cpp Source File

OpenTTD Source 13.2.1

countedobj.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11
12 #include "countedptr.hpp"
13
14 #include "../safeguards.h"
15
16 int32 SimpleCountedObject::AddRef()
17 {
18 return ++m_ref_cnt;
19 }
20
21 int32 SimpleCountedObject::Release()
22 {
23 int32 res = --m_ref_cnt;
24 assert(res >= 0);
25 if (res == 0) {
26 try {
27 FinalRelease(); // may throw, for example ScriptTest/ExecMode
28 } catch (...) {
29 delete this;
30 throw;
31 }
32 delete this;
33 }
34 return res;
35 }
countedptr.hpp