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

Search Toolkit Book for CSafeStatic

CSafeStatic<>:: More...

#include <corelib/ncbi_safe_static.hpp>

+ Inheritance diagram for CSafeStatic< T, Callbacks >:
+ Collaboration diagram for CSafeStatic< T, Callbacks >:

Public Types

typedef Callbacks TCallbacks
 
typedef CSafeStatic< T, TCallbacksTThisType
 
typedef CSafeStaticLifeSpan TLifeSpan
 
typedef CSafeStatic_Allocator< TTAllocator
 
typedef CSafeStatic_Callbacks< T >::FCreate FCreate
 Callback function types. More...
 
typedef CSafeStatic_Callbacks< T >::FCleanup FCleanup
 
- 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

 CSafeStatic (TLifeSpan life_span=TLifeSpan::GetDefault())
 Constructor. More...
 
 CSafeStatic (FCreate create, FCleanup cleanup, TLifeSpan life_span=TLifeSpan::GetDefault())
 Constructor. More...
 
 CSafeStatic (TCallbacks callbacks, TLifeSpan life_span=TLifeSpan::GetDefault())
 Constructor. More...
 
TGet (void)
 Create the variable if not created yet, return the reference. More...
 
Toperator-> (void)
 
Toperator* (void)
 
- Public Member Functions inherited from CSafeStaticPtr_Base
 ~CSafeStaticPtr_Base (void)
 

Private Member Functions

 CSafeStatic (const CSafeStatic &)=delete
 
CSafeStaticoperator= (const CSafeStatic &)=delete
 
void x_Init (void)
 

Static Private Member Functions

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

Private Attributes

TCallbacks m_Callbacks
 

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 Callbacks = CSafeStatic_Callbacks<T>>
class CSafeStatic< T, Callbacks >

CSafeStatic<>::

For on-demand object access, both non-CObject and CObject based. Create the variable of type "T" on the first access. The default implementation of allocator uses reference counter of CObject class to prevent premature destruction. Should be used only as static object. Otherwise the correct initialization is not guaranteed.

Parameters
TType of the variable to be stored.
CallbacksA class implementing two methods to perform additional initialization and cleanup: void Create(T* ptr) void Cleanup(T* ptr) NOTE: The Cleanup callback must not destroy the object itself, just perform any additional actions.

Definition at line 447 of file ncbi_safe_static.hpp.

Member Typedef Documentation

◆ FCleanup

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef CSafeStatic_Callbacks<T>::FCleanup CSafeStatic< T, Callbacks >::FCleanup

Definition at line 462 of file ncbi_safe_static.hpp.

◆ FCreate

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef CSafeStatic_Callbacks<T>::FCreate CSafeStatic< T, Callbacks >::FCreate

Callback function types.

The default callback class can be used as a simple wrapper for static functions.

See also
CSafeStatic_Callbacks

Definition at line 461 of file ncbi_safe_static.hpp.

◆ TAllocator

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef CSafeStatic_Allocator<T> CSafeStatic< T, Callbacks >::TAllocator

Definition at line 456 of file ncbi_safe_static.hpp.

◆ TCallbacks

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef Callbacks CSafeStatic< T, Callbacks >::TCallbacks

Definition at line 453 of file ncbi_safe_static.hpp.

◆ TLifeSpan

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef CSafeStaticLifeSpan CSafeStatic< T, Callbacks >::TLifeSpan

Definition at line 455 of file ncbi_safe_static.hpp.

◆ TThisType

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
typedef CSafeStatic<T, TCallbacks> CSafeStatic< T, Callbacks >::TThisType

Definition at line 454 of file ncbi_safe_static.hpp.

Constructor & Destructor Documentation

◆ CSafeStatic() [1/4]

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
CSafeStatic< T, Callbacks >::CSafeStatic ( TLifeSpan  life_span = TLifeSpan::GetDefault())
inline

Constructor.

Parameters
life_spanLife span allows to control destruction of objects. Objects with the same life span are destroyed in the order reverse to their creation order.
See also
CSafeStaticLifeSpan

Definition at line 470 of file ncbi_safe_static.hpp.

◆ CSafeStatic() [2/4]

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
CSafeStatic< T, Callbacks >::CSafeStatic ( FCreate  create,
FCleanup  cleanup,
TLifeSpan  life_span = TLifeSpan::GetDefault() 
)
inline

Constructor.

Parameters
initCallback function to be used to create the stored object.
cleanupCallback function to be used for additional cleanup.
life_spanLife span allows to control destruction of objects. Objects with the same life span are destroyed in the order reverse to their creation order.
See also
CSafeStaticLifeSpan

Definition at line 484 of file ncbi_safe_static.hpp.

◆ CSafeStatic() [3/4]

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
CSafeStatic< T, Callbacks >::CSafeStatic ( TCallbacks  callbacks,
TLifeSpan  life_span = TLifeSpan::GetDefault() 
)
inline

Constructor.

Parameters
callbacksCallbacks class instance.
life_spanLife span allows to control destruction of objects. Objects with the same life span are destroyed in the order reverse to their creation order.
See also
CSafeStaticLifeSpan

Definition at line 499 of file ncbi_safe_static.hpp.

◆ CSafeStatic() [4/4]

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
CSafeStatic< T, Callbacks >::CSafeStatic ( const CSafeStatic< T, Callbacks > &  )
privatedelete

Member Function Documentation

◆ Get()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
T& CSafeStatic< T, Callbacks >::Get ( void  )
inline

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

Definition at line 506 of file ncbi_safe_static.hpp.

Referenced by CUsedTlsBases::ClearAll(), CDiagContextThreadData::CollectDiagMessage(), CCgiApplication::ConfigureDiagFormat(), CNcbiEncrypt::Encrypt(), CObjectIStreamAsnBinary::ExpectStringTag(), get_date_range_rule_collection(), get_date_rule_collection(), GetBioseqInfoStack(), CDataSource::GetDefaultBlobCacheSizeLimit(), GetDefaultCDBErrorHandler(), CUrl::GetDefaultEncoder(), CSequenceAmbigTrimmer::GetDefaultTrimRules(), GetDiagContext(), CCgiRequest::GetEntry(), CGridGlobals::GetInstance(), CDriverManager::GetInstance(), CGraphCache< TData >::GetInstance(), CBlastLMDBManager::GetInstance(), NWinHook::CPEi386::GetInstance(), NWinHook::CApiHookMgr::GetInstance(), CSmallDNS::GetLocalHost(), GetModuleName(), GetObjStore(), CNcbiArguments::GetProgramName(), CCgiContext::GetRequestValue(), CObjectIStream::GetSource(), CUsedTlsBases::Init(), CDbapiConnMgr::Instance(), CTLibContextRegistry::Instance(), NWinHook::COnExitProcess::Instance(), CObjectOStreamAsnBinary::MakeUTF8StringTag(), CSafeStatic< CTls< TValue >, CStaticTls_Callbacks< TValue > >::operator*(), CSafeStatic< CTls< TValue >, CStaticTls_Callbacks< TValue > >::operator->(), CAsyncDiagHandler::Post(), CNcbiEncrypt::Reload(), s_GetCookieNameBannedSymbols(), s_GetFastTime(), s_GetNewIdHandle(), s_GetScopeAutoReleaseEnabled(), s_GetScopeAutoReleaseSize(), s_GetScopePostponeDelete(), CNcbiEncrypt::x_Decrypt(), CObjectIStream::x_GetFixCharsMethodDefault(), CObjectOStream::x_GetFixCharsMethodDefault(), CBV_PoolBlockAlloc< BA, Lock >::x_Instance(), CDiagContext::x_LogEnvironment(), SDiagMessage::x_OldWrite(), and CSharedHitId::x_SetHitId().

◆ operator*()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
T& CSafeStatic< T, Callbacks >::operator* ( void  )
inline

Definition at line 515 of file ncbi_safe_static.hpp.

◆ operator->()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
T* CSafeStatic< T, Callbacks >::operator-> ( void  )
inline

Definition at line 514 of file ncbi_safe_static.hpp.

◆ operator=()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
CSafeStatic& CSafeStatic< T, Callbacks >::operator= ( const CSafeStatic< T, Callbacks > &  )
privatedelete

◆ sx_SelfCleanup()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
static void CSafeStatic< T, Callbacks >::sx_SelfCleanup ( CSafeStaticPtr_Base safe_static,
TInstanceMutexGuard guard 
)
inlinestaticprivate

Definition at line 545 of file ncbi_safe_static.hpp.

◆ x_CastPtr()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
static T* CSafeStatic< T, Callbacks >::x_CastPtr ( const void *  ptr)
inlinestaticprivate

◆ x_Init()

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
void CSafeStatic< T, Callbacks >::x_Init ( void  )
inlineprivate

Member Data Documentation

◆ m_Callbacks

template<class T , class Callbacks = CSafeStatic_Callbacks<T>>
TCallbacks CSafeStatic< T, Callbacks >::m_Callbacks
private

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