2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file countedobj.cpp Support for reference counted objects. */
|
|
|
|
|
2007-07-20 18:44:04 +00:00
|
|
|
#include "../stdafx.h"
|
|
|
|
|
|
|
|
#include "countedptr.hpp"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2007-07-20 18:44:04 +00:00
|
|
|
int32 SimpleCountedObject::AddRef()
|
|
|
|
{
|
|
|
|
return ++m_ref_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 SimpleCountedObject::Release()
|
|
|
|
{
|
|
|
|
int32 res = --m_ref_cnt;
|
|
|
|
assert(res >= 0);
|
|
|
|
if (res == 0) {
|
2015-08-10 20:04:31 +00:00
|
|
|
try {
|
|
|
|
FinalRelease(); // may throw, for example ScriptTest/ExecMode
|
|
|
|
} catch (...) {
|
|
|
|
delete this;
|
|
|
|
throw;
|
|
|
|
}
|
2007-07-20 18:44:04 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|