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

Search Toolkit Book for CSafeStaticPtr

CSafeStaticPtr<>:: More...

#include <corelib/ncbi_safe_static.hpp>

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

Public Types

typedef CSafeStaticLifeSpan TLifeSpan
 
- Public Types inherited from CSafeStaticPtr_Base
typedef void(* FUserCleanup) (void *ptr)
 User cleanup function type. More...
 
typedef CSafeStaticLifeSpan TLifeSpan
 Life span. More...
 

Public Member Functions

 CSafeStaticPtr (FUserCleanup user_cleanup=0, TLifeSpan life_span=TLifeSpan::GetDefault())
 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 CSafeStaticPtr_Base
 ~CSafeStaticPtr_Base (void)
 

Private Member Functions

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

Static Private Member Functions

static Tx_CastPtr (const void *ptr)
 
static void sx_SelfCleanup (CSafeStaticPtr_Base *safe_static, TInstanceMutexGuard &guard)
 

Additional Inherited Members

- Protected Types inherited from CSafeStaticPtr_Base
typedef CGuard< CSafeStaticPtr_BaseTInstanceMutexGuard
 
typedef void(* FSelfCleanup) (CSafeStaticPtr_Base *safe_static, TInstanceMutexGuard &guard)
 Cleanup function type used by derived classes. More...
 
- Protected Member Functions inherited from CSafeStaticPtr_Base
 CSafeStaticPtr_Base (FSelfCleanup self_cleanup, FUserCleanup user_cleanup=0, TLifeSpan life_span=TLifeSpan::GetDefault())
 Constructor. More...
 
 DECLARE_CLASS_STATIC_MUTEX (sm_ClassMutex)
 
const void * x_GetPtr () const
 
void x_SetPtr (const void *ptr)
 
bool x_IsSetPtr () const
 
const void * x_ReleasePtr ()
 
bool x_IsStdStatic (void) const
 
void x_Cleanup (void)
 
- Static Protected Member Functions inherited from CSafeStaticPtr_Base
static int x_GetCreationOrder (void)
 
- Protected Attributes inherited from CSafeStaticPtr_Base
atomic< const void * > m_Ptr
 Pointer to the data. More...
 
FSelfCleanup m_SelfCleanup
 
FUserCleanup m_UserCleanup
 
TLifeSpan m_LifeSpan
 
int m_CreationOrder
 
int m_MutexRefCount
 
CMutexm_InstanceMutex
 

Detailed Description

template<class T>
class CSafeStaticPtr< T >

CSafeStaticPtr<>::

For simple on-demand variables. Create the variable of type "T" on demand, destroy it on the program termination. Should be used only as static object. Otherwise the correct initialization is not guaranteed.

Deprecated:
Use CSafeStatic<> instead.

Definition at line 603 of file ncbi_safe_static.hpp.

Member Typedef Documentation

◆ TLifeSpan

template<class T >
typedef CSafeStaticLifeSpan CSafeStaticPtr< T >::TLifeSpan

Definition at line 609 of file ncbi_safe_static.hpp.

Constructor & Destructor Documentation

◆ CSafeStaticPtr()

template<class T >
CSafeStaticPtr< T >::CSafeStaticPtr ( FUserCleanup  user_cleanup = 0,
TLifeSpan  life_span = TLifeSpan::GetDefault() 
)
inline

Constructor.

Parameters
user_cleanupUser-provided cleanup function to be executed on destruction.
life_spanLife span allows to control destruction of objects.
See also
CSafeStaticPtr_Base

Definition at line 618 of file ncbi_safe_static.hpp.

Member Function Documentation

◆ Get() [1/2]

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

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

Deprecated:
Use CSafeStatic class instead.

Definition at line 636 of file ncbi_safe_static.hpp.

References CSafeStaticPtr< T >::x_CastPtr(), CSafeStaticPtr_Base::x_GetPtr(), CSafeStaticPtr< T >::x_Init(), and CSafeStaticPtr_Base::x_IsSetPtr().

◆ Get() [2/2]

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

◆ operator*()

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

Definition at line 645 of file ncbi_safe_static.hpp.

References CSafeStaticPtr< T >::Get().

◆ operator->()

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

Definition at line 644 of file ncbi_safe_static.hpp.

References CSafeStaticPtr< T >::Get().

◆ Set()

template<class T >
void CSafeStaticPtr< 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 safe-static variables.

Definition at line 777 of file ncbi_safe_static.hpp.

References CSafeStaticGuard::Register().

◆ sx_SelfCleanup()

template<class T >
static void CSafeStaticPtr< T >::sx_SelfCleanup ( CSafeStaticPtr_Base safe_static,
TInstanceMutexGuard guard 
)
inlinestaticprivate

◆ x_CastPtr()

template<class T >
static T* CSafeStaticPtr< T >::x_CastPtr ( const void *  ptr)
inlinestaticprivate

Definition at line 605 of file ncbi_safe_static.hpp.

References T.

Referenced by CSafeStaticPtr< T >::Get(), and CSafeStaticPtr< T >::sx_SelfCleanup().

◆ x_Init() [1/2]

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

Definition at line 806 of file ncbi_safe_static.hpp.

References CSafeStaticGuard::Register().

◆ x_Init() [2/2]

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

Definition at line 792 of file ncbi_safe_static.hpp.

References CSafeStaticGuard::Register(), and T.

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


The documentation for this class was generated from the following file:
Modified on Sun Jul 14 05:01:24 2024 by modify_doxy.py rev. 669887