void Node::load( DataBuffer& dataBuffer, GenericMap& theMap ) { // The first byte... uint8 bitField = dataBuffer.readNextByte(); m_majorRoad = BitUtility::getBit(bitField, MAJOR_ROAD_BIT_NBR); m_roadToll = BitUtility::getBit(bitField, ROAD_TOLL_BIT_NBR); m_entryRestrictions = ItemTypes::entryrestriction_t((bitField & 0x0C) >> 2); m_nbrLanes = ItemTypes::entryrestriction_t((bitField & 0x03)); // The next three bytes m_level = (int8) dataBuffer.readNextByte(); m_maximumWeight = dataBuffer.readNextByte(); m_maximumHeight = dataBuffer.readNextByte(); m_speedLimit = dataBuffer.readNextByte(); m_junctionType = ItemTypes::junction_t(dataBuffer.readNextByte()); m_nbrEntryConnections = dataBuffer.readNextShort(); m_entryConnections = NULL; if ( m_nbrEntryConnections > 0 ) { m_entryConnections = (Connection *)(theMap.getConnectionAllocator().getNextObject()); for ( uint32 i=0; i < m_nbrEntryConnections; ++i ) { if ( i != 0 ) { theMap.getConnectionAllocator().getNextObject(); } m_entryConnections[ i ].load( dataBuffer ); } } }
static bool checkGenericMapsEqual(const GenericMap & expected, const GenericMap & actual) { CPPUNIT_ASSERT_EQUAL(expected.size(), actual.size()); for(auto expectedElement : expected) { CPPUNIT_ASSERT(actual.count(expectedElement.first) != 0); if(!checkGenericsEqual(expectedElement.second, actual.at(expectedElement.first))) { return false; } } return true; }
ExtEngineManager::Trigger::Trigger(thread_db* tdbb, MemoryPool& pool, ExtEngineManager* aExtManager, ExternalEngine* aEngine, RoutineMetadata* aMetadata, ExternalTrigger* aTrigger, const Jrd::Trigger* aTrg) : extManager(aExtManager), engine(aEngine), metadata(aMetadata), trigger(aTrigger), trg(aTrg), fieldsPos(pool), database(tdbb->getDatabase()) { dsc shortDesc; shortDesc.makeShort(0); jrd_rel* relation = trg->relation; if (relation) { GenericMap<Left<MetaName, USHORT> > fieldsMap; for (FB_SIZE_T i = 0; i < relation->rel_fields->count(); ++i) { jrd_fld* field = (*relation->rel_fields)[i]; if (field) fieldsMap.put(field->fld_name, (USHORT) i); } format = Routine::createFormat(pool, metadata->triggerFields, false); LocalStatus status; for (unsigned i = 0; i < format->fmt_count / 2u; ++i) { const char* fieldName = metadata->triggerFields->getField(&status, i); status.check(); USHORT pos; if (!fieldsMap.get(fieldName, pos)) fb_assert(false); else fieldsPos.add(pos); } } }
static Generic fromGenericAttribute(const GenericAttribute * attr) { { auto boolAttr = dynamic_cast<const BoolAttribute *>(attr); if(boolAttr != nullptr) { return Generic(boolAttr->get()); } } { auto numberAttr = dynamic_cast<const _NumberAttribute<float> *>(attr); if(numberAttr != nullptr) { return Generic(numberAttr->get()); } } { auto stringAttr = dynamic_cast<const _StringAttribute<std::string> *>(attr); if(stringAttr != nullptr) { return Generic(stringAttr->get()); } } { auto listAttr = dynamic_cast<const GenericAttributeList *>(attr); if(listAttr != nullptr) { GenericArray genericArray; genericArray.reserve(listAttr->size()); for(const auto & element : *listAttr) { genericArray.emplace_back(fromGenericAttribute(element.get())); } return Generic(std::move(genericArray)); } } { auto mapAttr = dynamic_cast<const GenericAttributeMap *>(attr); if(mapAttr != nullptr) { GenericMap genericMap; genericMap.reserve(mapAttr->size()); for(const auto & element : *mapAttr) { genericMap.emplace(element.first, fromGenericAttribute(element.second.get())); } return Generic(std::move(genericMap)); } } return Generic(); }
void TestAttal::testMap() { GenericMap * map = new GenericMap(); map->newUnknownMap( 50, 60 ); QCOMPARE( (int)map->getHeight() , 50 ); QCOMPARE( (int)map->getWidth() , 60 ); GenericCell * cell = NULL; bool except = false; try { cell = map->at( 500, 650 ); } catch( const char * err ) { except = true; } QCOMPARE( except , true ); except = false; try { cell = map->at( -5, -6 ); } catch( const char * err ) { except = true; } QCOMPARE( except , true ); except = false; try { cell = map->at( 5, 6 ); } catch( const char * err ) { except = true; } QCOMPARE( except , false ); QCOMPARE( cell->getRow() , 5 ); map->newMapType( 50, 60,2 ); QCOMPARE( (int)map->getHeight() , 50 ); QCOMPARE( (int)map->getWidth() , 60 ); QCOMPARE( (int)map->at(1,1)->getType() ,2 ); delete map; }
void GenericConversionTest::testMapSerialization() { GenericMap map; map.emplace(Util::StringIdentifier("firstBool"), Util::Generic(true)); map.emplace(Util::StringIdentifier("secondBool"), Util::Generic(false)); map.emplace(Util::StringIdentifier("first string"), Util::Generic(std::string("[1, 2, \"xyz\"]"))); map.emplace(Util::StringIdentifier("second string"), Util::Generic(std::string("hello"))); map.emplace(Util::StringIdentifier("first number"), Util::Generic(12345.6f)); map.emplace(Util::StringIdentifier("second number"), Util::Generic(-4321.1f)); GenericMap innerMap; innerMap.emplace(Util::StringIdentifier("a"), Util::Generic(std::string("one"))); innerMap.emplace(Util::StringIdentifier("b"), Util::Generic(std::string("two"))); innerMap.emplace(Util::StringIdentifier("c"), Util::Generic(std::string("three"))); map.emplace(Util::StringIdentifier("innerMap"), Util::Generic(innerMap)); const Util::Generic genericMap(map); std::stringstream tempStream; Util::GenericConversion::toJSON(genericMap, tempStream); const std::string serialization = tempStream.str(); const Util::Generic importedGenericArray = Util::GenericConversion::fromJSON(tempStream); CPPUNIT_ASSERT(checkGenericsEqual(genericMap, importedGenericArray)); }