Added destructor for Body, removeBody method for PlanetarySystem.

This commit is contained in:
Chris Laurel 2002-02-08 19:19:29 +00:00
parent c20240a5e2
commit 0a120acf7e
2 changed files with 31 additions and 1 deletions

View file

@ -39,6 +39,14 @@ Body::Body(PlanetarySystem* _system) :
}
Body::~Body()
{
// clean up orbit, atmosphere, etc.
if (system != NULL)
system->removeBody(this);
}
PlanetarySystem* Body::getSystem() const
{
return system;
@ -341,6 +349,26 @@ PlanetarySystem::PlanetarySystem(const Star* _star) :
}
void PlanetarySystem::addBody(Body* body)
{
satellites.insert(satellites.end(), body);
}
void PlanetarySystem::removeBody(Body* body)
{
for (vector<Body*>::iterator iter = satellites.begin();
iter != satellites.end(); iter++)
{
if (*iter == body)
{
satellites.erase(iter);
break;
}
}
}
Body* PlanetarySystem::find(string _name, bool deepSearch) const
{
for (vector<Body*>::const_iterator iter = satellites.begin();

View file

@ -31,7 +31,8 @@ class PlanetarySystem
Body* getPrimaryBody() const { return primary; };
int getSystemSize() const { return satellites.size(); };
Body* getBody(int i) const { return satellites[i]; };
void addBody(Body* body) { satellites.insert(satellites.end(), body); };
void addBody(Body* body);
void removeBody(Body* body);
enum TraversalResult
{
@ -85,6 +86,7 @@ class Body
{
public:
Body(PlanetarySystem*);
~Body();
PlanetarySystem* getSystem() const;
std::string getName() const;