I have a hierarchy like this:
class Sphere;
class Cube;
class SpherePair;
class Entity {};
class Cube : public Entity {
public:
list<Sphere*> spheres_;
};
class Sphere : public Entity {
public:
Cube *cube;
SpherePair *spherepair;
};
class SpherePair : public Entity {
public:
Sphere *first;
Sphere *second;
};
I want to create a clone of the Cube object and all objects associated with it (Sphere, SpherePair, Cube).
The cube has spheres inside, each sphere is half the SpherePair object. SpherePair points to spheres that are in separate cubes or in the same cube.
This is necessary for the correct functionality of Undo.
I would also like to have a map of old and cloned objects:
std::map<Entity*, Entity*> old_new;
Posted: . Before these circular links, I had simple clone functionality:
class Entity {
public:
virtual Entity* clone() = 0;
}
It was used in such a scheme:
std::vector<Entity*> selected_objects_;
void move(const vec3f &offset) {
document->beginUndo();
for(int i = 0; i < selected_objects_.size(); ++i) {
Entity *cloned = selected_objects_[i]->clone();
cloned->move(offset);
selected_objects_[i]->setDeleted(true);
document->pushToUndo(selected_objects_[i]);
document->addEntity(cloned);
}
document->endUndo();
}
source
share