Bucket Bucket::operator/(int size) { Bucket newBucket = Bucket(this->owner); for (int i = 0; i < this->elementsCount; i++) newBucket.addEgg(Egg(this->container[i].getName, this->container[i].getSize / size)); return newBucket; }
void cWSSAnvil::LoadEggFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { std::auto_ptr<cThrownEggEntity> Egg(new cThrownEggEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0))); if (!LoadProjectileBaseFromNBT(*Egg.get(), a_NBT, a_TagIdx)) { return; } // Store the new egg in the entities list: a_Entities.push_back(Egg.release()); }
// Deserializing the basket from the binary file in the already existing basket // If there is an error, the existing basket is not changed bool Basket::deserialize(const char* file) { Basket d; cout << "Iniating deserialization." << endl; std::ifstream myfile(file, std::ios::binary); if (!myfile) { cout << "Error" << endl; return false; } int amountOfE; myfile.read((char*)&amountOfE, sizeof(amountOfE)); if (!myfile) { cout << "Error." << endl; return false; } char buffer[1000]; int basketNameLen=0; myfile.read((char*)&basketNameLen, sizeof(basketNameLen)); myfile.read((char*)buffer, basketNameLen); name[basketNameLen] = '\0'; d.setName(buffer); for (int i = 0; i < amountOfE; i++) { double eggSize = 0; myfile.read((char*)&eggSize, sizeof(eggSize)); int nameSize = 0; myfile.read((char*)&nameSize, sizeof(nameSize)); myfile.read((char*)buffer, nameSize); buffer[nameSize] = '\0'; d.addÅgg(Egg(buffer, eggSize)); } //if all is okay, existing basket = basket we just read from the binary file *this = d; myfile.close(); return true; }