Toy* Toys::AddToy(Toy::EnumToyType type) { Toy *toy = Toy::Create(type, m_pClient, /*parent*/0, GetWindowFlags()); if( toy ) { connect(toy, SIGNAL(recvWidgetsChanged()), this, SLOT(onRecvWidgetsChanged())); connect(toy, SIGNAL(closing(Toy*)), this, SLOT(onToyClosing(Toy*))); connect(toy, SIGNAL(changed()), this, SLOT(onToyChanged())); connect(toy, SIGNAL(toggleMainWindow()), this, SLOT(onToyToggledMainWindow())); if(m_Opacity != 100) toy->setWindowOpacity(m_Opacity * 0.01); m_List.push_back(toy); if( !m_Loading ) { toy->showNormal(); BuildRecvWidgetsTable(); toy->raise(); } emit changed(); } return toy; }
int main() { int num; if (scanf("%d", &num)==1) { vector<int> weights(num); Toy toy (ReadInWeights(num)); printf("%lld\n", toy.Effort()); } return 0; }
int main() { Toy toto; Toy ET(Toy::ALIEN, "green", "./alien.txt"); toto.setName("TOTO !"); if (toto.getType() == Toy::BASIC_TOY) std::cout << "basic toy: " << toto.getName() << std::endl << toto.getAscii() << std::endl; if (ET.getType() == Toy::ALIEN) std::cout << "this alien is: " << ET.getName() << std::endl << ET.getAscii() << std::endl; return 1337; }
void Toys::DeleteToy(size_t index) { if(index < m_List.size()) { Toy *toy = m_List[index]; m_List.erase(m_List.begin() + index); toy->close(); toy->deleteLater(); BuildRecvWidgetsTable(); emit changed(); } }
void Toys::ActivateToy(size_t index) { if(index < m_List.size()) { Toy *toy = m_List[index]; Qt::WindowStates ws = toy->windowState(); if( ws.testFlag(Qt::WindowMaximized) ) toy->showMaximized(); else toy->showNormal(); toy->activateWindow(); } }
bool Toys::Load(EosLog &log, const QString &path, QStringList &lines, int &index) { Clear(); while(index>=0 && index<lines.size()) { m_Loading = true; QStringList items; Utils::GetItemsFromQuotedString(lines[index], items); if(items.size() > 0) { bool ok = false; int n = items[0].toInt(&ok); if(ok && n>=0 && n<Toy::TOY_COUNT) { Toy *toy = AddToy( static_cast<Toy::EnumToyType>(n) ); if( toy ) toy->Load(log, path, lines, index); else index++; } else index++; } else index++; m_Loading = false; } BuildRecvWidgetsTable(); return true; }
int main() { Toy *b = new Buzz("buzziiiii"); Toy *w = new Woody("wood"); Toy *t = new Toy(Toy::ALIEN, "ET", "alien.txt"); b->speak("To the code, and beyond !!!!!!!!"); w->speak("There’s a snake in my boot."); t->speak("the claaaaaaw"); return (0); }
bool ToyStory::tellMeAStory(std::string const & filename, Toy & character1, toy_speak speak1, Toy & character2, toy_speak speak2) { std::ifstream file(filename.data()); std::cout << character1.getAscii() << std::endl; std::cout << character2.getAscii() << std::endl; if (file.is_open()) { char buffer[1024]; std::string sentence; size_t index; int count = 0; while (!file.eof()) { memset(buffer, 0, 1024); file.getline(buffer, 1024); sentence = buffer; if ((index = sentence.find("picture:")) == 0) { std::string picture = sentence.substr(8); if (count % 2) { if (!character1.setAscii(picture)) { return false; } std::cout << character1.getAscii() << std::endl; } else { if (!character2.setAscii(picture)) { return false; } std::cout << character2.getAscii() << std::endl; } } else { if (count % 2) { if (!(character1.*speak1)(sentence)) { return false; } } else { if (!(character2.*speak2)(sentence)) { return false; } } } count++; } } return true; }
int main() { // PICTURE Tester *tester = new Tester("Picture"); Picture p; tester->test(p.data, std::string(""), "constructor without filename make an empty string"); p.getPictureFromFile(std::string("file.test")); tester->test(p.data, std::string("this is a test\ncool"), "when a correct filename is provided, it correctly reads the file"); p.getPictureFromFile(std::string("notExistingFile.test")); tester->test(p.data, std::string("ERROR"), "when there is an error, the string is set to ERROR"); delete tester; // PICTURE // TOY tester = new Tester("Toy"); Toy t; tester->test(t.getType(), Toy::BASIC_TOY, "default constructor set the type to BASIC_TOY"); tester->test(t.getName(), std::string("toy"), "default constructor set the name to toy"); tester->test(t.getAscii(), std::string(""), "default constructor set the ascii to ''"); Toy t2(Toy::ALIEN, std::string("E.T"), std::string("file.test")); tester->test(t2.getType(), Toy::ALIEN, "constructor set the type correctly"); tester->test(t2.getName(), std::string("E.T"), "constructor set the name correctly"); tester->test(t2.getAscii(), std::string("this is a test\ncool"), "constructor set the ascii correctly"); t = t2; tester->test(t.getType(), t2.getType() , "operator= set the type correctly"); tester->test(t.getName(), t2.getName(), "operator= set the name correctly"); tester->test(t.getAscii(), t2.getAscii(), "operator= set the ascii correctly"); delete tester; // TOY // BUZZ + WOODY tester = new Tester("Buzz and Woody"); Buzz buzz(std::string("foo")); Woody woody(std::string("bar"), std::string("file.test")); tester->test(buzz.getType(), Toy::BUZZ, "Buzz constructor (no file) set the type correctly"); tester->test(buzz.getName(), std::string("foo"), "Buzz constructor (no file) set the name correctly"); tester->test(buzz.getAscii(), std::string("Buzz !!!"), "Buzz constructor (no file) set the ascii correctly"); tester->test(woody.getType(), Toy::WOODY, "Woody constructor set the type correctly"); tester->test(woody.getName(), std::string("bar"), "Woody constructor set the name correctly"); tester->test(woody.getAscii(), std::string("this is a test\ncool"), "Woody constructor set the ascii correctly"); tester->warn("The following tests cannot be unit tested, please check by hand"); t.speak("I cannot unit test this... Does it work ? (toy)"); buzz.speak("I cannot unit test this... Does it work ? (buzz)"); woody.speak("I cannot unit test this... Does it work ? (woody)"); delete tester; // BUZZ + WOODY // OPERATOR<< tester = new Tester("operator<<"); t << "woohoo"; tester->test(t.getAscii(), std::string("woohoo"), "operator<< with TOY and STRING"); tester->warn("The following test cannot be unit tested, please check by hand"); std::cout << t; delete tester; // OPERATOR<< return 0; }
Toy::Toy(const Toy &c) { this->Type = c.getType(); this->Name = c.getName(); }
void Toys::UpdateWindowFlags() { for(TOY_LIST::const_iterator i=m_List.begin(); i!=m_List.end(); i++) { Toy *toy = *i; QPoint pos( toy->frameGeometry().topLeft() ); Qt::WindowStates ws = toy->windowState(); bool wasVisible = toy->isVisible(); toy->hide(); toy->setWindowFlags( GetWindowFlags() ); if( ws.testFlag(Qt::WindowMinimized) ) { toy->showMinimized(); } else if( ws.testFlag(Qt::WindowMaximized) ) { toy->showMaximized(); if( !wasVisible ) toy->close(); } else { toy->move( pos ); toy->showNormal(); Toy::ClipToScreen( *toy ); if( !wasVisible ) toy->close(); } } }
Toy::Toy(const Toy &ty) { _name = ty.getName(); _pic.data = ty.getAscii(); _type = ty.getType(); }
Toy::Toy(Toy const &cls) { _type = cls.getType(); _name = cls.getName(); _picture = cls.getPicture(); }