ASSA::IdSet Class Reference

#include <IdSet.h>

List of all members.

Public Member Functions

 IdSet ()
 Default constructor creates IdSet object with ID equals to 0.
int newid ()
 Return current id.
int recycle (int id_)
 Recycle id_.
int currid () const
 Get current id.

Private Attributes

int m_next_available_id
 Current id.
fd_set m_id_set_map
 Map of all ids.

Detailed Description

Definition at line 38 of file IdSet.h.


Constructor & Destructor Documentation

ASSA::IdSet::IdSet (  )  [inline]

Default constructor creates IdSet object with ID equals to 0.

Definition at line 71 of file IdSet.h.

References m_id_set_map.

00072     : m_next_available_id (0)
00073 {
00074     ::memset (&m_id_set_map, 0, sizeof (m_id_set_map));
00075 }


Member Function Documentation

int ASSA::IdSet::currid (  )  const [inline]

Get current id.

This function just returns current id without changing anything.

Definition at line 79 of file IdSet.h.

References m_next_available_id.

00080 {
00081     return m_next_available_id;
00082 }

int IdSet::newid (  ) 

Return current id.

Mark it as being in use and set new current id value to the next lowest available.

Definition at line 20 of file IdSet.cpp.

References m_id_set_map, m_next_available_id, and trace.

00021 {
00022     register int i;
00023     register int current;
00024 
00025     trace("IdSet::newid");
00026 
00027     current = m_next_available_id++;
00028 
00029     if (m_next_available_id < FD_SETSIZE) 
00030     {
00031     // mark current id as being in use
00032     FD_SET(current, &m_id_set_map);
00033 
00034     // search starting from current position to the end 
00035     // assuming that m_next_available_id is maintained
00036     // to be the lowest available at all times.
00037 
00038     for (i=current+1; i<FD_SETSIZE; i++) 
00039     {
00040         if (!FD_ISSET(i, &m_id_set_map)) 
00041         {
00042         m_next_available_id = i;
00043         return current;
00044         }
00045     }
00046     // if I am here, I am out of ids
00047     m_next_available_id = FD_SETSIZE;
00048     }
00049     return -1;
00050 }

int IdSet::recycle ( int  id_  ) 

Recycle id_.

Mark it as available and adjust current id if necessary.

Definition at line 54 of file IdSet.cpp.

References m_id_set_map, m_next_available_id, and trace.

00055 {
00056     trace("IdSet::recycle");
00057 
00058     if ( 0 <= id_ && id_ < FD_SETSIZE ) {
00059         FD_CLR(id_, &m_id_set_map); // mark id as free
00060         
00061         // if id is smaller then current, adjust current
00062         if (id_ < m_next_available_id) {
00063             m_next_available_id = id_;
00064         }
00065         return 0;
00066     }
00067     return -1;
00068 }


Member Data Documentation

fd_set ASSA::IdSet::m_id_set_map [private]

Map of all ids.

Definition at line 66 of file IdSet.h.

Referenced by IdSet(), newid(), and recycle().

Current id.

Definition at line 62 of file IdSet.h.

Referenced by currid(), newid(), and recycle().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Thu Sep 24 22:04:36 2009 for libassa by  doxygen 1.6.1