ircproxy  The Ultimate Cyborg

Counter Class Reference

#include <Counter.h>

Inheritance diagram for Counter:

List of all members.


Detailed Description

A counter with scope-safe increment/decrement.

Use this class like:

Counter counter;

if (counter == 0)

To increment the counter, create an Increment object in a scope:

Increment increment(counter);

When increment is destructed, the counter will automatically be decremented again.

Definition at line 38 of file Counter.h.


Public Member Functions

 Counter (void)
 Constructor.
 ~Counter ()
 Destructor.
 operator int () const
 Automatic conversion to int.

Private Attributes

int M_counter
 Non-zero when locked.

Friends

class Increment
 Has direct access to M_counter.

Constructor & Destructor Documentation

Counter::Counter ( void   )  [inline]

Constructor.

Definition at line 44 of file Counter.h.

00044 : M_counter(0) { }

Counter::~Counter (  )  [inline]

Destructor.

Definition at line 46 of file Counter.h.

References ASSERT, and M_counter.

00046 { ASSERT(M_counter == 0); }


Member Function Documentation

Counter::operator int (  )  const [inline]

Automatic conversion to int.

Definition at line 49 of file Counter.h.

References M_counter.

00049 { return M_counter; }


Friends And Related Function Documentation

friend class Increment [friend]

Has direct access to M_counter.

Definition at line 40 of file Counter.h.


Member Data Documentation

int Counter::M_counter [private]

Non-zero when locked.

Definition at line 41 of file Counter.h.

Referenced by Increment::Increment(), operator int(), ~Counter(), and Increment::~Increment().


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

Copyright © 2005-2007 Carlo Wood.  All rights reserved.