Loading...
Searching...
No Matches
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

## IdSet()

ASSA::IdSet::IdSet | ( |  | ) |

inline

Default constructor creates IdSet object with ID equals to 0.

Definition at line 70 of file IdSet.h.

: m_next_available_id (0)
{
::memset (&m_id_set_map, 0, sizeof (m_id_set_map));
}
ASSA::IdSet::m_next_available_id
int m_next_available_id
Current id.
Definition IdSet.h:62
ASSA::IdSet::m_id_set_map
fd_set m_id_set_map
Map of all ids.
Definition IdSet.h:66

References m_id_set_map.

## Member Function Documentation

## currid()

int ASSA::IdSet::currid | ( |  | ) | const

inline

Get current id.

This function just returns current id without changing anything.

Definition at line 78 of file IdSet.h.

{
return m_next_available_id;
}

References m_next_available_id.

## newid()

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 19 of file IdSet.cpp.

{
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))
{
m_next_available_id = i;
return current;
}
}
// if I am here, I am out of ids
m_next_available_id = FD_SETSIZE;
}
return -1;
}
trace
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32

References m_id_set_map, m_next_available_id, and trace.

## recycle()

int IdSet::recycle | ( | int | id_ | ) |

Recycle id_.

Mark it as available and adjust current id if necessary.

Definition at line 53 of file IdSet.cpp.

{
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) {
m_next_available_id = id_;
}
return 0;
}
return -1;
}

References m_id_set_map, m_next_available_id, and trace.

## Member Data Documentation

## m_id_set_map

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

## m_next_available_id

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:

- IdSet.h
- IdSet.cpp