]> Shamusworld >> Repos - architektonas/blobdiff - src/container.cpp
Added Architektonas drawing file loading/saving infrastructure.
[architektonas] / src / container.cpp
index c867eaf80224c59609925d49eed1ec35683d3103..2ee9c7afa2291d9591302d14d051c1ffd82217d1 100644 (file)
@@ -24,22 +24,53 @@ Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p),
 {
 }
 
+
+// Copy constructor
+Container::Container(const Container & copy): Object(copy.position, copy.parent)
+{
+       // Use overloaded assignment operator
+       *this = copy;
+}
+
+
 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)
+{
+       // Take care of self-assignment
+       if (this == &copy)
+               return *this;
+
+       Clear();
+
+       for(int i=0; i<(int)copy.objects.size(); i++)
+               objects.push_back(copy.objects[i]);
+
+       return *this;
+}
+
+
 /*virtual*/ void Container::Draw(Painter * painter)
 {
        for(int i=0; i<(int)objects.size(); i++)
                objects[i]->Draw(painter);
 }
 
+
 /*virtual*/ Vector Container::Center(void)
 {
        return position;
@@ -58,6 +89,7 @@ I click here and drag there?"
 Also: should put the snap logic into the Object base class (as a static method)...
 */
 
+
 /*virtual*/ bool Container::Collided(Vector point)
 {
        objectWasDragged = false;
@@ -165,8 +197,10 @@ if (dimension)
        return collision;
 }
 
+
 // The TLC is passing all mouse movement here, so we're doing the same here.
 // Need to adjust all other objects to handle things correctly.
+
 // One optimization that will need to be done eventually is to subdivide the screen
 // into parts and keep subdividing until an acceptable number of objects lie within
 // the slice. This way, the GUI will still be responsive and *not* have to test
@@ -186,6 +220,7 @@ if (dimension)
 //     needUpdate = false;
 }
 
+
 /*virtual*/ void Container::PointerReleased(void)
 {
        dragging = false;
@@ -206,6 +241,7 @@ about keeping track of old states...
                objects[i]->PointerReleased();
 }
 
+
 /*virtual*/ bool Container::NeedsUpdate(void)
 {
        needUpdate = false;
@@ -219,7 +255,19 @@ about keeping track of old states...
        return needUpdate;
 }
 
+
 /*virtual*/ void Container::Add(Object * object)
 {
        objects.push_back(object);
 }
+
+
+void Container::Clear(void)
+{
+       // No memory leaks!
+       while (objects.size() > 0)
+       {
+               delete objects[0];
+               objects.erase(objects.begin());
+       }
+}