Spore ModAPI  2.4.0
API for creating C++ mods for Spore
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Object Class Referenceabstract

This class represents a basic reference counted object. More...

#include <Object.h>

Inheritance diagram for Object:
App::ICamera DefaultObject Editors::EditorRigblock Palettes::ColorPickerUI Palettes::PaletteCategory Palettes::PaletteItem Palettes::PaletteMain Palettes::PalettePage Resource::DatabasePackedFile Resource::ResourceObject Simulator::cBehaviorBase Simulator::cToolStrategy Simulator::ISimulatorSerializable UTFWin::IWinProc UTFWin::LayoutReader UTFWin::UTFWinObject

Public Member Functions

virtual int AddRef ()=0
virtual int Release ()=0
virtual void * Cast (uint32_t typeID) const =0

Static Public Attributes

static const uint32_t TYPE = 0xEE3F516E

Protected Member Functions

virtual ~Object ()

Detailed Description

This class represents a basic reference counted object.

Reference counted objects can be used inside intrusive_ptr structures in order to have automatic memory management. For example: intrusive_ptr<Window> mpWindow = new Window();

Internally, reference counted objects store a reference count. That value is increased every time AddRef() is called, and decreased every time Release() is called. When the reference count reaches 0, the object deletes itself. Every AddRef() call must be paired with a Release() call; intrusive_ptr does that automatically.

However, intrusive pointers must be used carefully, since it could case problems on certain cases. For example, class A has an intrusive_ptr member. B has an intrusive_ptr that points to the first object. This causes a recursive dependance that makes those objects never be deleted.

Additionally, this class contains a Cast method, that allows classes to implement an efficient equivalent to dynamic_cast. You can use it directly, but it's recommended to use object_cast instead. For example, to cast an IDrawable* pDrawable; into a IImageDrawable*:

// Cast an IDrawable* pDrawable into a IImageDrawable*
IImageDrawable* result = object_cast<IImageDrawable>(pDrawable);
// If it can be casted it will return nullptr; it's recommend it to always check
if (result) ...

Object is an interface; for a default implementation, check DefaultObject. Object can be considered an equivalent to COM objects.

You can use the "ModAPI Object" item template to create a basic Object class that supports casting.

Constructor & Destructor Documentation

◆ ~Object()

virtual Object::~Object ( )

Member Function Documentation

◆ AddRef()

virtual int Object::AddRef ( )
pure virtual

◆ Cast()

virtual void* Object::Cast ( uint32_t  typeID) const
pure virtual

◆ Release()

virtual int Object::Release ( )
pure virtual

Member Data Documentation


const uint32_t Object::TYPE = 0xEE3F516E

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