NCBI C++ ToolKit
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
CGraphCache< TData > Class Template Reference

Search Toolkit Book for CGraphCache

CGraphCache –. More...

#include <gui/widgets/seq_graphic/graph_cache.hpp>

+ Inheritance diagram for CGraphCache< TData >:
+ Collaboration diagram for CGraphCache< TData >:

Public Member Functions

virtual ~CGraphCache ()
 
void Stop ()
 
CRef< TData > GetCachedData (const string &data_key)
 Retrieves TData from in-memory cache. More...
 
CRef< TData > GetData (const string &data_key)
 Retrieves TData from in-memory cache or if not found calls TData::Init to initialize new TData instance. More...
 
void RemoveData (const string &data_key)
 Removes Data from in-memory cache. More...
 
void SaveData (CRef< TData > data)
 Clones TData, puts it into Save Queue for asynchroneous storage operation. More...
 
void EnableICache (bool value)
 
- Public Member Functions inherited from CObject
 CObject (void)
 Constructor. More...
 
 CObject (const CObject &src)
 Copy constructor. More...
 
virtual ~CObject (void)
 Destructor. More...
 
CObjectoperator= (const CObject &src) THROWS_NONE
 Assignment operator. More...
 
bool CanBeDeleted (void) const THROWS_NONE
 Check if object can be deleted. More...
 
bool IsAllocatedInPool (void) const THROWS_NONE
 Check if object is allocated in memory pool (not system heap) More...
 
bool Referenced (void) const THROWS_NONE
 Check if object is referenced. More...
 
bool ReferencedOnlyOnce (void) const THROWS_NONE
 Check if object is referenced only once. More...
 
void AddReference (void) const
 Add reference to object. More...
 
void RemoveReference (void) const
 Remove reference to object. More...
 
void ReleaseReference (void) const
 Remove reference without deleting object. More...
 
virtual void DoNotDeleteThisObject (void)
 Mark this object as not allocated in heap – do not delete this object. More...
 
virtual void DoDeleteThisObject (void)
 Mark this object as allocated in heap – object can be deleted. More...
 
void * operator new (size_t size)
 Define new operator for memory allocation. More...
 
void * operator new[] (size_t size)
 Define new[] operator for 'array' memory allocation. More...
 
void operator delete (void *ptr)
 Define delete operator for memory deallocation. More...
 
void operator delete[] (void *ptr)
 Define delete[] operator for memory deallocation. More...
 
void * operator new (size_t size, void *place)
 Define new operator. More...
 
void operator delete (void *ptr, void *place)
 Define delete operator. More...
 
void * operator new (size_t size, CObjectMemoryPool *place)
 Define new operator using memory pool. More...
 
void operator delete (void *ptr, CObjectMemoryPool *place)
 Define delete operator. More...
 
virtual void DebugDump (CDebugDumpContext ddc, unsigned int depth) const
 Define method for dumping debug information. More...
 
- Public Member Functions inherited from CDebugDumpable
 CDebugDumpable (void)
 
virtual ~CDebugDumpable (void)
 
void DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const
 
void DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const
 
void DumpToConsole (void) const
 

Static Public Member Functions

static CGraphCacheGetInstance ()
 
- Static Public Member Functions inherited from CObject
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (void)
 Define method to throw null pointer exception. More...
 
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (const type_info &type)
 
static EAllocFillMode GetAllocFillMode (void)
 
static void SetAllocFillMode (EAllocFillMode mode)
 
static void SetAllocFillMode (const string &value)
 Set mode from configuration parameter value. More...
 
- Static Public Member Functions inherited from CDebugDumpable
static void EnableDebugDump (bool on)
 

Private Types

using TDataKey = string
 

Private Member Functions

 CGraphCache ()
 
 CGraphCache (const CGraphCache &)=delete
 
CGraphCacheoperator= (const CGraphCache &)=delete
 
void x_Run (CRef< CRequestContext > context)
 

Private Attributes

mutex m_Lock
 Saving Queue and Cache lock. More...
 
queue< CRef< TData > > m_Queue
 Saving Queue for storage operations. More...
 
bool m_HasICache = false
 Flag indicates if data should be saved into ICache. More...
 
map< TDataKey, CRef< TData > > m_Cache
 in-memory data cache More...
 
TGraphCachePool m_Storage
 ICache pool. More...
 
condition_variable m_CV
 wake-up signal for save requests More...
 
thread m_Thread
 background thread for save processing More...
 
atomic< boolm_StopRequested {false}
 flag to stop the backround thread More...
 

Friends

class CSafeStatic_Allocator< CGraphCache >
 

Additional Inherited Members

- Public Types inherited from CObject
enum  EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern }
 Control filling of newly allocated memory. More...
 
typedef CObjectCounterLocker TLockerType
 Default locker type for CRef. More...
 
typedef atomic< Uint8TCounter
 Counter type is CAtomiCounter. More...
 
typedef Uint8 TCount
 Alias for value type of counter. More...
 
- Static Public Attributes inherited from CObject
static const TCount eCounterBitsCanBeDeleted = 1 << 0
 Define possible object states. More...
 
static const TCount eCounterBitsInPlainHeap = 1 << 1
 Heap signature was found. More...
 
static const TCount eCounterBitsPlaceMask
 Mask for 'in heap' state flags. More...
 
static const int eCounterStep = 1 << 2
 Skip over the "in heap" bits. More...
 
static const TCount eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2)
 Minimal value for valid objects (reference counter is zero) Must be a single bit value. More...
 
static const TCount eCounterStateMask
 Valid object, and object in heap. More...
 
- Protected Member Functions inherited from CObject
virtual void DeleteThis (void)
 Virtual method "deleting" this object. More...
 

Detailed Description

template<class TData>
class CGraphCache< TData >

CGraphCache –.

in-memeory cache for graph data Provides concurrent access and asynchroneous storage operation for TData

TData is expected to provide: Init() - method to be called to initialize data Save() - method to serialize data

ICache storage is not used by default the caller needs to invoke EnableICache() to enable it

if ICache is enabled GraphCache start a backround thread (m_Thread) on first save request The consecutive save request sends a copy of data to m_Queue for asynchroneous Save.

Definition at line 93 of file graph_cache.hpp.

Member Typedef Documentation

◆ TDataKey

template<class TData >
using CGraphCache< TData >::TDataKey = string
private

Definition at line 232 of file graph_cache.hpp.

Constructor & Destructor Documentation

◆ ~CGraphCache()

template<class TData >
virtual CGraphCache< TData >::~CGraphCache ( )
inlinevirtual

Definition at line 103 of file graph_cache.hpp.

References ERR_POST, Error(), and CGraphCache< TData >::Stop().

◆ CGraphCache() [1/2]

template<class TData >
CGraphCache< TData >::CGraphCache ( )
inlineprivate

Definition at line 196 of file graph_cache.hpp.

◆ CGraphCache() [2/2]

template<class TData >
CGraphCache< TData >::CGraphCache ( const CGraphCache< TData > &  )
privatedelete

Member Function Documentation

◆ EnableICache()

template<class TData >
void CGraphCache< TData >::EnableICache ( bool  value)
inline

Definition at line 192 of file graph_cache.hpp.

References CGraphCache< TData >::m_HasICache, and value.

Referenced by CSGAlignmentDS::EnablePileUpCache().

◆ GetCachedData()

template<class TData >
CRef<TData> CGraphCache< TData >::GetCachedData ( const string data_key)
inline

Retrieves TData from in-memory cache.

Parameters
data_keymemory access key generated by TData
Returns
instance of TData or NULL if there are no cached data

Definition at line 124 of file graph_cache.hpp.

References CGraphCache< TData >::m_Cache, and CGraphCache< TData >::m_Lock.

Referenced by CSGAlignmentDS::IsGraphCached(), CVcfFeatureJob::x_Execute(), and CSGFeatureJob::x_ProcessCachedVcfTabix().

◆ GetData()

template<class TData >
CRef<TData> CGraphCache< TData >::GetData ( const string data_key)
inline

Retrieves TData from in-memory cache or if not found calls TData::Init to initialize new TData instance.

Parameters
data_keymemory access key generated by TData
Returns
instance of TData or NULL if there are no cached data and TData does not have ICache

Definition at line 140 of file graph_cache.hpp.

References CGraphCache< TData >::m_Cache, CGraphCache< TData >::m_HasICache, CGraphCache< TData >::m_Lock, CGraphCache< TData >::m_Storage, and Ref().

Referenced by CSGAlignmentDS::CanShowRange(), CSGAlignmentDS::GetGraphCost(), CSGAlignmentDS::IsRangeCached(), CSGAlignStatJob::x_Execute(), CSGSeqGraphJob::x_Execute(), CVcfFeatureJob::x_Execute(), and CSGFeatureJob::x_ProcessCachedBigBed().

◆ GetInstance()

template<class TData >
static CGraphCache& CGraphCache< TData >::GetInstance ( void  )
inlinestatic

◆ operator=()

template<class TData >
CGraphCache& CGraphCache< TData >::operator= ( const CGraphCache< TData > &  )
privatedelete

◆ RemoveData()

template<class TData >
void CGraphCache< TData >::RemoveData ( const string data_key)
inline

Removes Data from in-memory cache.

Parameters
data_keymemory access key generated by TData

Definition at line 161 of file graph_cache.hpp.

References map_checker< Container >::end(), map_checker< Container >::erase(), map_checker< Container >::find(), CGraphCache< TData >::m_Cache, and CGraphCache< TData >::m_Lock.

Referenced by CSGAlignmentDS::ClearCache(), and CSGAlignStatJob::x_Execute().

◆ SaveData()

template<class TData >
void CGraphCache< TData >::SaveData ( CRef< TData >  data)
inline

◆ Stop()

template<class TData >
void CGraphCache< TData >::Stop ( void  )
inline

◆ x_Run()

template<class TData >
void CGraphCache< TData >::x_Run ( CRef< CRequestContext context)
inlineprivate

Friends And Related Function Documentation

◆ CSafeStatic_Allocator< CGraphCache >

template<class TData >
friend class CSafeStatic_Allocator< CGraphCache >
friend

Definition at line 196 of file graph_cache.hpp.

Member Data Documentation

◆ m_Cache

template<class TData >
map<TDataKey, CRef<TData> > CGraphCache< TData >::m_Cache
private

◆ m_CV

template<class TData >
condition_variable CGraphCache< TData >::m_CV
private

wake-up signal for save requests

Definition at line 237 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::SaveData(), CGraphCache< TData >::Stop(), and CGraphCache< TData >::x_Run().

◆ m_HasICache

template<class TData >
bool CGraphCache< TData >::m_HasICache = false
private

Flag indicates if data should be saved into ICache.

Definition at line 230 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::EnableICache(), CGraphCache< TData >::GetData(), and CGraphCache< TData >::SaveData().

◆ m_Lock

template<class TData >
mutex CGraphCache< TData >::m_Lock
private

◆ m_Queue

template<class TData >
queue<CRef<TData> > CGraphCache< TData >::m_Queue
private

Saving Queue for storage operations.

Definition at line 228 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::SaveData(), and CGraphCache< TData >::x_Run().

◆ m_StopRequested

template<class TData >
atomic<bool> CGraphCache< TData >::m_StopRequested {false}
private

flag to stop the backround thread

Definition at line 239 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::Stop(), and CGraphCache< TData >::x_Run().

◆ m_Storage

template<class TData >
TGraphCachePool CGraphCache< TData >::m_Storage
private

ICache pool.

Definition at line 235 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::GetData(), and CGraphCache< TData >::x_Run().

◆ m_Thread

template<class TData >
thread CGraphCache< TData >::m_Thread
private

background thread for save processing

Definition at line 238 of file graph_cache.hpp.

Referenced by CGraphCache< TData >::SaveData(), and CGraphCache< TData >::Stop().


The documentation for this class was generated from the following file:
Modified on Sat Dec 02 09:22:36 2023 by modify_doxy.py rev. 669887