CGraph
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
USingleton< T, type, autoInit > Class Template Reference

支持默认构造一个T类型的对象、封装成单例使用 目前实际上只支持CObject及其派生类作为单例要维护的对象类型,其他类型在init/destroy阶段啥都不做 More...

#include <USingleton.h>

Inheritance diagram for USingleton< T, type, autoInit >:
Inheritance graph
[legend]
Collaboration diagram for USingleton< T, type, autoInit >:
Collaboration graph
[legend]

Public Member Functions

 USingleton () noexcept
 
 ~USingleton () override
 
T * get ()
 
- Public Member Functions inherited from CObject
 CObject ()=default
 
virtual ~CObject ()=default
 

Protected Member Functions

CStatus init () override
 
CStatus destroy () override
 
CVoid create ()
 
CStatus clear ()
 
 CGRAPH_NO_ALLOWED_COPY (USingleton)
 
- Protected Member Functions inherited from UtilsObject
CStatus run () override
 

Private Attributes

T * handle_ { nullptr }
 
std::mutex lock_
 

Detailed Description

template<typename T, USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
class USingleton< T, type, autoInit >

支持默认构造一个T类型的对象、封装成单例使用 目前实际上只支持CObject及其派生类作为单例要维护的对象类型,其他类型在init/destroy阶段啥都不做

Template Parameters
T单例实际维护的对象类型,在USingleton内部维护为T *句柄
type单例模式,支持懒汉(LAZY)和饿汉(HUNGRY)模式,默认HUNGRY
autoInit是否在构造时自动初始化,默认false

Constructor & Destructor Documentation

◆ USingleton()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
USingleton< T, type, autoInit >::USingleton ( )
inlineexplicitnoexcept
Here is the call graph for this function:

◆ ~USingleton()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
USingleton< T, type, autoInit >::~USingleton ( )
inlineoverride
Here is the call graph for this function:

Member Function Documentation

◆ CGRAPH_NO_ALLOWED_COPY()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
USingleton< T, type, autoInit >::CGRAPH_NO_ALLOWED_COPY ( USingleton< T, type, autoInit >  )
protected

◆ clear()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
CStatus USingleton< T, type, autoInit >::clear ( )
inlineprotected

销毁单例句柄

Returns

◆ create()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
CVoid USingleton< T, type, autoInit >::create ( )
inlineprotected

单例的创建一个句柄

Returns

◆ destroy()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
CStatus USingleton< T, type, autoInit >::destroy ( )
inlineoverrideprotectedvirtual

释放函数

Reimplemented from CObject.

Here is the call graph for this function:

◆ get()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
T* USingleton< T, type, autoInit >::get ( )
inline

获取singleton句柄信息

Returns
Here is the call graph for this function:

◆ init()

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
CStatus USingleton< T, type, autoInit >::init ( )
inlineoverrideprotectedvirtual

初始化函数

Reimplemented from CObject.

Here is the call graph for this function:

Member Data Documentation

◆ handle_

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
T* USingleton< T, type, autoInit >::handle_ { nullptr }
private

◆ lock_

template<typename T , USingletonType type = USingletonType::HUNGRY, CBool autoInit = false>
std::mutex USingleton< T, type, autoInit >::lock_
private

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