Top Up Prev Next Bottom Contents Index Search

6.5 Class ParticleStack

ParticleStack is an efficient base class for the implementation of structures that organize Particles. As Particles have a link field, ParticleStack is simply implemented as a linked list of Particles. Strictly speaking, a dequeue is implemented; particles can be inserted from either end. ParticleStack has some odd attributes; it is designed for very efficient implementation of Geodesic and Plasma to move around large numbers of Particle objects very efficiently.

ParticleStack(Particle* h); 
The constructor takes a Particle pointer. If it is a null pointer an empty ParticleStack is created. Otherwise the stack has one particle. Adding a Particle to a ParticleStack modifies that Particle's link field; therefore a Particle can belong to only one ParticleStack at a time.

~ParticleStack(); 
The destructor deletes all Particles EXCEPT for the last one; we do not delete the last one because it is the "reference" particle (for Plasma) and is normally not dynamically created (this code may be moved in a future release to the Plasma destructor, as this behavior is needed for Plasma and not for other types of ParticleStack).

void put(Particle* p); 
Push p onto the top (or head) of the ParticleStack.

Particle* get(); 
Pop the particle off the top (or head) of the ParticleStack.

void putTail(Particle* p); 
Add p at the bottom (or tail) of the ParticleStack.

int empty() const; 
Return TRUE (1) if the ParticleStack is empty, otherwise 0.

int moreThanOne() const; 
Return TRUE (1) if the ParticleStack has two or more particles, otherwise 0. This is provided to speed up the derived class Plasma a bit.

void freeup(); 
Returns all Particles on the stack to their Plasma (the allocation pool for that particle type).

Particle* head() const;
Return pointer to head.

Particle* tail() const;
Return pointer to tail.



Top Up Prev Next Bottom Contents Index Search

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