library of assembled shared sources

http://lass.cocamware.com

lass::util::IdGenerator< T > Class Template Reference

Generates sequential and unique ID's. More...

#include <id_generator.h>


Public Member Functions

 IdGenerator (typename CallTraits< T >::TParam iFirstId=0)
 Construct an ID generator of which iFirstId is the first ID to be generated.
CallTraits< T >::TValue operator() ()
 Generate an ID.
void setNext (typename CallTraits< T >::TParam iNextId)
 set the next ID to be drawn.

Private Attributes

CallTraits< T >::TValue nextId_


Detailed Description

template<typename T>
class lass::util::IdGenerator< T >

Generates sequential and unique ID's.

Author:
Bram de Greve
Date:
2003
Pretty simple. This object generates unique ID numbers, each incremented by one, starting from a given ID.

  IdGenerator<unsigned> generator;
  LASS_COUT << generator() << "\n"; // will print '0'
  LASS_COUT << generator() << "\n"; // will print '1'
  LASS_COUT << generator() << "\n"; // will print '2'
  LASS_COUT << generator() << "\n"; // will print '3'
  ...

requirements for T:
  • T must implement prefix increment, operator++
  • T must be less-than comparable, operator<
  • T must be copy-constructible

Definition at line 87 of file id_generator.h.


Constructor & Destructor Documentation

template<typename T >
lass::util::IdGenerator< T >::IdGenerator ( typename CallTraits< T >::TParam  iFirstId = 0  )  [inline]

Construct an ID generator of which iFirstId is the first ID to be generated.

Definition at line 62 of file id_generator.inl.


Member Function Documentation

template<typename T >
CallTraits< T >::TValue lass::util::IdGenerator< T >::operator() (  )  [inline]

Generate an ID.

Each call to this operator will give you a new ID incremented by one.

Exceptions:
an exception is thrown if the generator can no longer increment the id field. Since the generator stores the id that will be returned on the next call, this means the maximum id returned will be num::NumTraits<T>::max-1

Definition at line 76 of file id_generator.inl.

References LASS_THROW, and lass::util::IdGenerator< T >::nextId_.

template<typename T >
void lass::util::IdGenerator< T >::setNext ( typename CallTraits< T >::TParam  iNextId  )  [inline]

set the next ID to be drawn.

Definition at line 92 of file id_generator.inl.

References lass::util::IdGenerator< T >::nextId_.


Field Documentation

template<typename T >
CallTraits<T>::TValue lass::util::IdGenerator< T >::nextId_ [private]


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

Generated on Mon Nov 10 14:22:17 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo