|
libassa 3.5.0
|
#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. | |
| 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.
: m_next_available_id (0) { ::memset (&m_id_set_map, 0, sizeof (m_id_set_map)); }
| 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.
{
return 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))
{
m_next_available_id = i;
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) {
m_next_available_id = id_;
}
return 0;
}
return -1;
}
fd_set ASSA::IdSet::m_id_set_map [private] |
int ASSA::IdSet::m_next_available_id [private] |
1.7.3