ug4
ug::LuaUserDataFactory< TData, dim, TRet > Class Template Reference

Factory providing LuaUserData. More...

#include <lua_user_data.h>

Static Public Member Functions

static SmartPtr< LuaUserData< TData, dim, TRet > > create (const std::string &name)
 

Protected Member Functions

 LuaUserDataFactory ()
 private constructor, since singleton More...
 
 LuaUserDataFactory (const LuaUserDataFactory &)
 
LuaUserDataFactoryoperator= (const LuaUserDataFactory &)
 

Static Protected Member Functions

static LuaUserDataFactory< TData, dim, TRet > & instance ()
 singleton provider More...
 
static SmartPtr< LuaUserData< TData, dim, TRet > > provide_or_create (const std::string &name)
 returns new Data if not already created, already existing else More...
 
static void remove (const std::string &name)
 removes the user data More...
 

Static Protected Attributes

static std::map< std::string, std::pair< LuaUserData< TData, dim, TRet > *, int * > > m_mData = std::map<std::string, std::pair<LuaUserData<TData,dim,TRet>*, int*> >()
 storage of already created data More...
 

Friends

class LuaUserData< TData, dim, TRet >
 

Detailed Description

template<typename TData, int dim, typename TRet>
class ug::LuaUserDataFactory< TData, dim, TRet >

Factory providing LuaUserData.

This class is a singleton providing LuaUserData for a given callback name. The factory creates a new LuaUserData and returns it as a SmartPtr if no Data has been created with the same callback name before. It already a LuaUserData using the same callback exists, then a SmartPtr to that instance is returned. Internally, therefore plain pointers and reference counters of the created SmartPtrs are stored and LuaUserData unregister from the List of created LuaUserData in this factory when their destructor is called.

Template Parameters
TDataData produced by LuaUserData
dimworld dimension
TRetbool flag or void

Constructor & Destructor Documentation

◆ LuaUserDataFactory() [1/2]

template<typename TData , int dim, typename TRet >
ug::LuaUserDataFactory< TData, dim, TRet >::LuaUserDataFactory ( )
inlineprotected

private constructor, since singleton

◆ LuaUserDataFactory() [2/2]

template<typename TData , int dim, typename TRet >
ug::LuaUserDataFactory< TData, dim, TRet >::LuaUserDataFactory ( const LuaUserDataFactory< TData, dim, TRet > &  )
protected

Member Function Documentation

◆ create()

template<typename TData , int dim, typename TRet >
static SmartPtr<LuaUserData<TData,dim,TRet> > ug::LuaUserDataFactory< TData, dim, TRet >::create ( const std::string &  name)
inlinestatic

Returns a LuaUserDataas a SmartPtr for a callback name. If a LuaUserData has already been created by the factory it simply returns a new SmartPtr without creation, else the LuaUserData is created. All LuaUserData store internally, if they have been created by a factory, and if so they unregister from the factory when their destructor is called.

NOTE: In order to allow any garbage collection of the LuaUserData, therefore this factory can not store the LuaUserData as a SmartPtr, but as a plain pointer together with the reference counter.

Parameters
namelua callback name
Returns
LuaUserNumber as SmartPtr

References ug::LuaUserDataFactory< TData, dim, TRet >::instance(), and name.

◆ instance()

template<typename TData , int dim, typename TRet >
static LuaUserDataFactory<TData,dim,TRet>& ug::LuaUserDataFactory< TData, dim, TRet >::instance ( )
inlinestaticprotected

singleton provider

Referenced by ug::LuaUserDataFactory< TData, dim, TRet >::create().

◆ operator=()

template<typename TData , int dim, typename TRet >
LuaUserDataFactory& ug::LuaUserDataFactory< TData, dim, TRet >::operator= ( const LuaUserDataFactory< TData, dim, TRet > &  )
protected

◆ provide_or_create()

template<typename TData , int dim, typename TRet >
SmartPtr< LuaUserData< TData, dim, TRet > > ug::LuaUserDataFactory< TData, dim, TRet >::provide_or_create ( const std::string &  name)
staticprotected

returns new Data if not already created, already existing else

References SmartPtr< T, FreePolicy >::get(), make_sp(), name, PROFILE_CALLBACK, and SmartPtr< T, FreePolicy >::refcount_ptr().

◆ remove()

template<typename TData , int dim, typename TRet >
void ug::LuaUserDataFactory< TData, dim, TRet >::remove ( const std::string &  name)
staticprotected

removes the user data

Referenced by ug::LuaUserData< TData, dim, TRet >::~LuaUserData().

Friends And Related Function Documentation

◆ LuaUserData< TData, dim, TRet >

template<typename TData , int dim, typename TRet >
friend class LuaUserData< TData, dim, TRet >
friend

Member Data Documentation

◆ m_mData

template<typename TData , int dim, typename TRet >
std::map< std::string, std::pair< LuaUserData< TData, dim, TRet > *, int * > > ug::LuaUserDataFactory< TData, dim, TRet >::m_mData = std::map<std::string, std::pair<LuaUserData<TData,dim,TRet>*, int*> >()
staticprotected

storage of already created data


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