CObject Class Reference
[Smart Pointers with Reference Counting]

Search Toolkit Book for CObject

#include <ncbiobj.hpp>

Inheritance diagram for CObject:

Inheritance graph
[legend]
Collaboration diagram for CObject:

Collaboration graph
[legend]
List of all members.

Detailed Description

CObject --.

Define the CObject which stores the reference count and the object.

CObject inherits from CDebugDumpable the ability to "dump" diagnostic information useful for debugging.

Definition at line 154 of file ncbiobj.hpp.

Public Types

typedef CObjectCounterLocker TLockerType
 Default locker type for CRef.
enum  EAllocFillMode { eAllocFillNone = 1, eAllocFillZero, eAllocFillPattern }
 Controll filling of newly allocated memory. More...

Public Member Functions

 CObject (void)
 Constructor.
 CObject (const CObject &src)
 Copy constructor.
virtual ~CObject (void)
 Destructor.
CObjectoperator= (const CObject &src) THROWS_NONE
 Assignment operator.
bool CanBeDeleted (void) const THROWS_NONE
 Check if object can be deleted.
bool IsAllocatedInPool (void) const THROWS_NONE
 Check if object is allocated in memory pool (not system heap).
bool Referenced (void) const THROWS_NONE
 Check if object is referenced.
bool ReferencedOnlyOnce (void) const THROWS_NONE
 Check if object is referenced only once.
void AddReference (void) const
 Add reference to object.
void RemoveReference (void) const
 Remove reference to object.
void ReleaseReference (void) const
 Remove reference without deleting object.
virtual void DoNotDeleteThisObject (void)
 Mark this object as not allocated in heap -- do not delete this object.
virtual void DoDeleteThisObject (void)
 Mark this object as allocated in heap -- object can be deleted.
void * operator new (size_t size)
 Define new operator for memory allocation.
void * operator new[] (size_t size)
 Define new[] operator for 'array' memory allocation.
void operator delete (void *ptr)
 Define delete operator for memory deallocation.
void operator delete[] (void *ptr)
 Define delete[] operator for memory deallocation.
void * operator new (size_t size, void *place)
 Define new operator.
void operator delete (void *ptr, void *place)
 Define delete operator.
void * operator new (size_t size, CObjectMemoryPool *place)
 Define new operator using memory pool.
void operator delete (void *ptr, CObjectMemoryPool *place)
 Define delete operator.
virtual void DebugDump (CDebugDumpContext ddc, unsigned int depth) const
 Define method for dumping debug information.

Static Public Member Functions

static void ThrowNullPointerException (void)
 Define method to throw null pointer exception.
static 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.

Protected Member Functions

virtual void DeleteThis (void) const
 Virtual method "deleting" this object.

Private Types

typedef CAtomicCounter TCounter
 Counter type is CAtomiCounter.
typedef TCounter::TValue TCount
 Alias for value type of counter.
enum  EObjectState {
  eStateBitsInHeap = 1 << 0, eStateBitsHeapSignature = 1 << 1, eStateBitsInHeapMask = eStateBitsInHeap | eStateBitsHeapSignature, eStateBitsValid = (unsigned int)(1 << (sizeof(TCount) * 8 - 2)),
  eStateMask = eStateBitsValid | eStateBitsInHeapMask, eCounterStep = 1 << 2, eCounterValid = eStateBitsValid, eCounterValidRef1 = eCounterValid + eCounterStep,
  eCounterValidRef2 = eCounterValid + eCounterStep*2, eInitCounterNotInHeap = eStateBitsValid, eInitCounterInHeap, eInitCounterInPool = eStateBitsValid | eStateBitsInHeap,
  eInitCounterInStack = eStateBitsValid | eStateBitsHeapSignature, eMagicCounterDeleted = 0x5b4d9f34 & ~eStateMask, eMagicCounterNew = 0x3423cb13 & ~eStateMask, eMagicCounterPoolDeleted = 0x4229775b & ~eStateMask,
  eMagicCounterPoolNew = 0x54917ec2 & ~eStateMask
}
 Define possible object states. More...

Private Member Functions

void InitCounter (void)
 Initialize counter.
void RemoveLastReference (TCount count) const
 Remove the last reference.
void InvalidObject (void) const
 Report object is invalid.
void CheckReferenceOverflow (TCount count) const
 Report that counter has overflowed.

Static Private Member Functions

static bool ObjectStateValid (TCount count)
 Check if object state is valid.
static bool ObjectStateCanBeDeleted (TCount count)
 Check if object can be deleted.
static bool ObjectStateIsAllocatedInPool (TCount count)
 Check if object is allocated in memory pool.
static bool ObjectStateUnreferenced (TCount count)
 Check if object can be referenced.
static bool ObjectStateReferenced (TCount count)
 Check if object can be referenced.
static bool ObjectStateReferencedOnlyOnce (TCount count)
 Check if object can be referenced only once.

Private Attributes

TCounter m_Counter
 The actual reference counter.

Friends

class CObjectMemoryPool
class CObjectEx


Member Typedef Documentation

typedef TCounter::TValue CObject::TCount [private]
 

Alias for value type of counter.

Reimplemented in CAcqSpecification_Base::C_Attlist, CAnalyzerList_Base::C_Attlist, CPrecursorList_Base::C_Attlist, CSpectrumList_Base::C_Attlist, CAcquisitionList_Base::C_Attlist, CAcquisitionSettingsList_Base::C_Attlist, CBinaryDataArrayList_Base::C_Attlist, CChromatogramList_Base::C_Attlist, CComponentList_Base::C_Attlist, CCvList_Base::C_Attlist, CDataProcessingList_Base::C_Attlist, CInstrumentConfigurationList_Base::C_Attlist, CPrecursorList_Base::C_Attlist, CReferenceableParamGroupList_Base::C_Attlist, CSampleList_Base::C_Attlist, CScanWindowList_Base::C_Attlist, CSelectedIonList_Base::C_Attlist, CSoftwareList_Base::C_Attlist, CSourceFileList_Base::C_Attlist, CSourceFileRefList_Base::C_Attlist, CSpectrumList_Base::C_Attlist, CTargetList_Base::C_Attlist, CCdd_repeat_Base, CEntrez2_boolean_reply_Base, CEntrez2_docsum_list_Base, CEntrez2_term_Base, CPC_Compound_Base, and CID2S_Gi_Range_Base.

Definition at line 285 of file ncbiobj.hpp.

typedef CAtomicCounter CObject::TCounter [private]
 

Counter type is CAtomiCounter.

Reimplemented in CGBProject_Base, and CGBProject_ver2_Base.

Definition at line 284 of file ncbiobj.hpp.

typedef CObjectCounterLocker CObject::TLockerType
 

Default locker type for CRef.

Definition at line 158 of file ncbiobj.hpp.


Member Enumeration Documentation

enum CObject::EAllocFillMode
 

Controll filling of newly allocated memory.

Default mode is eAllocFillNone if not changed by configuration. eAllocFillNone - do not fill at all this mode is faster and is necessary to avoid interference with memory checker programs like valgrind. eAllocFillZero - fill new memory with zeros (old default mode) eAllocFillPattern - fill with non-zero pattern

Enumerator:
eAllocFillNone 
eAllocFillZero 
eAllocFillPattern 

Definition at line 261 of file ncbiobj.hpp.

enum CObject::EObjectState [private]
 

Define possible object states.

When TCounter is signed, all valid values start with 01; when it is unsigned, they start with 1. In other words, when TCounter is signed, the msb (most significant bit) is 0, and the bit after that is a 1; and if the counter is unsigned, then the msb is 1.

Least significant bits are the "memory" bits and the most significant bit (or the one after it) is the "valid" bit.

The following bit positions have special significance:

  • Least significant bit = 0 means object not in heap.
  • Least significant bit = 1 means object in heap.
  • Most significant bit (or one after it) = 0 means object not valid
  • Most significant bit (or one after it) = 1 means object is valid

Possible bit patterns:

  • [0]0x...xxxx : non valid object -> cannot be referenced.
  • [0]1c...ccx0 : object not in heap -> cannot be deleted.
  • [0]1c...cc01 : illegal; should be impossible to achieve.
  • [0]1c...cc11 : object in heap -> can be deleted.
Enumerator:
eStateBitsInHeap  Detected as in heap.
eStateBitsHeapSignature  Heap signature was found.
eStateBitsInHeapMask  Mask for 'in heap' state flags.
eStateBitsValid  1 in the left most of the valid bits -- signed case
eStateMask  Valid object, and object in heap.
eCounterStep  Skip over the "in heap" bits.
eCounterValid  Minimal value for valid objects (reference counter is zero).
eCounterValidRef1  Minimal value for referenced valid objects (reference counter = 1).
eCounterValidRef2  Minimal value for double referenced objects (reference counter = 2).
eInitCounterNotInHeap  Initial counter value for non-heap objects.
eInitCounterInHeap  Initial counter value for in-heap objects.
eInitCounterInPool  Initial counter value for objects allocated in memory pool.
eInitCounterInStack  Initial counter value for probably non-heap objects (w/ signature).
eMagicCounterDeleted  All magic counter values should have all their state bits off.

Magic counter value for deleted objects

eMagicCounterNew  Magic counter value for object allocated in heap.
eMagicCounterPoolDeleted  Magic counter value for deleted object allocated in memory pool.
eMagicCounterPoolNew  Magic counter value for objects allocated in memory pool.

Definition at line 308 of file ncbiobj.hpp.


Constructor & Destructor Documentation

CObject::CObject void   ) 
 

Constructor.

Definition at line 435 of file ncbiobj.cpp.

References InitCounter().

Referenced by CObjectMemoryPool::Delete().

CObject::CObject const CObject src  ) 
 

Copy constructor.

Definition at line 441 of file ncbiobj.cpp.

References InitCounter().

CObject::~CObject void   )  [virtual]
 

Destructor.

Definition at line 453 of file ncbiobj.cpp.

References _ASSERT, eMagicCounterDeleted, eMagicCounterPoolDeleted, ERR_POST_X, CAtomicCounter::Get(), m_Counter, ObjectStateIsAllocatedInPool(), ObjectStateReferenced(), ObjectStateUnreferenced(), ObjectStateValid(), ObjFatal, and CAtomicCounter::Set().


Member Function Documentation

void CObject::CheckReferenceOverflow TCount  count  )  const [private]
 

Report that counter has overflowed.

Definition at line 488 of file ncbiobj.cpp.

References eMagicCounterDeleted, eMagicCounterPoolDeleted, NCBI_THROW, and ObjectStateValid().

Referenced by AddReference().

void CObject::DebugDump CDebugDumpContext  ddc,
unsigned int  depth
const [virtual]
 

Define method for dumping debug information.

Implements CDebugDumpable.

Reimplemented in CBLAST_SequenceBlk, CBlastQueryInfo, CQuerySetUpOptions, CLookupTableOptions, CLookupTableWrap, CBlastInitialWordOptions, CBlastInitialWordParameters, CBlast_ExtendWord, CBlastExtensionOptions, CBlastExtensionParameters, CBlastHitSavingOptions, CBlastHitSavingParameters, CPSIBlastOptions, CBlastDatabaseOptions, CBlastScoreBlk, CBlastScoringOptions, CBlastScoringParameters, CBlastEffectiveLengthsOptions, CBlastEffectiveLengthsParameters, CBlastGapAlignStruct, CBlastHSPResults, CPSIMsa, CPSIMatrix, CPSIDiagnosticsRequest, CPSIDiagnosticsResponse, CBlastSeqSrc, CBlastSeqSrcIterator, CBlast_Message, CBlastMaskLoc, CBlastSeqLoc, CSBlastProgress, CBlastOptions, CBlastDbDataLoader, CRemoteBlastDbDataLoader, CSerialObject, and CBlastOptionsLocal.

Definition at line 669 of file ncbiobj.cpp.

References CDebugDumpContext::Log(), and CDebugDumpContext::SetFrame().

Referenced by CSerialObject::DebugDump().

void CObject::DeleteThis void   )  const [protected, virtual]
 

Virtual method "deleting" this object.

Method is called whenever by all other indicators this object should be deleted. These indicators are: last reference to the object is removed, object created on heap and method DoNotDeleteThisObject() was not called. Default implementation actually deletes the object, but derived classes are free to do whatever they want (e.g. if they know that they are allocated at some pool they should return themselves to this pool).

Reimplemented in CRWLockHolder, and CNCBlobLockHolder.

Definition at line 512 of file ncbiobj.cpp.

References _ASSERT, CObjectMemoryPool::Delete(), eInitCounterInHeap, eInitCounterInPool, CAtomicCounter::Get(), and m_Counter.

Referenced by RemoveLastReference().

void CObject::DoDeleteThisObject void   )  [virtual]
 

Mark this object as allocated in heap -- object can be deleted.

Definition at line 616 of file ncbiobj.cpp.

References CAtomicCounter::Add(), eMagicCounterDeleted, eMagicCounterPoolDeleted, ERR_POST_X, eStateBitsHeapSignature, eStateBitsInHeap, eStateBitsValid, CAtomicCounter::Get(), m_Counter, NCBI_THROW, ObjectStateValid(), and ObjFatal.

Referenced by CObjectMemoryPoolChunk::CreateChunk(), CThread::CThread(), and CTls< TValue >::CTls().

void CObject::DoNotDeleteThisObject void   )  [virtual]
 

Mark this object as not allocated in heap -- do not delete this object.

Definition at line 587 of file ncbiobj.cpp.

References CAtomicCounter::Add(), eMagicCounterDeleted, eMagicCounterPoolDeleted, eStateBitsInHeapMask, CAtomicCounter::Get(), m_Counter, NCBI_THROW, and ObjectStateValid().

CObject::EAllocFillMode CObject::GetAllocFillMode void   )  [static]
 

Definition at line 203 of file ncbiobj.cpp.

void CObject::InitCounter void   )  [private]
 

Initialize counter.

Definition at line 370 of file ncbiobj.cpp.

References eInitCounterInHeap, eInitCounterInPool, eInitCounterInStack, eInitCounterNotInHeap, eMagicCounterNew, eMagicCounterPoolNew, GetSecondCounter(), m_Counter, CAtomicCounter::m_Value, CAtomicCounter::Set(), and STACK_THRESHOLD.

Referenced by CObject().

void CObject::InvalidObject void   )  const [private]
 

Report object is invalid.

Example: Attempt to use a deleted object.

void CObject::operator delete void *  ptr,
CObjectMemoryPool place
 

Define delete operator.

Definition at line 331 of file ncbiobj.cpp.

References _ASSERT, CObjectMemoryPool::Deallocate(), eMagicCounterPoolDeleted, eMagicCounterPoolNew, CAtomicCounter::Get(), and m_Counter.

void CObject::operator delete void *  ptr,
void *  place
 

Define delete operator.

void CObject::operator delete void *  ptr  ) 
 

Define delete operator for memory deallocation.

Definition at line 275 of file ncbiobj.cpp.

References _ASSERT, eMagicCounterDeleted, eMagicCounterNew, CAtomicCounter::Get(), m_Counter, and operator().

void CObject::operator delete[] void *  ptr  ) 
 

Define delete[] operator for memory deallocation.

Definition at line 359 of file ncbiobj.cpp.

References operator().

void * CObject::operator new size_t  size,
CObjectMemoryPool place
 

Define new operator using memory pool.

Definition at line 313 of file ncbiobj.cpp.

References _ASSERT, CObjectMemoryPool::Allocate(), eMagicCounterPoolNew, GetSecondCounter(), m_Counter, operator new(), and CAtomicCounter::Set().

void * CObject::operator new size_t  size,
void *  place
 

Define new operator.

Definition at line 290 of file ncbiobj.cpp.

References _ASSERT, and sx_FillNewMemory().

void * CObject::operator new size_t  size  ) 
 

Define new operator for memory allocation.

Definition at line 245 of file ncbiobj.cpp.

References _ASSERT, eMagicCounterNew, GetSecondCounter(), m_Counter, operator(), CAtomicCounter::Set(), and sx_FillNewMemory().

Referenced by CObjectMemoryPoolChunk::CreateChunk(), and operator new().

void * CObject::operator new[] size_t  size  ) 
 

Define new[] operator for 'array' memory allocation.

Definition at line 347 of file ncbiobj.cpp.

References operator(), and sx_FillNewMemory().

void CObject::ReleaseReference void   )  const
 

Remove reference without deleting object.

Definition at line 563 of file ncbiobj.cpp.

References CAtomicCounter::Add(), eCounterStep, eMagicCounterDeleted, eMagicCounterPoolDeleted, m_Counter, NCBI_THROW, and ObjectStateValid().

Referenced by CInterfaceObjectLocker< Interface >::UnlockRelease(), CObjectCounterLocker::UnlockRelease(), and impl::CDBHandlerStack::CUserHandlerWrapper::CObjGuard::~CObjGuard().

void CObject::RemoveLastReference TCount  count  )  const [private]
 

Remove the last reference.

Definition at line 527 of file ncbiobj.cpp.

References CAtomicCounter::Add(), DeleteThis(), eCounterStep, eMagicCounterDeleted, eMagicCounterPoolDeleted, ERR_POST_X, m_Counter, ObjectStateCanBeDeleted(), ObjectStateUnreferenced(), ObjectStateValid(), and ObjFatal.

Referenced by RemoveReference().

void CObject::SetAllocFillMode const string &  value  )  [static]
 

Set mode from configuration parameter value.

Definition at line 215 of file ncbiobj.cpp.

References ALLOC_FILL_MODE_DEFAULT, NStr::CompareNocase(), eAllocFillNone, eAllocFillPattern, and eAllocFillZero.

void CObject::SetAllocFillMode EAllocFillMode  mode  )  [static]
 

Definition at line 209 of file ncbiobj.cpp.

Referenced by CNcbiApplication::x_HonorStandardSettings().

void CObject::ThrowNullPointerException const type_info &  type  )  [static]
 

Definition at line 696 of file ncbiobj.cpp.

References Abort().

void CObject::ThrowNullPointerException void   )  [static]
 

Define method to throw null pointer exception.

Static method through which all CRef<> / CConstRef<> null pointer throws travel. This is done to avoid an inline throw.

Definition at line 683 of file ncbiobj.cpp.

References Abort().

Referenced by CConstRef< IAppJobError, CInterfaceObjectLocker< IAppJobError > >::ThrowNullPointerException(), and CRef< CQueueItem >::ThrowNullPointerException().


Friends And Related Function Documentation

friend class CObjectEx [friend]
 

Definition at line 364 of file ncbiobj.hpp.

friend class CObjectMemoryPool [friend]
 

Definition at line 363 of file ncbiobj.hpp.


Member Data Documentation

TCounter CObject::m_Counter [mutable, private]
 

The actual reference counter.

Reimplemented in CGBProject_Base, CGBProject_ver2_Base, and CSeqIdGenerator.

Definition at line 404 of file ncbiobj.hpp.

Referenced by AddReference(), CanBeDeleted(), DeleteThis(), DoDeleteThisObject(), DoNotDeleteThisObject(), InitCounter(), IsAllocatedInPool(), operator delete(), operator new(), Referenced(), ReferencedOnlyOnce(), ReleaseReference(), RemoveLastReference(), RemoveReference(), CObjectEx::WeakAddReference(), and ~CObject().


The documentation for this class was generated from the following files:
Generated on Mon Dec 7 13:11:02 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:23:35 2009 by modify_doxy.py rev. 173732