Ceylan::Countable Class Reference

This very simple class allows instance counting for all objects that inherit from it. More...

#include <CeylanCountable.h>

Collaboration diagram for Ceylan::Countable:

Collaboration graph
[legend]

List of all members.

Public Types

typedef Ceylan::Uint32 InstanceCount
 Records rhe number of instances.

Public Member Functions

 Countable (bool verbose=true)
 Constructs a Countable, increments the global reference count.
virtual ~Countable () throw ()
 The virtual destructor decrements the reference count.

Static Public Member Functions

static const std::string ToString (Ceylan::VerbosityLevels level=Ceylan::high)
 Returns informations about the global reference count.
static InstanceCount GetInstanceCount ()
 Returns the current instance count.
static InstanceCount GetMaximumInstanceCount ()
 Returns the current maximum instance count ever reached in this run.

Private Member Functions

 Countable (const Countable &source)
 Copy constructor made private to ensure that it will never be called.
Countableoperator= (const Countable &source)
 Assignment operator made private to ensure that it will never be called.

Private Attributes

bool _verbose
 Tells whether count changes should be recorded in LightLog.

Static Private Attributes

static InstanceCount ReferenceCount = 0
 The current reference count.
static InstanceCount MaximumReferenceCount = 0
 The maximum reference count that has been already reached.
static const std::string LogPrefix = "[Instance count]"
 The prefix used when instance counts are logged.


Detailed Description

This very simple class allows instance counting for all objects that inherit from it.

Its main use is to check that every Countable is rightly deallocated when appropriate, i.e. each program should end up with a null instance count.

Note:
This can only tell how many objects implementing this interface are alive at any given time, no matter what their actual class is: one cannot tell which they are, what is their type. So it gives the number of elements of a set, not its elements. Some more work is therefore needed to track down objects that should be deallocated but are not. Using Ceylan::Object with trackInstance set to true or Valgrind would be a solution.
See also:
Ceylan::Object

http://valgrind.kde.org

Definition at line 65 of file CeylanCountable.h.


Member Typedef Documentation

Records rhe number of instances.

Definition at line 74 of file CeylanCountable.h.


Constructor & Destructor Documentation

Countable::Countable ( bool  verbose = true  )  [explicit]

Constructs a Countable, increments the global reference count.

Parameters:
verbose tells whether LogLight should be used to publish changes of instances counts.
Note:
LogLight has to be enabled at compile-time (CEYLAN_DEBUG_LOG flag) to have those informations displayed.

Definition at line 52 of file CeylanCountable.cc.

References _verbose, CEYLAN_LOG, LogPrefix, MaximumReferenceCount, ReferenceCount, and Ceylan::toString().

Countable::~Countable (  )  throw () [virtual]

The virtual destructor decrements the reference count.

Definition at line 72 of file CeylanCountable.cc.

References _verbose, CEYLAN_LOG, Ceylan::emergencyShutdown(), LogPrefix, MaximumReferenceCount, ReferenceCount, and Ceylan::toString().

Ceylan::Countable::Countable ( const Countable source  )  [private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

Countable::InstanceCount Countable::GetInstanceCount (  )  [static]

Returns the current instance count.

Definition at line 102 of file CeylanCountable.cc.

References ReferenceCount.

Countable::InstanceCount Countable::GetMaximumInstanceCount (  )  [static]

Returns the current maximum instance count ever reached in this run.

Definition at line 111 of file CeylanCountable.cc.

References MaximumReferenceCount.

Countable& Ceylan::Countable::operator= ( const Countable source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

const string Countable::ToString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  [static]

Returns informations about the global reference count.

See also:
TextDisplayable, Displayable

Ceylan::VerbosityLevels

Definition at line 92 of file CeylanCountable.cc.

References MaximumReferenceCount, ReferenceCount, and Ceylan::toString().


Member Data Documentation

Tells whether count changes should be recorded in LightLog.

Note:
This is a per-instance member.

Definition at line 132 of file CeylanCountable.h.

Referenced by Countable(), and ~Countable().

const string Countable::LogPrefix = "[Instance count]" [static, private]

The prefix used when instance counts are logged.

Definition at line 144 of file CeylanCountable.h.

Referenced by Countable(), and ~Countable().

The maximum reference count that has been already reached.

Definition at line 140 of file CeylanCountable.h.

Referenced by Countable(), GetMaximumInstanceCount(), ToString(), and ~Countable().

The current reference count.

Definition at line 136 of file CeylanCountable.h.

Referenced by Countable(), GetInstanceCount(), ToString(), and ~Countable().


The documentation for this class was generated from the following files:

Generated on Thu Jun 4 20:40:11 2009 for Ceylan by  doxygen 1.5.8