4.6. IdSet Class
IdSet class is my shot at the concept of
reusable IDs, similar to the reusable file descriptors provided by
UNIX. ID numbers are recyclable, up to 1024.
4.6.1. DEFINITION
class IdSet
{
public:
IdSet ();
int newid ();
int recycle (int id_);
int currid () const;
};
|
4.6.2. USAGE
For example,
#include <assa/IdSet.h>
void foo ()
{
// Initialize current id to 0
IdSet ehid;
// Return id (0), mark it as in use, and set current
// to the next available (1)
int a = ehid.get_id ();
// Return current id (1) with no side effects
int b = ehid.curr_id ();
// Recycle argument (0) and adjust current id
ehid.recycle (0);
}
|