2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#pragma once
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Base Class for most shared objects (Node, Rep). Defines the addRef, release system.
|
|
|
|
|
* \brief Inspired by COM IUnknown system.
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-05-13 22:58:27 +00:00
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
# include "MEM_guardedalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-07-25 19:13:11 +02:00
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2014-04-17 14:19:10 +09:00
|
|
|
class BaseObject {
|
2008-04-30 15:41:54 +00:00
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
inline BaseObject()
|
|
|
|
|
{
|
|
|
|
|
_ref_counter = 0;
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
virtual ~BaseObject() {}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** At least makes a release on this.
|
2015-07-06 14:18:03 +10:00
|
|
|
* The BaseObject::destroy method must be explicitly called at the end of any overloaded destroy
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
|
|
|
|
virtual int destroy()
|
|
|
|
|
{
|
|
|
|
|
return release();
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Increments the reference counter */
|
2012-12-28 20:21:05 +00:00
|
|
|
inline int addRef()
|
|
|
|
|
{
|
|
|
|
|
return ++_ref_counter;
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Decrements the reference counter */
|
2012-12-28 20:21:05 +00:00
|
|
|
inline int release()
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_ref_counter) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_ref_counter--;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return _ref_counter;
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
private:
|
2023-07-25 12:51:50 +10:00
|
|
|
uint _ref_counter;
|
2013-05-13 22:58:27 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BaseObject")
|
|
|
|
|
#endif
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|