NCBI C++ ToolKit
Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
CAutoInitPtr< T > Class Template Reference

Search Toolkit Book for CAutoInitPtr

CAutoInitPtr<>:: More...

#include <corelib/ncbi_autoinit.hpp>

+ Inheritance diagram for CAutoInitPtr< T >:
+ Collaboration diagram for CAutoInitPtr< T >:

Public Member Functions

 CAutoInitPtr (FUserCleanup user_cleanup=0)
 Constructor. More...
 
TGet (void)
 Create the variable if not created yet, return the reference. More...
 
template<class FUserCreate >
TGet (FUserCreate user_create)
 Get the existing object or create a new one using the provided FUserCreate object. More...
 
Toperator-> (void)
 
Toperator* (void)
 
void Set (T *object)
 Initialize with an existing object. More...
 
- Public Member Functions inherited from CAutoInitPtr_Base
 ~CAutoInitPtr_Base (void)
 
bool IsInitialized (void) const
 

Private Member Functions

void x_Init (void)
 
template<class FUserCreate >
void x_Init (FUserCreate user_create)
 

Static Private Member Functions

static void x_SelfCleanup (void **ptr)
 

Additional Inherited Members

- Public Types inherited from CAutoInitPtr_Base
typedef void(* FUserCleanup) (void *ptr)
 User cleanup function type. More...
 
- Protected Types inherited from CAutoInitPtr_Base
typedef void(* FSelfCleanup) (void **ptr)
 Cleanup function type used by derived classes. More...
 
- Protected Member Functions inherited from CAutoInitPtr_Base
 CAutoInitPtr_Base (FSelfCleanup self_cleanup, FUserCleanup user_cleanup=0)
 Constructor. More...
 
void AssertUninitialized (void) const
 
 DECLARE_CLASS_STATIC_MUTEX (sm_Mutex)
 
- Protected Attributes inherited from CAutoInitPtr_Base
void * m_Ptr
 Pointer to the data. More...
 

Detailed Description

template<class T>
class CAutoInitPtr< T >

CAutoInitPtr<>::

For simple on-demand variables. Create the variable of type "T" on demand, destroy it on the CAutoInitPtr termination. The class should not be used for static variables, use CSafeStaticPtr class instead.

Definition at line 121 of file ncbi_autoinit.hpp.

Constructor & Destructor Documentation

◆ CAutoInitPtr()

template<class T >
CAutoInitPtr< T >::CAutoInitPtr ( FUserCleanup  user_cleanup = 0)
inline

Constructor.

Parameters
user_cleanupUser-provided cleanup function to be executed on destruction.
See also
CAutoInitPtr_Base

Definition at line 129 of file ncbi_autoinit.hpp.

Member Function Documentation

◆ Get() [1/2]

template<class T >
template<class FUserCreate >
T& CAutoInitPtr< T >::Get ( FUserCreate  user_create)
inline

Get the existing object or create a new one using the provided FUserCreate object.

Definition at line 144 of file ncbi_autoinit.hpp.

References CAutoInitPtr_Base::m_Ptr, T, and CAutoInitPtr< T >::x_Init().

◆ Get() [2/2]

template<class T >
T& CAutoInitPtr< T >::Get ( void  )
inline

Create the variable if not created yet, return the reference.

Definition at line 134 of file ncbi_autoinit.hpp.

References CAutoInitPtr_Base::m_Ptr, T, and CAutoInitPtr< T >::x_Init().

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

◆ operator*()

template<class T >
T& CAutoInitPtr< T >::operator* ( void  )
inline

Definition at line 153 of file ncbi_autoinit.hpp.

References CAutoInitPtr< T >::Get().

◆ operator->()

template<class T >
T* CAutoInitPtr< T >::operator-> ( void  )
inline

Definition at line 152 of file ncbi_autoinit.hpp.

References CAutoInitPtr< T >::Get().

◆ Set()

template<class T >
void CAutoInitPtr< T >::Set ( T object)
inline

Initialize with an existing object.

The object MUST be allocated with "new T" – it will be destroyed with "delete object" in the end. Set() works only for not yet initialized CAutoInitPtr variables.

Definition at line 262 of file ncbi_autoinit.hpp.

◆ x_Init() [1/2]

template<class T >
template<class FUserCreate >
void CAutoInitPtr< T >::x_Init ( FUserCreate  user_create)
inlineprivate

Definition at line 284 of file ncbi_autoinit.hpp.

◆ x_Init() [2/2]

template<class T >
void CAutoInitPtr< T >::x_Init ( void  )
inlineprivate

Definition at line 273 of file ncbi_autoinit.hpp.

References T.

Referenced by CAutoInitPtr< T >::Get().

◆ x_SelfCleanup()

template<class T >
static void CAutoInitPtr< T >::x_SelfCleanup ( void **  ptr)
inlinestaticprivate

Definition at line 169 of file ncbi_autoinit.hpp.

References T, and tmp.


The documentation for this class was generated from the following file:
Modified on Wed May 29 18:44:07 2024 by modify_doxy.py rev. 669887