The Battle for Wesnoth  1.19.15+dev
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
enable_lua_ptr< T > Class Template Reference

Allows creation of lua_ptr<T> instances, but does not affect the lifetime of the T itself. More...

#include <lua_ptr.hpp>

Public Member Functions

 enable_lua_ptr (T *tp)
 
 enable_lua_ptr (enable_lua_ptr &&o)
 The weak_ptrs are pointing to o's shared_ptr's control block, so to keep existing weak_ptrs valid the existing control block is reused instead of replaced. More...
 
enable_lua_ptroperator= (enable_lua_ptr &&o)
 

Private Member Functions

 enable_lua_ptr (const enable_lua_ptr &o)=delete
 
enable_lua_ptroperator= (const enable_lua_ptr &o)=delete
 

Private Attributes

std::shared_ptr< T * > self_
 

Friends

class lua_ptr< T >
 

Detailed Description

template<typename T>
class enable_lua_ptr< T >

Allows creation of lua_ptr<T> instances, but does not affect the lifetime of the T itself.

This allows the instance of T to be deleted while the lua_ptr<T>s still exist.

The implementation details are making a shared_ptr<non-owning raw pointer to T>, with that shared_ptr owned by the instance of T that's being pointed to, which is then used to create weak_ptrs. The lua_ptr is a wrapper to make sure that no-one gets a second non-temporary shared_ptr<non-owning raw pointer T>. As there's only one shared_ptr, the weak_ptrs become invalid (but defined behavior) when the instance of T is deleted, because that deletes the shared_ptr.

Definition at line 33 of file lua_ptr.hpp.

Constructor & Destructor Documentation

◆ enable_lua_ptr() [1/3]

template<typename T >
enable_lua_ptr< T >::enable_lua_ptr ( T *  tp)
inline

Definition at line 36 of file lua_ptr.hpp.

◆ enable_lua_ptr() [2/3]

template<typename T >
enable_lua_ptr< T >::enable_lua_ptr ( enable_lua_ptr< T > &&  o)
inline

The weak_ptrs are pointing to o's shared_ptr's control block, so to keep existing weak_ptrs valid the existing control block is reused instead of replaced.

After the move, the existing control block will point to the new T, and o.self_ will be empty (which is guaranteed by the specification for std::shared_ptr's move assignment operator).

Definition at line 46 of file lua_ptr.hpp.

References enable_lua_ptr< T >::self_.

◆ enable_lua_ptr() [3/3]

template<typename T >
enable_lua_ptr< T >::enable_lua_ptr ( const enable_lua_ptr< T > &  o)
privatedelete

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
enable_lua_ptr& enable_lua_ptr< T >::operator= ( const enable_lua_ptr< T > &  o)
privatedelete

◆ operator=() [2/2]

template<typename T >
enable_lua_ptr& enable_lua_ptr< T >::operator= ( enable_lua_ptr< T > &&  o)
inline

Definition at line 50 of file lua_ptr.hpp.

References enable_lua_ptr< T >::self_.

Friends And Related Function Documentation

◆ lua_ptr< T >

template<typename T >
friend class lua_ptr< T >
friend

Definition at line 58 of file lua_ptr.hpp.

Member Data Documentation

◆ self_

template<typename T >
std::shared_ptr<T*> enable_lua_ptr< T >::self_
private

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