Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
sbk::core::database_ptr< TObject > Class Template Reference

#include <database_ptr.h>

Inheritance diagram for sbk::core::database_ptr< TObject >:

Public Types

using TThisType = database_ptr< TObject >
 
using TIdentifierType = sbk_id
 
using TObjectPtr = TObject *
 
using TObjectRef = TObject &
 
using TObjectWeak = std::weak_ptr< database_object >
 
using TObjectShared = std::shared_ptr< TObject >
 
using TPtrType = std::weak_ptr< database_object >
 

Public Member Functions

 database_ptr ()
 Creates an empty and null LazyPtr.
 
 database_ptr (const TThisType &other)=default
 
 database_ptr (TThisType &&other)=default
 
 database_ptr (sbk_id id)
 Creates a LazyPtr that can lookup its object pointer after construction.
 
 database_ptr (const TObjectShared &object)
 Create a valid LazyPtr.
 
 database_ptr (const TObjectPtr &object)
 Create a valid LazyPtr.
 
 database_ptr (std::nullptr_t)
 Create an empty and null LazyPtr.
 
auto id () const noexcept -> sbk_id
 Get ID of the referenced object.
 
auto shared () const noexcept -> TObjectShared
 
auto weak () const noexcept -> TObjectWeak
 
auto raw () const noexcept -> TObjectPtr
 Get raw pointer of the referenced object.
 
auto lookup_raw () const noexcept -> TObjectPtr
 
auto has_id () const noexcept -> bool
 Returns true if we hold a valid ID and can search for an object at runtime.
 
auto null () const noexcept -> bool
 Returns true if the object pointer is not set.
 
auto pending () const noexcept -> bool
 Returns true if we hold an ID but haven't found the live object to point to yet.
 
auto stale () const noexcept -> bool
 Returns true if we previously referenced an object that has been destroyed.
 
auto valid () const noexcept -> bool
 Returns true if we hold an ID and a valid pointer to the object.
 
auto lookup () const noexcept -> bool
 Find the live object referenced by the ID and store it.
 
auto reset (TObjectPtr object=nullptr) -> void
 Clear all references.
 
TThisTypeoperator= (TObjectShared object)
 
TThisTypeoperator= (TObjectPtr object)
 Assign this LazyPtr to a new object, potentially destroying the current object if we're acting as a UniquePtr.
 
TThisTypeoperator= (const TThisType &other)
 
TThisTypeoperator= (const TThisType &&other)
 
 operator bool () const
 Returns true if this LazyPtr references a valid object.
 
bool operator! () const
 Returns true if this LazyPtr is invalid.
 
TObjectPtr operator-> () const
 Access the raw object.
 

Protected Attributes

sbk_id m_objectID
 
TPtrType m_objectPtr = TPtrType()
 
bool m_null
 

Detailed Description

template<typename TObject>
class sbk::core::database_ptr< TObject >

Lazy Pointer Lazy pointers store an Indentifier to an object and use it to find the object later Lazy pointers can be serialized so references can persist through multiple shutdowns Passing only an indentifier will create a pointer that references no object but will try to find the object when accessing the object

Constructor & Destructor Documentation

◆ database_ptr() [1/4]

template<typename TObject >
sbk::core::database_ptr< TObject >::database_ptr ( sbk_id  id)
inline

Creates a LazyPtr that can lookup its object pointer after construction.

Parameters
idID of the object to reference

◆ database_ptr() [2/4]

template<typename TObject >
sbk::core::database_ptr< TObject >::database_ptr ( const TObjectShared &  object)
inline

Create a valid LazyPtr.

Parameters
object

◆ database_ptr() [3/4]

template<typename TObject >
sbk::core::database_ptr< TObject >::database_ptr ( const TObjectPtr &  object)
inline

Create a valid LazyPtr.

Parameters
object

◆ database_ptr() [4/4]

template<typename TObject >
sbk::core::database_ptr< TObject >::database_ptr ( std::nullptr_t  )
inline

Create an empty and null LazyPtr.

Parameters
nullptr_t

Member Function Documentation

◆ lookup()

template<typename TObject >
auto sbk::core::database_ptr< TObject >::lookup ( ) const -> bool
inlinenoexcept

Find the live object referenced by the ID and store it.

Returns
true if the object was found and we're a valid ptr

◆ operator->()

template<typename TObject >
TObjectPtr sbk::core::database_ptr< TObject >::operator-> ( ) const
inline

Access the raw object.

Returns
raw object

◆ operator=()

template<typename TObject >
TThisType & sbk::core::database_ptr< TObject >::operator= ( TObjectPtr  object)
inline

Assign this LazyPtr to a new object, potentially destroying the current object if we're acting as a UniquePtr.

Parameters
objectto assign to
Returns
this

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