void Block::destroyPins(void) { Enumeration* en = NULL; // lock input pins table _idp.lock(); // delete input pins en = _idp.values(); while (en->hasMoreElements()) delete (DataPin *) en->nextElement(); // unlock input pins table _idp.unlock(); // lock output pins table _odp.lock(); // delete output pins en = _odp.values(); while (en->hasMoreElements()) delete (DataPin *) en->nextElement(); // unlock output pins table _odp.unlock(); }
void OW_EnumerationTestCases::testAllBig() { try { Enumeration<String> e; for (unsigned int i = 1; i <= bigLoopVal; i++) { e.addElement(String(i)); } for (unsigned int i = 0; i < bigLoopVal; ++i) { unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == bigLoopVal - i); String foo = e.nextElement(); unitAssert(foo == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch(Exception& e) { cerr << e << endl; throw; } }
void OW_EnumerationTestCases::testInsertIterator() { try { std::vector<String> as; for (unsigned int i = 1; i <= loopVal; i++) { as.push_back(String(i)); } Enumeration<String> e; std::copy(as.begin(), as.end(), Enumeration_insert_iterator<String>(e)); for (unsigned int i = 0; i < loopVal; ++i) { unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == loopVal - i); unitAssert(e.nextElement() == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e << endl; throw; } }
void OW_EnumerationTestCases::testQueueBig() { try { Enumeration<String> e; // now test it's queue like capabilities e.addElement("9"); for (unsigned int i = 10; i <= bigLoopVal; ++i) { e.addElement(String(i)); unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == 2); String foo = e.nextElement(); unitAssert(foo == String(i - 1)); } unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == 1); unitAssert(e.nextElement() == String(bigLoopVal)); unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e; throw; } }
int32 Block::sendMessageToPeersOf(DataPin* dp, uint32 code) { cmessage cm; dp->lockTable(Pin::PEERS_TABLE); memset(&cm, 0, sizeof(cmessage)); Enumeration* peers = dp->getPeers(); while (peers->hasMoreElements()) { DataPin* dpi = (DataPin*) peers->nextElement(); Block* b = dpi->getBlock(); ControlPin* cp = b->getControlPin(); cm.code = code; cm.from = this; cp->tryPutMessage(&cm); } dp->unlockTable(Pin::PEERS_TABLE); // ok return SUCCESS; }
void OW_EnumerationTestCases::testInputIterator() { try { Enumeration<String> e; for (unsigned int i = 1; i <= loopVal; i++) { e.addElement(String(i)); } std::vector<String> vec; std::copy(Enumeration_input_iterator<String>(e), // start of source Enumeration_input_iterator<String>(), // end of source std::back_inserter(vec)); // destination for (unsigned int i = 0; i < loopVal; ++i) { unitAssert(vec[i] == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e << endl; throw; } }
string Customer::statement() { double totalAmount = 0; int frequentRenterPoints = 0; Enumeration rentals = _rentals.elements(); string result = "Rental Record for "+ getName() + "\n"; while(rentals.hasMoreElements()) { double thisAmount = 0; Rental each = (Rental)rentals.nextElement(); thisAmount = amountFor(each); //add frequent renter points frequentRenterPoints ++; //add bonus for a two day new release rental if((each.getMovice().getPriceCode() == Movice.NEW_RELEASE)&& each.getDaysRented() > 1) frequentRenterPoints ++; //show figures for this rental result += "\t" + each.getMovice().getTitle() + "\t" + string.valueOf(thisAmount) +"\n"; totalAmount += thisAmount; } //add footer lines result += "Amount owed is "+ string.valueof(totalAmount)+"\n"; result += "You earned "+ string.valueof(frequentRenterPoints)+" frequent renter points"; return result; }
void Interp::deleteCommands(void) { Enumeration* e = keys(); while (e->hasMoreElements()) { char* com_name = (char*) e->nextElement(); Command* c = (Command*) get(com_name); if (c) delete c; } }
void VideoFormats::fillVectorWithFormats(Vector* v) { Enumeration* en = keys(); while (en->hasMoreElements()) { char* key = (char*) en->nextElement(); item* itm = (item*) get(key); if (itm->type == VIDEOFORMAT) v->addElement(key, (uint32) strlen(key) + 1); } }
Block::~Block(void) { // DEBUG UOSUTIL_DOUT(("~Block(): entered\n")); // destroy callbacks destroyHandlers(); // destroy pins destroyPins(); // delete wires for control pins Enumeration* ew = _cp.getWires(); while (ew->hasMoreElements()) { Wire* w = (Wire*) ew->nextElement(); if (w) delete w; } // DEBUG UOSUTIL_DOUT(("~Block(): exited\n")); }