libassa  3.5.1
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. More...
 
int newid ()
 Return current id. More...
 
int recycle (int id_)
 Recycle id_. More...
 
int currid () const
 Get current id. More...
 

Private Attributes

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

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.

73 {
74  ::memset (&m_id_set_map, 0, sizeof (m_id_set_map));
75 }
int m_next_available_id
Current id.
Definition: IdSet.h:62
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.

80 {
81  return m_next_available_id;
82 }

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.

21 {
22  register int i;
23  register int current;
24 
25  trace("IdSet::newid");
26 
27  current = m_next_available_id++;
28 
29  if (m_next_available_id < FD_SETSIZE)
30  {
31  // mark current id as being in use
32  FD_SET(current, &m_id_set_map);
33 
34  // search starting from current position to the end
35  // assuming that m_next_available_id is maintained
36  // to be the lowest available at all times.
37 
38  for (i=current+1; i<FD_SETSIZE; i++)
39  {
40  if (!FD_ISSET(i, &m_id_set_map))
41  {
43  return current;
44  }
45  }
46  // if I am here, I am out of ids
47  m_next_available_id = FD_SETSIZE;
48  }
49  return -1;
50 }
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition: Logger.h:429

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.

55 {
56  trace("IdSet::recycle");
57 
58  if ( 0 <= id_ && id_ < FD_SETSIZE ) {
59  FD_CLR(id_, &m_id_set_map); // mark id as free
60 
61  // if id is smaller then current, adjust current
62  if (id_ < m_next_available_id) {
63  m_next_available_id = id_;
64  }
65  return 0;
66  }
67  return -1;
68 }

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: