X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcontainer.cpp;h=a8cf0ad87ec45015ee5f0f73729ed7412b33a680;hb=9d59b5831000704a1ed39c22a6043ba658993159;hp=2ee9c7afa2291d9591302d14d051c1ffd82217d1;hpb=baf67656b97e3d61e9223e66ebe4f554e364cd4a;p=architektonas diff --git a/src/container.cpp b/src/container.cpp index 2ee9c7a..a8cf0ad 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -35,30 +35,29 @@ Container::Container(const Container & copy): Object(copy.position, copy.parent) Container::~Container() { -#if 0 - // No memory leaks! - while (objects.size() > 0) - { - delete objects[0]; - objects.erase(objects.begin()); - } -#else Clear(); -#endif } // Assignment operator -Container & Container::operator=(const Container & copy) +Container & Container::operator=(const Container & from) { // Take care of self-assignment - if (this == ©) + if (this == &from) return *this; Clear(); - for(int i=0; i<(int)copy.objects.size(); i++) - objects.push_back(copy.objects[i]); + // Small problem with this approach: if the copied object goes out of scope, + // all of the objects we copied in here will be deleted. D'oh! + for(uint i=0; iDraw(painter); + } } @@ -150,13 +152,17 @@ Like so: { if (objects[i]->Collided(point)) { +#if 0 Dimension * dimension = objects[i]->GetAttachedDimension(); - - objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o) +#endif + Object * objectToDelete = objects[i]; + objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o) [NOPE! SURE DOESN'T!] + delete objectToDelete; // If this object had an attached dimension, reattach it to another object, if any... // The only problem with that approach is if the object it gets attached to is deleted, // it will call the dimension to use a NULL pointer and BLAMMO +#if 0 if (dimension) { Vector p1 = dimension->GetPoint1(); @@ -173,7 +179,7 @@ if (dimension) dimension->SetPoint2(objectP2); } } - +#endif // This only allows deleting objects one at a time... break; // however, this way of doing things could be problematic if we don't @@ -246,7 +252,7 @@ about keeping track of old states... { needUpdate = false; - for(int i=0; i<(int)objects.size(); i++) + for(uint i=0; iNeedsUpdate()) needUpdate = true; @@ -259,6 +265,7 @@ about keeping track of old states... /*virtual*/ void Container::Add(Object * object) { objects.push_back(object); +printf("Container: Added object (=$%X). size = %li\n", object, objects.size()); } @@ -267,7 +274,23 @@ void Container::Clear(void) // No memory leaks! while (objects.size() > 0) { +printf("Container: Deleting object ($%X)...\n", objects[0]); delete objects[0]; objects.erase(objects.begin()); } } + + +/*virtual*/ void Container::Enumerate(FILE * file) +{ + // Only put "CONTAINER" markers if *not* the top level container + if (parent != NULL) + fprintf(file, "CONTAINER\n"); + + for(uint i=0; iEnumerate(file); + + if (parent != NULL) + fprintf(file, "ENDCONTAINER\n"); +} +