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; } }
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(); }
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; }
/** * The way to calculate the cache is the follow: * loop on the current element against an array list * that has the cache. It is the copy of the original cache. * When an current element is found in the cache, it is removed * from the cache copy. At the end the remained element * in the cache are the deleted ones. */ bool CacheSyncSource::fillItemModifications() { // all the current items keys list Enumeration* items = (Enumeration*)getAllItemList(); if (!items) { LOG.error("Error in fillItemModification"); return false; } // all the action are done on the copy so we can delete // the element found. The remained are the deleted by the user. Enumeration& e = cache->getProperties(); ArrayList cacheCopy; while(e.hasMoreElement()) { cacheCopy.add(*e.getNextElement()); } //if (e) { // delete e; //} StringBuffer* key; KeyValuePair* kvp; ArrayListEnumeration *newitems = new ArrayListEnumeration(), *moditems = new ArrayListEnumeration(); if (items) { while(items->hasMoreElement()) { key = (StringBuffer*)items->getNextElement(); int size = cacheCopy.size(); bool foundnew = true; for (int i = 0; i < size; i++) { kvp = (KeyValuePair*)(cacheCopy[i]); if (strcmp(kvp->getKey(), key->c_str()) == 0) { foundnew = false; // see if it is updated. StringBuffer sign = getItemSignature(*key); if (sign != kvp->getValue()) { // there is an update. if equal nothing to do... moditems->add(*key); } cacheCopy.removeElementAt(i); break; } } if (foundnew) { newitems->add(*key); } } } newKeys = newitems; updatedKeys = moditems; deletedKeys = new ArrayListEnumeration(cacheCopy); delete items; return true; }
void BindPhysics() { using namespace Sqrat; Class<CPhysicsSystem, NoConstructor> def; def.Func("Scale", &CPhysicsSystem::Scale); def.Func("CreateBody", &CPhysicsSystem::CreateBody); def.Func("CreateWorldOutline", &CPhysicsSystem::CreateWorldOutline); RootTable().Bind("PhysicsSystem", def); // Push the singleton to squirrel sq_pushroottable( Sqrat::DefaultVM::Get() ); sq_pushstring( Sqrat::DefaultVM::Get(), "PhysicsSystem", -1 ); sq_get( Sqrat::DefaultVM::Get(), -2 ); sq_pushstring( Sqrat::DefaultVM::Get(), "Physics", -1 ); sq_createinstance( Sqrat::DefaultVM::Get(), -2 ); sq_setinstanceup( Sqrat::DefaultVM::Get(), -1, (SQUserPointer)Input() ); sq_newslot( Sqrat::DefaultVM::Get(), -4, SQFalse ); sq_pop( Sqrat::DefaultVM::Get(), 2 ); // Box2D // b2Vec2 Class<b2Vec2> vec2; vec2.Func("Set", &b2Vec2::Set); RootTable().Bind("b2Vec2", vec2); // b2ChainShape Class<b2ChainShape> chain; chain.Func("CreateLoop", &b2ChainShape::CreateLoop ); RootTable().Bind("b2ChainShape", chain); // b2CircleShape /* Class<b2CircleShape> circle; circle.Var("radius", &b2CircleShape::m_radius); RootTable().Bind("b2CircleShape", circle); */ // b2BodyDef Class<b2BodyDef> bodydef; bodydef.Var("position", &b2BodyDef::position); bodydef.Var("linearDamping", &b2BodyDef::linearDamping); bodydef.Var("type", &b2BodyDef::type); RootTable().Bind("b2BodyDef", bodydef); // b2BodyType Enumeration bodyType; bodyType.Const("b2_dynamicBody", (int)b2_dynamicBody); ConstTable().Enum( "bodyType", bodyType); /* ConstTable().Enum("b2_staticBody", (int)b2_staticBody); ConstTable().Const("b2_kinematicBody", (int)b2_kinematicBody); ConstTable().Const("b2_dynamicBody", (int)b2_dynamicBody); */ }
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); } }
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; } }
QVariant ObjectNodeInstance::convertEnumToValue(const QVariant &value, const PropertyName &name) { Q_ASSERT(value.canConvert<Enumeration>()); int propertyIndex = object()->metaObject()->indexOfProperty(name); QMetaProperty metaProperty = object()->metaObject()->property(propertyIndex); QVariant adjustedValue; Enumeration enumeration = value.value<Enumeration>(); if (metaProperty.isValid() && metaProperty.isEnumType()) { adjustedValue = metaProperty.enumerator().keyToValue(enumeration.name()); } else { QQmlExpression expression(context(), object(), enumeration.toString()); adjustedValue = expression.evaluate(); if (expression.hasError()) qDebug() << "Enumeration can not be evaluated:" << object() << name << enumeration; } return adjustedValue; }
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")); }
void OW_EnumerationTestCases::testReleaseFile() { String file; { Enumeration<String> e; e.addElement("5"); unitAssert(e.numberOfElements() == 1); e.addElement("a"); unitAssert(e.numberOfElements() == 2); unitAssert(!e.usingTempFile()); file = e.releaseFile(); unitAssert(file.length() > 0); unitAssert(e.numberOfElements() == 0); } Enumeration<String> e2(file); unitAssert(e2.numberOfElements() == 2); unitAssert(e2.nextElement() == String("5")); unitAssert(e2.numberOfElements() == 1); unitAssert(e2.nextElement() == String("a")); unitAssert(e2.numberOfElements() == 0); }
void OW_EnumerationTestCases::testCreation() { Enumeration<String> e; e.addElement("5"); unitAssert(e.numberOfElements() == 1); }
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; } }