Support Forum       G3D Web Page     
Classes | Public Member Functions | List of all members
G3D::lazy_ptr< T > Class Template Reference


Provides a level of indirection for accessing objects to allow computing them on demand or extending them with metadata without subclassing the object itself. More...

Public Member Functions

 lazy_ptr ()
 Creates a nullptr lazy pointer. More...
 
 lazy_ptr (nullptr_t)
 
 lazy_ptr (const std::function< shared_ptr< T >(void)> &resolve)
 Creates a lazy_ptr from a function that will create the object. More...
 
 lazy_ptr (const shared_ptr< T > &object)
 Creates a lazy_ptr for an already-resolved object. More...
 
template<class S >
 lazy_ptr (const shared_ptr< S > &object)
 Creates a lazy_ptr for an already-resolved object. More...
 
bool isNull () const
 Is the proxy itself a null pointer. More...
 
bool operator!= (const lazy_ptr< T > &other) const
 
const T & operator* () const
 Invokes resolve. More...
 
T & operator* ()
 Invokes resolve. More...
 
const T * operator-> () const
 Invokes resolve. More...
 
T * operator-> ()
 Invokes resolve. More...
 
bool operator== (const lazy_ptr< T > &other) const
 
const shared_ptr< T > resolve () const
 Returns a pointer to a T or a nullptr pointer. More...
 
shared_ptr< T > resolve ()
 Returns a pointer to a T or a nullptr pointer.
More...
 
bool resolved () const
 True if this object can be resolved() without triggering any evaluation. More...
 

Detailed Description

template<class T>
class G3D::lazy_ptr< T >


Provides a level of indirection for accessing objects to allow computing them on demand or extending them with metadata without subclassing the object itself.

For example, lazy loading of files.

Useful for implementing lazy loading, for example, as done by ArticulatedModel::lazyCreate:

lazy_ptr<ArticulatedModel>([specification, name]{ return ArticulatedModel::create(specification, name); });

Analogous to shared_ptr and weak_ptr. Copies of lazy_ptrs retain the same underlying object, so it will only be resolved once.

Threadsafe.

Constructor & Destructor Documentation

◆ lazy_ptr() [1/5]

template<class T>
G3D::lazy_ptr< T >::lazy_ptr ( )
inline

Creates a nullptr lazy pointer.

◆ lazy_ptr() [2/5]

template<class T>
G3D::lazy_ptr< T >::lazy_ptr ( nullptr_t  )
inline

◆ lazy_ptr() [3/5]

template<class T>
G3D::lazy_ptr< T >::lazy_ptr ( const std::function< shared_ptr< T >(void)> &  resolve)
inline

Creates a lazy_ptr from a function that will create the object.

◆ lazy_ptr() [4/5]

template<class T>
G3D::lazy_ptr< T >::lazy_ptr ( const shared_ptr< T > &  object)
inline

Creates a lazy_ptr for an already-resolved object.

◆ lazy_ptr() [5/5]

template<class T>
template<class S >
G3D::lazy_ptr< T >::lazy_ptr ( const shared_ptr< S > &  object)
inline

Creates a lazy_ptr for an already-resolved object.

Member Function Documentation

◆ isNull()

template<class T>
bool G3D::lazy_ptr< T >::isNull ( ) const
inline

◆ operator!=()

template<class T>
bool G3D::lazy_ptr< T >::operator!= ( const lazy_ptr< T > &  other) const
inline

◆ operator*() [1/2]

template<class T>
const T& G3D::lazy_ptr< T >::operator* ( ) const
inline

Invokes resolve.

If you intend to use multiple dereferences, it is faster to invoke resolve() once and store the shared_ptr.

◆ operator*() [2/2]

template<class T>
T& G3D::lazy_ptr< T >::operator* ( )
inline

Invokes resolve.

If you intend to use multiple dereferences, it is faster to invoke resolve() once and store the shared_ptr.

◆ operator->() [1/2]

template<class T>
const T* G3D::lazy_ptr< T >::operator-> ( ) const
inline

Invokes resolve.

If you intend to use multiple dereferences, it is faster to invoke resolve() once and store the shared_ptr.

◆ operator->() [2/2]

template<class T>
T* G3D::lazy_ptr< T >::operator-> ( )
inline

Invokes resolve.

If you intend to use multiple dereferences, it is faster to invoke resolve() once and store the shared_ptr.

◆ operator==()

template<class T>
bool G3D::lazy_ptr< T >::operator== ( const lazy_ptr< T > &  other) const
inline

◆ resolve() [1/2]

template<class T>
const shared_ptr<T> G3D::lazy_ptr< T >::resolve ( ) const
inline

Returns a pointer to a T or a nullptr pointer.

If there are multiple levels of proxies, then this call resolves all of them.

Referenced by G3D::lazy_ptr< T >::operator*(), and G3D::lazy_ptr< T >::operator->().

◆ resolve() [2/2]

template<class T>
shared_ptr<T> G3D::lazy_ptr< T >::resolve ( )
inline

Returns a pointer to a T or a nullptr pointer.

If there are multiple levels of proxies, then this call resolves all of them.

◆ resolved()

template<class T>
bool G3D::lazy_ptr< T >::resolved ( ) const
inline

True if this object can be resolved() without triggering any evaluation.


documentation generated on Wed Nov 24 2021 08:01:57 using doxygen 1.8.15