bool OsmAnd::MapStyleEvaluationResult::getIntegerValue(const int valueDefId, unsigned int& value) const { const auto itValue = _d->_values.constFind(valueDefId); if(itValue == _d->_values.cend()) return false; value = itValue->toUInt(); return true; }
void CheatsManager::OnWatchItemChanged(QTableWidgetItem* item) { if (m_updating) return; int index = item->data(INDEX_ROLE).toInt(); int column = item->data(COLUMN_ROLE).toInt(); switch (column) { case 0: m_watch[index].name = item->text(); break; case 2: m_watch[index].locked = item->checkState() == Qt::Checked; if (m_watch[index].locked) m_watch[index].locked_value = GetResultValue(m_results[index]); UpdatePatch(m_watch[index]); break; case 3: { const auto text = item->text(); u32 value = 0; switch (m_watch[index].type) { case DataType::Byte: value = text.toUShort(nullptr, 16) & 0xFF; break; case DataType::Short: value = text.toUShort(nullptr, 16); break; case DataType::Int: value = text.toUInt(nullptr, 16); break; case DataType::Float: { float f = text.toFloat(); std::memcpy(&value, &f, sizeof(float)); break; } default: break; } m_watch[index].locked_value = value; UpdatePatch(m_watch[index]); break; } } Update(); }
unsigned int getValueUInt(tinyxml2::XMLElement* _parentElement, const std::string& _name) { assert(_parentElement != nullptr); assert(!_name.empty()); std::string str = _parentElement->FirstChildElement(_name.c_str())->GetText(); return toUInt(str); }
QVariant QDBusDemarshaller::toVariantInternal() { switch (q_dbus_message_iter_get_arg_type(&iterator)) { case DBUS_TYPE_BYTE: return qVariantFromValue(toByte()); case DBUS_TYPE_INT16: return qVariantFromValue(toShort()); case DBUS_TYPE_UINT16: return qVariantFromValue(toUShort()); case DBUS_TYPE_INT32: return toInt(); case DBUS_TYPE_UINT32: return toUInt(); case DBUS_TYPE_DOUBLE: return toDouble(); case DBUS_TYPE_BOOLEAN: return toBool(); case DBUS_TYPE_INT64: return toLongLong(); case DBUS_TYPE_UINT64: return toULongLong(); case DBUS_TYPE_STRING: return toString(); case DBUS_TYPE_OBJECT_PATH: return qVariantFromValue(toObjectPath()); case DBUS_TYPE_SIGNATURE: return qVariantFromValue(toSignature()); case DBUS_TYPE_VARIANT: return qVariantFromValue(toVariant()); case DBUS_TYPE_ARRAY: switch (q_dbus_message_iter_get_element_type(&iterator)) { case DBUS_TYPE_BYTE: // QByteArray return toByteArray(); case DBUS_TYPE_STRING: return toStringList(); case DBUS_TYPE_DICT_ENTRY: return qVariantFromValue(duplicate()); default: return qVariantFromValue(duplicate()); } case DBUS_TYPE_STRUCT: return qVariantFromValue(duplicate()); default: qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", q_dbus_message_iter_get_arg_type(&iterator), q_dbus_message_iter_get_arg_type(&iterator)); return QVariant(); break; }; }
/* Convert N0 into ascii in BUF, which is assumed to be big enough (at least 67 bytes long). Observe BASE, SYNED and HEXCAPS. */ static void convert_int ( /*OUT*/char* buf, Long n0, Int base, Bool syned, Bool hexcaps ) { ULong u0; char c; Bool minus = False; Int i, j, bufi = 0; buf[bufi] = 0; if (syned) { if (n0 < 0) { minus = True; u0 = (ULong)(-n0); } else { u0 = (ULong)(n0); } } else { u0 = (ULong)n0; } while (1) { buf[bufi++] = '0' + toUInt(u0 % base); u0 /= base; if (u0 == 0) break; } if (minus) buf[bufi++] = '-'; buf[bufi] = 0; for (i = 0; i < bufi; i++) if (buf[i] > '9') buf[i] = buf[i] + (hexcaps ? 'A' : 'a') - '9' - 1; i = 0; j = bufi-1; while (i <= j) { c = buf[i]; buf[i] = buf[j]; buf[j] = c; i++; j--; } }
bool UBVersion::operator > (const UBVersion &otherVersion) const { return toUInt() > otherVersion.toUInt(); }
static inline UInt sel32x2_0 ( ULong w64 ) { return 0xFFFFFFFF & toUInt(w64); }
bool OsmAndTools::Styler::Configuration::parseFromCommandLineArguments( const QStringList& commandLineArgs, Configuration& outConfiguration, QString& outError) { outConfiguration = Configuration(); const std::shared_ptr<OsmAnd::ObfsCollection> obfsCollection(new OsmAnd::ObfsCollection()); outConfiguration.obfsCollection = obfsCollection; const std::shared_ptr<OsmAnd::MapStylesCollection> stylesCollection(new OsmAnd::MapStylesCollection()); outConfiguration.stylesCollection = stylesCollection; for (const auto& arg : commandLineArgs) { if (arg.startsWith(QLatin1String("-obfsPath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfsPath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } obfsCollection->addDirectory(value, false); } else if (arg.startsWith(QLatin1String("-obfsRecursivePath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfsRecursivePath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } obfsCollection->addDirectory(value, true); } else if (arg.startsWith(QLatin1String("-obfFile="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-obfFile="))); if (!QFile(value).exists()) { outError = QString("'%1' file does not exist").arg(value); return false; } obfsCollection->addFile(value); } else if (arg.startsWith(QLatin1String("-stylesPath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-stylesPath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } QFileInfoList styleFilesList; OsmAnd::Utilities::findFiles(QDir(value), QStringList() << QLatin1String("*.render.xml"), styleFilesList, false); for (const auto& styleFile : styleFilesList) stylesCollection->addStyleFromFile(styleFile.absoluteFilePath()); } else if (arg.startsWith(QLatin1String("-stylesRecursivePath="))) { const auto value = Utilities::resolvePath(arg.mid(strlen("-stylesRecursivePath="))); if (!QDir(value).exists()) { outError = QString("'%1' path does not exist").arg(value); return false; } QFileInfoList styleFilesList; OsmAnd::Utilities::findFiles(QDir(value), QStringList() << QLatin1String("*.render.xml"), styleFilesList, true); for (const auto& styleFile : styleFilesList) stylesCollection->addStyleFromFile(styleFile.absoluteFilePath()); } else if (arg.startsWith(QLatin1String("-styleName="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-styleName="))); outConfiguration.styleName = value; } else if (arg.startsWith(QLatin1String("-styleSetting:"))) { const auto settingValue = arg.mid(strlen("-styleSetting:")); const auto settingKeyValue = settingValue.split(QLatin1Char('=')); if (settingKeyValue.size() != 2) { outError = QString("'%1' can not be parsed as style settings key and value").arg(settingValue); return false; } outConfiguration.styleSettings[settingKeyValue[0]] = Utilities::purifyArgumentValue(settingKeyValue[1]); } else if (arg.startsWith(QLatin1String("-mapObject="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-mapObject="))); uint64_t mapObjectId = 0u; bool ok = false; if (value[0] == QChar('-')) mapObjectId = static_cast<uint64_t>(value.toLongLong(&ok)); else mapObjectId = value.toULongLong(&ok); if (!ok) { outError = QString("'%1' can not be parsed as map object identifier").arg(value); return false; } outConfiguration.mapObjectsIds.insert(mapObjectId); } else if (arg.startsWith(QLatin1String("-zoom="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-zoom="))); bool ok = false; outConfiguration.zoom = static_cast<OsmAnd::ZoomLevel>(value.toUInt(&ok)); if (!ok || outConfiguration.zoom < OsmAnd::MinZoomLevel || outConfiguration.zoom > OsmAnd::MaxZoomLevel) { outError = QString("'%1' can not be parsed as zoom").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-displayDensityFactor="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-displayDensityFactor="))); bool ok = false; outConfiguration.displayDensityFactor = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as display density factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-mapScale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-mapScale="))); bool ok = false; outConfiguration.mapScale = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as map scale factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-symbolsScale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-symbolsScale="))); bool ok = false; outConfiguration.symbolsScale = value.toFloat(&ok); if (!ok) { outError = QString("'%1' can not be parsed as symbols scale factor").arg(value); return false; } } else if (arg.startsWith(QLatin1String("-locale="))) { const auto value = Utilities::purifyArgumentValue(arg.mid(strlen("-locale="))); outConfiguration.locale = value; } else if (arg == QLatin1String("-metrics")) { outConfiguration.metrics = true; } else if (arg == QLatin1String("-verbose")) { outConfiguration.verbose = true; } else { outError = QString("Unrecognized argument: '%1'").arg(arg); return false; } } // Validate if (obfsCollection->getSourceOriginIds().isEmpty()) { outError = QLatin1String("No OBF files found or specified"); return false; } if (outConfiguration.styleName.isEmpty()) { outError = QLatin1String("'styleName' can not be empty"); return false; } return true; }
bool OsmAndTools::Styler::evaluate(EvaluatedMapObjects& outEvaluatedMapObjects, std::ostream& output) #endif { bool success = true; for (;;) { // Find style if (configuration.verbose) output << xT("Resolving style '") << QStringToStlString(configuration.styleName) << xT("'...") << std::endl; const auto mapStyle = configuration.stylesCollection->getResolvedStyleByName(configuration.styleName); if (!mapStyle) { if (configuration.verbose) { output << "Failed to resolve style '" << QStringToStlString(configuration.styleName) << "' from collection:" << std::endl; for (const auto& style : configuration.stylesCollection->getCollection()) { if (style->isMetadataLoaded()) { if (style->isStandalone()) output << "\t" << QStringToStlString(style->name) << std::endl; else { output << "\t" << QStringToStlString(style->name) << "::" << QStringToStlString(style->parentName) << std::endl; } } else output << "\t[missing metadata]" << std::endl; } } else { output << "Failed to resolve style '" << QStringToStlString(configuration.styleName) << "' from collection:" << std::endl; } success = false; break; } // Load all map objects const auto mapObjectsFilterById = [this] (const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section, const uint64_t mapObjectId, const OsmAnd::AreaI& bbox, const OsmAnd::ZoomLevel firstZoomLevel, const OsmAnd::ZoomLevel lastZoomLevel, const OsmAnd::ZoomLevel requestedZoom) -> bool { return configuration.mapObjectsIds.contains(mapObjectId); }; if (configuration.verbose) { if (configuration.mapObjectsIds.isEmpty()) output << xT("Going to load all available map objects...") << std::endl; else output << xT("Going to load ") << configuration.mapObjectsIds.size() << xT(" map objects...") << std::endl; } const auto obfDataInterface = configuration.obfsCollection->obtainDataInterface(); QList< std::shared_ptr<const OsmAnd::BinaryMapObject> > mapObjects_; success = obfDataInterface->loadBinaryMapObjects( &mapObjects_, nullptr, configuration.zoom, nullptr, configuration.mapObjectsIds.isEmpty() ? OsmAnd::ObfMapSectionReader::FilterByIdFunction() : mapObjectsFilterById, nullptr, nullptr, nullptr, nullptr); const auto mapObjects = OsmAnd::copyAs< QList< std::shared_ptr<const OsmAnd::MapObject> > >(mapObjects_); if (!success) { if (configuration.verbose) output << xT("Failed to load map objects!") << std::endl; break; } if (configuration.verbose) output << xT("Loaded ") << mapObjects.size() << xT(" map objects") << std::endl; // Prepare all resources for map style evaluation if (configuration.verbose) { output << xT("Initializing map presentation environment with display density ") << configuration.displayDensityFactor << xT(", map scale ") << configuration.mapScale << xT(", symbols scale ") << configuration.symbolsScale << xT(" and locale '") << QStringToStlString(configuration.locale) << xT("'...") << std::endl; } const std::shared_ptr<OsmAnd::MapPresentationEnvironment> mapPresentationEnvironment(new OsmAnd::MapPresentationEnvironment( mapStyle, configuration.displayDensityFactor, configuration.mapScale, configuration.symbolsScale, configuration.locale)); if (configuration.verbose) output << xT("Applying extra style settings to map presentation environment...") << std::endl; mapPresentationEnvironment->setSettings(configuration.styleSettings); // Create primitiviser const std::shared_ptr<OsmAnd::MapPrimitiviser> primitiviser(new OsmAnd::MapPrimitiviser(mapPresentationEnvironment)); if (configuration.verbose) output << xT("Going to primitivise map objects...") << std::endl; OsmAnd::MapPrimitiviser_Metrics::Metric_primitiviseAllMapObjects metrics; const auto primitivisedData = primitiviser->primitiviseAllMapObjects( configuration.zoom, mapObjects, nullptr, nullptr, configuration.metrics ? &metrics : nullptr); if (configuration.verbose) { output << xT("Primitivised ") << primitivisedData->primitivesGroups.size() << xT(" groups from ") << mapObjects.size() << xT(" map objects") << std::endl; } // Obtain evaluated values for each group and print it for (const auto& primitivisedGroup : OsmAnd::constOf(primitivisedData->primitivesGroups)) { const auto& mapObject = primitivisedGroup->sourceObject; const auto binaryMapObject = std::dynamic_pointer_cast<const OsmAnd::BinaryMapObject>(mapObject); const auto& encDecRules = mapObject->encodingDecodingRules; // Skip objects that were not requested if (!configuration.mapObjectsIds.isEmpty() && binaryMapObject && !configuration.mapObjectsIds.contains(binaryMapObject->id)) { continue; } outEvaluatedMapObjects[mapObject] = primitivisedGroup; output << QStringToStlString(QString(80, QLatin1Char('-'))) << std::endl; output << QStringToStlString(mapObject->toString()) << std::endl; for (const auto& typeRuleId : OsmAnd::constOf(mapObject->typesRuleIds)) { const auto itTypeRule = encDecRules->decodingRules.constFind(typeRuleId); if (itTypeRule != encDecRules->decodingRules.cend()) { const auto& typeRule = *itTypeRule; output << xT("\tType: ") << QStringToStlString(typeRule.tag) << xT(" = ") << QStringToStlString(typeRule.value) << std::endl; } else { output << xT("\tType: #") << typeRuleId << xT(" (UNRESOLVED)") << std::endl; } } for (const auto& typeRuleId : OsmAnd::constOf(mapObject->additionalTypesRuleIds)) { const auto itTypeRule = encDecRules->decodingRules.constFind(typeRuleId); if (itTypeRule != encDecRules->decodingRules.cend()) { const auto& typeRule = *itTypeRule; output << xT("\tExtra type: ") << QStringToStlString(typeRule.tag) << xT(" = ") << QStringToStlString(typeRule.value) << std::endl; } else { output << xT("\tExtra type: #") << typeRuleId << xT(" (UNRESOLVED)") << std::endl; } } for (const auto& captionTagId : OsmAnd::constOf(mapObject->captionsOrder)) { const auto& captionValue = mapObject->captions[captionTagId]; if (encDecRules->name_encodingRuleId == captionTagId) output << xT("\tCaption: ") << QStringToStlString(captionValue) << std::endl; else if (encDecRules->ref_encodingRuleId == captionTagId) output << xT("\tRef: ") << QStringToStlString(captionValue) << std::endl; else { const auto itCaptionTagAsLocalizedName = encDecRules->localizedName_decodingRules.constFind(captionTagId); const auto itCaptionTagRule = encDecRules->decodingRules.constFind(captionTagId); QString captionTag(QLatin1String("UNRESOLVED")); if (itCaptionTagAsLocalizedName != encDecRules->localizedName_decodingRules.cend()) captionTag = *itCaptionTagAsLocalizedName; if (itCaptionTagRule != encDecRules->decodingRules.cend()) captionTag = itCaptionTagRule->tag; output << xT("\tCaption [") << QStringToStlString(captionTag) << xT("]: ") << QStringToStlString(captionValue) << std::endl; } } if (!primitivisedGroup->points.isEmpty()) { output << primitivisedGroup->points.size() << xT(" point(s):") << std::endl; unsigned int pointPrimitiveIndex = 0u; for (const auto& pointPrimitive : OsmAnd::constOf(primitivisedGroup->points)) { output << xT("\tPoint #") << pointPrimitiveIndex << std::endl; QString ruleTag; QString ruleValue; const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex( pointPrimitive->typeRuleIdIndex, ruleTag, ruleValue); if (typeRuleResolved) { output << xT("\t\tTag/value: ") << QStringToStlString(ruleTag) << xT(" = ") << QStringToStlString(ruleValue) << std::endl; } else { output << xT("\t\tTag/value: ") << pointPrimitive->typeRuleIdIndex << xT(" (failed to resolve)") << std::endl; } output << xT("\t\tZ order: ") << pointPrimitive->zOrder << std::endl; output << xT("\t\tArea*2: ") << pointPrimitive->doubledArea << std::endl; const auto& values = pointPrimitive->evaluationResult.getValues(); for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values)) { const auto valueDefinitionId = evaluatedValueEntry.key(); const auto value = evaluatedValueEntry.value(); const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId); output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = "); if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color) output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString()); else output << QStringToStlString(value.toString()); output << std::endl; } pointPrimitiveIndex++; } } if (!primitivisedGroup->polylines.isEmpty()) { output << primitivisedGroup->polylines.size() << xT(" polyline(s):") << std::endl; unsigned int polylinePrimitiveIndex = 0u; for (const auto& polylinePrimitive : OsmAnd::constOf(primitivisedGroup->polylines)) { output << xT("\tPolyline #") << polylinePrimitiveIndex << std::endl; QString ruleTag; QString ruleValue; const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex( polylinePrimitive->typeRuleIdIndex, ruleTag, ruleValue); if (typeRuleResolved) { output << xT("\t\tTag/value: ") << QStringToStlString(ruleTag) << xT(" = ") << QStringToStlString(ruleValue) << std::endl; } else { output << xT("\t\tTag/value: ") << polylinePrimitive->typeRuleIdIndex << xT(" (failed to resolve)") << std::endl; } output << xT("\t\tZ order: ") << polylinePrimitive->zOrder << std::endl; output << xT("\t\tArea*2: ") << polylinePrimitive->doubledArea << std::endl; const auto& values = polylinePrimitive->evaluationResult.getValues(); for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values)) { const auto valueDefinitionId = evaluatedValueEntry.key(); const auto value = evaluatedValueEntry.value(); const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId); output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = "); if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color) output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString()); else output << QStringToStlString(value.toString()); output << std::endl; } polylinePrimitiveIndex++; } } if (!primitivisedGroup->polygons.isEmpty()) { output << primitivisedGroup->polygons.size() << xT(" polygon(s):") << std::endl; unsigned int polygonPrimitiveIndex = 0u; for (const auto& polygonPrimitive : OsmAnd::constOf(primitivisedGroup->polygons)) { output << xT("\tPolygon #") << polygonPrimitiveIndex << std::endl; QString ruleTag; QString ruleValue; const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex( polygonPrimitive->typeRuleIdIndex, ruleTag, ruleValue); if (typeRuleResolved) { output << xT("\t\tTag/value: ") << QStringToStlString(ruleTag) << xT(" = ") << QStringToStlString(ruleValue) << std::endl; } else { output << xT("\t\tTag/value: ") << polygonPrimitive->typeRuleIdIndex << xT(" (failed to resolve)") << std::endl; } output << xT("\t\tZ order: ") << polygonPrimitive->zOrder << std::endl; output << xT("\t\tArea*2: ") << polygonPrimitive->doubledArea << std::endl; const auto& values = polygonPrimitive->evaluationResult.getValues(); for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values)) { const auto valueDefinitionId = evaluatedValueEntry.key(); const auto value = evaluatedValueEntry.value(); const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId); output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = "); if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color) output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString()); else output << QStringToStlString(value.toString()); output << std::endl; } polygonPrimitiveIndex++; } } const auto itSymbolsGroup = primitivisedData->symbolsGroups.constFind(mapObject); if (itSymbolsGroup != primitivisedData->symbolsGroups.cend()) { const auto& symbolsGroup = *itSymbolsGroup; output << symbolsGroup->symbols.size() << xT(" symbol(s):") << std::endl; unsigned int symbolIndex = 0u; for (const auto& symbol : OsmAnd::constOf(symbolsGroup->symbols)) { const auto textSymbol = std::dynamic_pointer_cast<const OsmAnd::MapPrimitiviser::TextSymbol>(symbol); const auto iconSymbol = std::dynamic_pointer_cast<const OsmAnd::MapPrimitiviser::IconSymbol>(symbol); output << xT("\tSymbol #") << symbolIndex; if (textSymbol) output << xT(" (text)"); else if (iconSymbol) output << xT(" (icon)"); output << std::endl; auto primitiveIndex = -1; if (primitiveIndex == -1) { primitiveIndex = primitivisedGroup->points.indexOf(symbol->primitive); if (primitiveIndex >= 0) output << xT("\t\tPrimitive: Point #") << primitiveIndex << std::endl; } if (primitiveIndex == -1) { primitiveIndex = primitivisedGroup->polylines.indexOf(symbol->primitive); if (primitiveIndex >= 0) output << xT("\t\tPrimitive: Polyline #") << primitiveIndex << std::endl; } if (primitiveIndex == -1) { primitiveIndex = primitivisedGroup->polygons.indexOf(symbol->primitive); if (primitiveIndex >= 0) output << xT("\t\tPrimitive: Polygon #") << primitiveIndex << std::endl; } output << xT("\t\tPosition31: ") << symbol->location31.x << xT("x") << symbol->location31.y << std::endl; output << xT("\t\tOrder: ") << symbol->order << std::endl; output << xT("\t\tDraw along path: ") << (symbol->drawAlongPath ? xT("yes") : xT("no")) << std::endl; output << xT("\t\tIntersects with: ") << QStringToStlString(QStringList(symbol->intersectsWith.toList()).join(QLatin1String(", "))) << std::endl; output << xT("\t\tMinDistance: ") << symbol->minDistance << std::endl; if (textSymbol) { output << xT("\t\tText: ") << QStringToStlString(textSymbol->value) << std::endl; output << xT("\t\tLanguage: "); switch (textSymbol->languageId) { case OsmAnd::LanguageId::Invariant: output << xT("invariant"); break; case OsmAnd::LanguageId::Native: output << xT("native"); break; case OsmAnd::LanguageId::Localized: output << xT("localized"); break; } output << std::endl; output << xT("\t\tDraw text on path: ") << (textSymbol->drawOnPath ? xT("yes") : xT("no")) << std::endl; output << xT("\t\tText vertical offset: ") << textSymbol->verticalOffset << std::endl; output << xT("\t\tText color: ") << QStringToStlString(textSymbol->color.toString()) << std::endl; output << xT("\t\tText size: ") << textSymbol->size << std::endl; output << xT("\t\tText shadow radius: ") << textSymbol->shadowRadius << std::endl; output << xT("\t\tText shadow color: ") << QStringToStlString(textSymbol->shadowColor.toString()) << std::endl; output << xT("\t\tText wrap width: ") << textSymbol->wrapWidth << std::endl; output << xT("\t\tText is bold: ") << (textSymbol->isBold ? xT("yes") : xT("no")) << std::endl; output << xT("\t\tText is italic: ") << (textSymbol->isItalic ? xT("yes") : xT("no")) << std::endl; output << xT("\t\tShield resource name: ") << QStringToStlString(textSymbol->shieldResourceName) << std::endl; } else if (iconSymbol) { output << xT("\t\tIcon resource name: ") << QStringToStlString(iconSymbol->resourceName) << std::endl; for (const auto& overlayResoucreName : iconSymbol->overlayResourceNames) output << xT("\t\tOverlay resource name: ") << QStringToStlString(overlayResoucreName) << std::endl; output << xT("\t\tShield resource name: ") << QStringToStlString(iconSymbol->shieldResourceName) << std::endl; output << xT("\t\tIntersection size: ") << iconSymbol->intersectionSize << std::endl; } symbolIndex++; } } } if (configuration.metrics) { output << xT("Metrics:\n") << QStringToStlString(metrics.toString(false, QLatin1String("\t"))) << std::endl; } break; } return success; }
QVariant QDBusDemarshaller::toVariantInternal() { switch (q_dbus_message_iter_get_arg_type(&iterator)) { case DBUS_TYPE_BYTE: return QVariant::fromValue(toByte()); case DBUS_TYPE_INT16: return QVariant::fromValue(toShort()); case DBUS_TYPE_UINT16: return QVariant::fromValue(toUShort()); case DBUS_TYPE_INT32: return toInt(); case DBUS_TYPE_UINT32: return toUInt(); case DBUS_TYPE_DOUBLE: return toDouble(); case DBUS_TYPE_BOOLEAN: return toBool(); case DBUS_TYPE_INT64: return toLongLong(); case DBUS_TYPE_UINT64: return toULongLong(); case DBUS_TYPE_STRING: return toStringUnchecked(); case DBUS_TYPE_OBJECT_PATH: return QVariant::fromValue(toObjectPathUnchecked()); case DBUS_TYPE_SIGNATURE: return QVariant::fromValue(toSignatureUnchecked()); case DBUS_TYPE_VARIANT: return QVariant::fromValue(toVariant()); case DBUS_TYPE_ARRAY: switch (q_dbus_message_iter_get_element_type(&iterator)) { case DBUS_TYPE_BYTE: // QByteArray return toByteArrayUnchecked(); case DBUS_TYPE_STRING: return toStringListUnchecked(); case DBUS_TYPE_DICT_ENTRY: return QVariant::fromValue(duplicate()); default: return QVariant::fromValue(duplicate()); } case DBUS_TYPE_STRUCT: return QVariant::fromValue(duplicate()); case DBUS_TYPE_UNIX_FD: if (capabilities & QDBusConnection::UnixFileDescriptorPassing) return QVariant::fromValue(toUnixFileDescriptor()); // fall through default: // qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", // q_dbus_message_iter_get_arg_type(&iterator), // q_dbus_message_iter_get_arg_type(&iterator)); char *ptr = 0; ptr += q_dbus_message_iter_get_arg_type(&iterator); q_dbus_message_iter_next(&iterator); // I hope you never dereference this pointer! return QVariant::fromValue<void *>(ptr); }; }
ModulePackage::ModulePackage(std::unique_ptr<QFile> file) { enum { HEAD, BRACE, BODY } state = HEAD; enum { OPERATOR, FUNCTION, TERMINAL } type; OperatorModule::StaticInfo opStatics; FunctionModule::StaticInfo funcStatics; OperatorInterface opInter; FunctionInterface funcInter; QList<QByteArray> head; QString description; QLibrary lib; name_ = QFileInfo(*file).baseName(); if (file->open(QFile::ReadOnly)) { while (!file->atEnd()) { QByteArray line = file->readLine().trimmed(); if (! line.isEmpty()) { switch (state) { case HEAD: head = line.split(':'); head[0] = head.at(0).trimmed(); head[1] = head.at(1).trimmed().toUpper(); if (head.at(1) == "OPERATOR") { type = OPERATOR; //opInter = new OperatorInterface; } else if (head.at(1) == "FUNCTION") { type = FUNCTION; //funcInter = new FunctionInterface; } else if (head.at(1) == "TERMINAL") { type = TERMINAL; } state = BRACE; break; case BRACE: if (line == "{") state = BODY; break; case BODY: if (line == "}") { switch (type) { case OPERATOR: modules.operators.append(OperatorModule(head.at(0), description, this, opInter, opStatics)); break; case FUNCTION: modules.functions.append(FunctionModule(head.at(0), description, this, funcInter, funcStatics)); break; case TERMINAL: modules.terminals.append(TerminalModule(head.at(0), description, this, (std::unique_ptr<CAS::AbstractArithmetic>(*)(const std::string &))lib.resolve(head[0] + "_jmodule"))); break; } state = HEAD; } else { auto colonPos = line.indexOf(':'); auto key = line.left(colonPos).trimmed(); auto value = line.right(line.length() - colonPos - 2).trimmed(); if (key == "description") { description = value; } else if (key == "matches") { if (type == OPERATOR) { opStatics.matches = std::make_shared<QString>(value); } else if (type == FUNCTION) { QList<QByteArray> matchParts = value.split(','); funcStatics.matches = std::make_shared<QPair<QString, unsigned int>>(QString(matchParts.at(0)), matchParts.at(1).toUInt()); } } else if (key == "priority") { if (type == OPERATOR) opStatics.priority = value.toUInt(); else if (type == FUNCTION) funcStatics.priority = value.toUInt(); } else if (type == OPERATOR && key == "associativity") { if (value == "left") opStatics.associativity = OperatorInterface::LEFT; else if (value == "right") opStatics.associativity = OperatorInterface::RIGHT; } else if (key == "lib") { lib.setFileName(value); std::string dbg = QString(head[0]).toStdString(); if (type == OPERATOR) opInter = ((OperatorInterface(*)())lib.resolve(head[0] + "_jmodule"))(); else if (type == FUNCTION) funcInter = ((FunctionInterface(*)())lib.resolve(head[0] + "_jmodule"))(); } } } } } } }
IRBB* bb_to_IR ( /*OUT*/VexGuestExtents* vge, /*IN*/ void* callback_opaque, /*IN*/ DisOneInstrFn dis_instr_fn, /*IN*/ UChar* guest_code, /*IN*/ Addr64 guest_IP_bbstart, /*IN*/ Bool (*chase_into_ok)(void*,Addr64), /*IN*/ Bool host_bigendian, /*IN*/ VexArch arch_guest, /*IN*/ VexArchInfo* archinfo_guest, /*IN*/ IRType guest_word_type, /*IN*/ Bool do_self_check, /*IN*/ Bool (*preamble_function)(void*,IRBB*), /*IN*/ Int offB_TISTART, /*IN*/ Int offB_TILEN ) { Long delta; Int i, n_instrs, first_stmt_idx; Bool resteerOK, need_to_put_IP, debug_print; DisResult dres; IRStmt* imark; static Int n_resteers = 0; Int d_resteers = 0; Int selfcheck_idx = 0; IRBB* irbb; Addr64 guest_IP_curr_instr; IRConst* guest_IP_bbstart_IRConst = NULL; Bool (*resteerOKfn)(void*,Addr64) = NULL; debug_print = toBool(vex_traceflags & VEX_TRACE_FE); /* Note: for adler32 to work without % operation for the self check, need to limit length of stuff it scans to 5552 bytes. Therefore limiting the max bb len to 100 insns seems generously conservative. */ /* check sanity .. */ vassert(sizeof(HWord) == sizeof(void*)); vassert(vex_control.guest_max_insns >= 1); vassert(vex_control.guest_max_insns < 100); vassert(vex_control.guest_chase_thresh >= 0); vassert(vex_control.guest_chase_thresh < vex_control.guest_max_insns); vassert(guest_word_type == Ity_I32 || guest_word_type == Ity_I64); /* Start a new, empty extent. */ vge->n_used = 1; vge->base[0] = guest_IP_bbstart; vge->len[0] = 0; /* And a new IR BB to dump the result into. */ irbb = emptyIRBB(); /* Delta keeps track of how far along the guest_code array we have so far gone. */ delta = 0; n_instrs = 0; /* Guest addresses as IRConsts. Used in the two self-checks generated. */ if (do_self_check) { guest_IP_bbstart_IRConst = guest_word_type==Ity_I32 ? IRConst_U32(toUInt(guest_IP_bbstart)) : IRConst_U64(guest_IP_bbstart); } /* If asked to make a self-checking translation, leave 5 spaces in which to put the check statements. We'll fill them in later when we know the length and adler32 of the area to check. */ if (do_self_check) { selfcheck_idx = irbb->stmts_used; addStmtToIRBB( irbb, IRStmt_NoOp() ); addStmtToIRBB( irbb, IRStmt_NoOp() ); addStmtToIRBB( irbb, IRStmt_NoOp() ); addStmtToIRBB( irbb, IRStmt_NoOp() ); addStmtToIRBB( irbb, IRStmt_NoOp() ); } /* If the caller supplied a function to add its own preamble, use it now. */ if (preamble_function) { Bool stopNow = preamble_function( callback_opaque, irbb ); if (stopNow) { /* The callback has completed the IR block without any guest insns being disassembled into it, so just return it at this point, even if a self-check was requested - as there is nothing to self-check. The five self-check no-ops will still be in place, but they are harmless. */ return irbb; } } /* Process instructions. */ while (True) { vassert(n_instrs < vex_control.guest_max_insns); /* Regardless of what chase_into_ok says, is chasing permissible at all right now? Set resteerOKfn accordingly. */ resteerOK = toBool( n_instrs < vex_control.guest_chase_thresh /* If making self-checking translations, don't chase .. it makes the checks too complicated. We only want to scan just one sequence of bytes in the check, not a whole bunch. */ && !do_self_check /* we can't afford to have a resteer once we're on the last extent slot. */ && vge->n_used < 3 ); resteerOKfn = resteerOK ? chase_into_ok : const_False; /* This is the IP of the instruction we're just about to deal with. */ guest_IP_curr_instr = guest_IP_bbstart + delta; /* This is the irbb statement array index of the first stmt in this insn. That will always be the instruction-mark descriptor. */ first_stmt_idx = irbb->stmts_used; /* Add an instruction-mark statement. We won't know until after disassembling the instruction how long it instruction is, so just put in a zero length and we'll fix it up later. */ addStmtToIRBB( irbb, IRStmt_IMark( guest_IP_curr_instr, 0 )); /* for the first insn, the dispatch loop will have set %IP, but for all the others we have to do it ourselves. */ need_to_put_IP = toBool(n_instrs > 0); /* Finally, actually disassemble an instruction. */ dres = dis_instr_fn ( irbb, need_to_put_IP, resteerOKfn, callback_opaque, guest_code, delta, guest_IP_curr_instr, arch_guest, archinfo_guest, host_bigendian ); /* stay sane ... */ vassert(dres.whatNext == Dis_StopHere || dres.whatNext == Dis_Continue || dres.whatNext == Dis_Resteer); vassert(dres.len >= 0 && dres.len <= 20); if (dres.whatNext != Dis_Resteer) vassert(dres.continueAt == 0); /* Fill in the insn-mark length field. */ vassert(first_stmt_idx >= 0 && first_stmt_idx < irbb->stmts_used); imark = irbb->stmts[first_stmt_idx]; vassert(imark); vassert(imark->tag == Ist_IMark); vassert(imark->Ist.IMark.len == 0); imark->Ist.IMark.len = toUInt(dres.len); /* Print the resulting IR, if needed. */ if (vex_traceflags & VEX_TRACE_FE) { for (i = first_stmt_idx; i < irbb->stmts_used; i++) { vex_printf(" "); ppIRStmt(irbb->stmts[i]); vex_printf("\n"); } } /* If dis_instr_fn terminated the BB at this point, check it also filled in the irbb->next field. */ if (dres.whatNext == Dis_StopHere) { vassert(irbb->next != NULL); if (debug_print) { vex_printf(" "); vex_printf( "goto {"); ppIRJumpKind(irbb->jumpkind); vex_printf( "} "); ppIRExpr( irbb->next ); vex_printf( "\n"); } } /* Update the VexGuestExtents we are constructing. */ /* If vex_control.guest_max_insns is required to be < 100 and each insn is at max 20 bytes long, this limit of 5000 then seems reasonable since the max possible extent length will be 100 * 20 == 2000. */ vassert(vge->len[vge->n_used-1] < 5000); vge->len[vge->n_used-1] = toUShort(toUInt( vge->len[vge->n_used-1] + dres.len )); n_instrs++; if (debug_print) vex_printf("\n"); /* Advance delta (inconspicuous but very important :-) */ delta += (Long)dres.len; switch (dres.whatNext) { case Dis_Continue: vassert(irbb->next == NULL); if (n_instrs < vex_control.guest_max_insns) { /* keep going */ } else { /* We have to stop. */ irbb->next = IRExpr_Const( guest_word_type == Ity_I32 ? IRConst_U32(toUInt(guest_IP_bbstart+delta)) : IRConst_U64(guest_IP_bbstart+delta) ); goto done; } break; case Dis_StopHere: vassert(irbb->next != NULL); goto done; case Dis_Resteer: /* Check that we actually allowed a resteer .. */ vassert(resteerOK); vassert(irbb->next == NULL); /* figure out a new delta to continue at. */ vassert(resteerOKfn(callback_opaque,dres.continueAt)); delta = dres.continueAt - guest_IP_bbstart; /* we now have to start a new extent slot. */ vge->n_used++; vassert(vge->n_used <= 3); vge->base[vge->n_used-1] = dres.continueAt; vge->len[vge->n_used-1] = 0; n_resteers++; d_resteers++; if (0 && (n_resteers & 0xFF) == 0) vex_printf("resteer[%d,%d] to 0x%llx (delta = %lld)\n", n_resteers, d_resteers, dres.continueAt, delta); break; default: vpanic("bb_to_IR"); } } /*NOTREACHED*/ vassert(0); done: /* We're done. The only thing that might need attending to is that a self-checking preamble may need to be created. */ if (do_self_check) { UInt len2check, adler32; IRTemp tistart_tmp, tilen_tmp; vassert(vge->n_used == 1); len2check = vge->len[0]; if (len2check == 0) len2check = 1; adler32 = genericg_compute_adler32( (HWord)guest_code, len2check ); /* Set TISTART and TILEN. These will describe to the despatcher the area of guest code to invalidate should we exit with a self-check failure. */ tistart_tmp = newIRTemp(irbb->tyenv, guest_word_type); tilen_tmp = newIRTemp(irbb->tyenv, guest_word_type); irbb->stmts[selfcheck_idx+0] = IRStmt_Tmp(tistart_tmp, IRExpr_Const(guest_IP_bbstart_IRConst) ); irbb->stmts[selfcheck_idx+1] = IRStmt_Tmp(tilen_tmp, guest_word_type==Ity_I32 ? IRExpr_Const(IRConst_U32(len2check)) : IRExpr_Const(IRConst_U64(len2check)) ); irbb->stmts[selfcheck_idx+2] = IRStmt_Put( offB_TISTART, IRExpr_Tmp(tistart_tmp) ); irbb->stmts[selfcheck_idx+3] = IRStmt_Put( offB_TILEN, IRExpr_Tmp(tilen_tmp) ); irbb->stmts[selfcheck_idx+4] = IRStmt_Exit( IRExpr_Binop( Iop_CmpNE32, mkIRExprCCall( Ity_I32, 2/*regparms*/, "genericg_compute_adler32", #if defined(__powerpc__) && defined(__powerpc64__) (void*)((ULong*)(&genericg_compute_adler32))[0], #else &genericg_compute_adler32, #endif mkIRExprVec_2( mkIRExpr_HWord( (HWord)guest_code ), mkIRExpr_HWord( (HWord)len2check ) ) ), IRExpr_Const(IRConst_U32(adler32)) ), Ijk_TInval, guest_IP_bbstart_IRConst ); } return irbb; }
static inline UInt min32U ( UInt xx, UInt yy ) { return toUInt((xx < yy) ? xx : yy); }
static inline UInt max32U ( UInt xx, UInt yy ) { return toUInt((xx > yy) ? xx : yy); }
static inline UInt mul32 ( Int xx, Int yy ) { Long t = ((Long)xx) * ((Long)yy); return toUInt(t); }