libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Attributes | List of all members
ASSA::IdSet Class Reference

#include <IdSet.h>

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.

{
::memset (&m_id_set_map, 0, sizeof (m_id_set_map));
}

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.

{
}
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.

{
register int i;
register int current;
trace("IdSet::newid");
current = m_next_available_id++;
if (m_next_available_id < FD_SETSIZE)
{
// mark current id as being in use
FD_SET(current, &m_id_set_map);
// search starting from current position to the end
// assuming that m_next_available_id is maintained
// to be the lowest available at all times.
for (i=current+1; i<FD_SETSIZE; i++)
{
if (!FD_ISSET(i, &m_id_set_map))
{
return current;
}
}
// if I am here, I am out of ids
m_next_available_id = FD_SETSIZE;
}
return -1;
}
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.

{
trace("IdSet::recycle");
if ( 0 <= id_ && id_ < FD_SETSIZE ) {
FD_CLR(id_, &m_id_set_map); // mark id as free
// if id is smaller then current, adjust current
if (id_ < m_next_available_id) {
}
return 0;
}
return -1;
}

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().

int ASSA::IdSet::m_next_available_id
private

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: