Top Up Prev Next Bottom Contents Index Search

6.8 Class ParticleQueue

Class ParticleQueue implements a queue of Particles. It uses a member of class ParticleStack to store the particles; it is not implemented by deriving from ParticleStack. It can implement a queue with finite or unlimited capacity. Rather than placing user-supplied Particles on the queue and removing them directly, it takes over the responsibility for memory management by allocating its own Particles from the Plasma and returning them as needed. When a user puts a Particle into the queue, the value of the Particle is copied (with the Particle 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).

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.