void Container::loadDataAsBinary(const string& filename) { freeShapes(); bool dataOK; bool animationFlag; char ch; int length; shapeID id; Shape* currShape = nullptr; int numItems; std::ifstream loadFile; loadFile.exceptions(std::ios::failbit); loadFile.open(filename, ios::binary); loadFile.read((char*)&numItems, sizeof(numItems)); for (int i = 0; i < numItems; ++i) { Point p(loadFile); loadFile.read((char*)&ch, sizeof(ch)); loadFile.read((char*)&length, sizeof(length)); loadFile.read((char*)&id, sizeof(id)); loadFile.read((char*)&animationFlag, sizeof(animationFlag)); dataOK = validateFileRead(length, id, ch, p); if (!dataOK) { string err = "Corrupted file"; throw string(err); } switch (id) { case SQUARE: currShape = new Square(p, ch, length, id); break; case DIAMOND: currShape = new Diamond(p, ch, length, id); break; } if (animationFlag) { currShape->addAnimation(); currShape->animation()->load(loadFile); dataOK = validateAnimationFileRead(*currShape->animation()); if (!dataOK) { currShape->removeAnimation(); string err = "Corrupted file"; throw string(err); } } else currShape->resetAnimation(); addShapeToList(currShape); } loadFile.close(); }
void Container::loadDataAsText(const string& filename) { freeShapes(); bool dataOK; std::ifstream loadFile; loadFile.exceptions(std::ios::failbit); loadFile.open(filename); int numItems; loadFile >> numItems; int id_; shapeID id; char ch; int length; Point p; double speedX, speedY; Shape* currShape = nullptr; for (int i = 0; i < numItems; ++i) { loadFile >> id_; id = id_ == 0 ? SQUARE : DIAMOND; loadFile >> p >> length >> ch >> speedX >> speedY; dataOK = validateFileRead(length, id, ch, p); dataOK = validateSpeed(speedX, speedY); if (!dataOK) { string err = "Corrupted file"; throw string(err); } switch (id) { case SQUARE: currShape = new Square(p, ch, length, id); break; case DIAMOND: currShape = new Diamond(p, ch, length, id); break; } if (speedX != 0 || speedY != 0 && currShape != nullptr) { currShape->addAnimation(); currShape->animation()->setSpeedX(speedX); currShape->animation()->setSpeedY(speedY); } else currShape->resetAnimation(); addShapeToList(currShape); } }
Container::~Container() { freeShapes(); lst.clear(); }
phdShapeGroup::~phdShapeGroup() { // disableEvents(); freeShapes(); }
phdShapeGroup::~phdShapeGroup() { freeShapes(); }