NAP
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ObjectPtrManager Class Reference

#include <rtti/objectptr.h>

Public Types

typedef std::unordered_set< ObjectPtrBase * > ObjectPtrSet
 

Public Member Functions

template<class OBJECTSBYIDMAP >
void patchPointers (OBJECTSBYIDMAP &newTargetObjects)
 
void resetPointers (const rtti::Object &targetObject)
 

Static Public Member Functions

static ObjectPtrManagerget ()
 

Description

Holds a set of all ObjectPtrs in the application. The purpose of the manager is to be able to retarget ObjectPtrs if objects get replaced by another object in the real-time updating system.

The way this is done is by storing pointers to ObjectPtrs. The reason is that this makes it possible to alter the contents of the pointer at any time without introducing an extra indirection: the ObjectPtr just behaves as a regular pointer. Because we are storing pointers, we need to make sure that at any time the ObjectPtr moves in memory, we should remove/add the ObjectPtr from the manager. This is done by the ObjectPtr on every possible occasion where they are moved from on location in memory to another.

One possible thing to note is that when objects get destructed, but the destructor isn't called (which is obviously incorrect), this may cause dangling pointers in this manager. The only case where this may happen is when destructors aren't virtual and the derived class holds ObjectPtrs.

Member Typedef Documentation

◆ ObjectPtrSet

typedef std::unordered_set<ObjectPtrBase*> ObjectPtrSet

Member Function Documentation

◆ get()

static ObjectPtrManager& get ( )
static

Returns the global ObjectPtrManager.

◆ patchPointers()

void patchPointers ( OBJECTSBYIDMAP &  newTargetObjects)

Patches pointers in the ObjectPtrManager to objects in the newTargetObjects map. The pointers are matched by comparing IDs of the objects being pointed to. This function is a template so we can deal with different kinds of values in the map; the key must always be a string, but the value may be a smart pointer or raw pointer.

Parameters
newTargetObjectsMap from string ID to RTTIObject pointer (either raw or smart pointer, as long as it can be dereferenced).

◆ resetPointers()

void resetPointers ( const rtti::Object targetObject)

Resets all ObjectPtrs to the specified object to nullptr

Parameters
targetObjectThe object to which ObjectPtrs are pointing to