Nebula
Loading...
Searching...
No Matches
Core::RefCounted Class Reference

#include <refcounted.h>

Detailed Description

The common base class of Nebula.

Implement a strong refcounted mechanism and runtime type information. Nebula checks at application shutdown for propert cleanup of all RefCounted objects. Refcounting leaks will generate a log on the debug output.

FIXME: The RefCounted class uses Interlocked functions and a CriticalSection to guarantee thread-safe refcounting and destruction, but only some classes need this (mostly messages which are passed between threads). If it is guaranteed that an object is only manipulated from the same thread then this thread-synchronization adds unnecessary overhead.

Inherited by Animation::AnimJob, Attr::AttributeTable, Audio::AudioDevice, Audio::AudioServer, Base::DisplayDeviceBase, Base::GameContentServerBase, Base::InputServerBase, Base::InstanceRendererBase, Base::InstanceServerBase, Base::ShaderServerBase, Base::ShapeRendererBase, Base::TextRendererBase, BaseGameFeature::LevelParser, Core::CoreServer, CoreAnimation::AnimKeyBuffer, CoreGraphics::DisplayEventHandler, CoreGraphics::RenderEventHandler, Db::Command, Db::Database, Db::Dataset, Db::DbFactory, Db::DbServer, Db::FilterSet, Db::Reader, Db::Relation, Db::Table, Db::Writer, Debug::DebugCounter, Debug::DebugServer, Debug::DebugTimer, Dynui::ImguiAddon, Dynui::ImguiConsole, Dynui::ImguiProfiler, Frame::FrameScript, Frame::FrameServer, FrameSync::FrameSyncTimer, Game::FeatureUnit, Game::GameServer, Game::Manager, Graphics::GraphicsServer, Graphics::Stage, Graphics::View, Http::HttpClientRegistry, Http::HttpRequestHandler, Http::HttpServer, Http::HttpServerProxy, Http::NebulaHttpClient, IO::ArchiveBase, IO::ArchiveFileSystemBase, IO::AssignRegistry, IO::Console, IO::ConsoleHandler, IO::IoServer, IO::SchemeRegistry, IO::Stream, IO::StreamCache, IO::StreamReader, IO::StreamWriter, Input::InputHandler, Linux::LinuxThread, MemDb::Database, Messaging::AsyncPort, Messaging::Handler, Messaging::Message, Messaging::Port, Net::StdTcpClient, Net::StdTcpClientConnection, Net::StdTcpServer, OSX::OSXThread, Picking::PickingServer, Posix::PosixSocket, Posix::PosixThread, RenderModules::RTPlugin, RenderModules::RTPluginRegistry, RenderModules::RenderModule, Resources::ResourceLoader, Resources::ResourceSaver, Resources::ResourceServer, Scripting::NSharpServer, Scripting::ScriptServer, Threading::ObjectRef, Visibility::VisibilityContainer, Win32::Win32Socket, and Win32::Win32Thread.

Public Member Functions

 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Static Public Member Functions

static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 

Protected Member Functions

virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Private Member Functions

 __DeclareClass (RefCounted)
 

Private Attributes

volatile int refCount
 

Constructor & Destructor Documentation

◆ RefCounted()

Core::RefCounted::RefCounted ( )
inline

constructor

◆ ~RefCounted()

Core::RefCounted::~RefCounted ( )
protectedvirtual

destructor (called when refcount reaches zero)

Member Function Documentation

◆ __DeclareClass()

Core::RefCounted::__DeclareClass ( RefCounted )
private

◆ AddRef()

void Core::RefCounted::AddRef ( )
inline

increment refcount by one

Increment the refcount of the object.

◆ DumpRefCountingLeaks()

void Core::RefCounted::DumpRefCountingLeaks ( )
static

dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)

This method should be called as the very last before an application exits.

◆ GetClassFourCC()

Util::FourCC Core::RefCounted::GetClassFourCC ( ) const
inline

get the class FourCC code

Get the class FourCC of the object.

◆ GetClassName()

const Util::String & Core::RefCounted::GetClassName ( ) const
inline

get the class name

Get the class name of the object.

◆ GetRefCount()

int Core::RefCounted::GetRefCount ( ) const
inline

get the current refcount

Return the current refcount of the object.

◆ IsA() [1/3]

bool Core::RefCounted::IsA ( const Rtti & rtti) const
inline

return true if this object is instance of given class, or a derived class

◆ IsA() [2/3]

bool Core::RefCounted::IsA ( const Util::FourCC & rttiFourCC) const
inline

return true if this object is instance of given class, or a derived class, by fourcc

◆ IsA() [3/3]

bool Core::RefCounted::IsA ( const Util::String & rttiName) const
inline

return true if this object is instance of given class, or a derived class, by string

◆ IsInstanceOf() [1/3]

bool Core::RefCounted::IsInstanceOf ( const Rtti & rtti) const
inline

return true if this object is instance of given class

◆ IsInstanceOf() [2/3]

bool Core::RefCounted::IsInstanceOf ( const Util::FourCC & classFourCC) const
inline

return true if this object is instance of given class by fourcc

◆ IsInstanceOf() [3/3]

bool Core::RefCounted::IsInstanceOf ( const Util::String & className) const
inline

return true if this object is instance of given class by string

◆ Release()

void Core::RefCounted::Release ( )
inline

decrement refcount and destroy object if refcount is zero

Decrement the refcount and destroy object if refcount is zero.

Member Data Documentation

◆ refCount

volatile int Core::RefCounted::refCount
private

The documentation for this class was generated from the following files: