clone
method); similarly, when a user gets a Particle from the queue, he or she supplies a Particle to received the copied value. The advantage of this is that the user need not worry about lifetimes of Particles - when to create them, when it is safe to return them to the Plasma or delete them. The ParticleQueue default constructor forms an empty, unlimited capacity queue. There is also a constructor of the form
ParticleQueue(unsigned int cap);This creates a queue that can hold at most
cap
particles. The destructor returns all Particles in the queue to their Plasma.
int empty() const;Return
TRUE
if the queue is empty, else FALSE
.
int full() const;Return
TRUE
if the length equals the capacity, else FALSE
.
unsigned int capacity() const;Return the queue's capacity. If unlimited, the largest possible unsigned int on the machine will be returned.
unsigned int length() const;Return the number of particles in the queue.
int putq(Particle& p);Put a copy of particle
p
into the queue, if there is room. Returns TRUE
on success, FALSE
if the queue is already at capacity.
int getq(Particle& p);Get a particle from the queue, and copy it into the user-supplied particle
p.
This returns TRUE
on success, FALSE
(and p
is unaltered) if the queue is empty.
void setCapacity(int sz);Modify the capacity to
sz,
if sz
is positive or zero. If negative, the capacity becomes infinite.
void initialize();Free up the queue contents. Particles are returned to their pools and the queue becomes empty.
void initialize(int n);Equivalent to
initialize()
followed by setCapacity(n)
.