예제 #1
0
파일: logs.cpp 프로젝트: naz95naz/tdesktop
QString logVectorLong(const QVector<uint64> &ids) {
	if (!ids.size()) return "[void list]";
	QString idsStr = QString("[%1").arg(*ids.cbegin());
	for (QVector<uint64>::const_iterator i = ids.cbegin() + 1, e = ids.cend(); i != e; ++i) {
		idsStr += QString(", %2").arg(*i);
	}
	return idsStr + "]";
}
예제 #2
0
void mtpUpdateDcOptions(const QVector<MTPDcOption> &options) {
	QSet<int32> already, restart;
	{
		mtpDcOptions opts;
		{
			QReadLocker lock(mtpDcOptionsMutex());
			opts = cDcOptions();
		}
		for (QVector<MTPDcOption>::const_iterator i = options.cbegin(), e = options.cend(); i != e; ++i) {
			const MTPDdcOption &optData(i->c_dcOption());
			int32 id = optData.vid.v, idWithShift = id + (optData.vflags.v * _mtp_internal::dcShift);
			if (already.constFind(idWithShift) == already.cend()) {
				already.insert(idWithShift);
				mtpDcOptions::const_iterator a = opts.constFind(idWithShift);
				if (a != opts.cend()) {
					if (a.value().ip != optData.vip_address.c_string().v || a.value().port != optData.vport.v) {
						restart.insert(id);
					}
				}
				opts.insert(idWithShift, mtpDcOption(id, optData.vflags.v, optData.vip_address.c_string().v, optData.vport.v));
			}
		}
		{
			QWriteLocker lock(mtpDcOptionsMutex());
			cSetDcOptions(opts);
		}
	}
	for (QSet<int32>::const_iterator i = restart.cbegin(), e = restart.cend(); i != e; ++i) {
		MTP::restart(*i);
	}
}
예제 #3
0
void Window::showDelayedServiceMsgs() {
	QVector<DelayedServiceMsg> toAdd = _delayedServiceMsgs;
	_delayedServiceMsgs.clear();
	for (QVector<DelayedServiceMsg>::const_iterator i = toAdd.cbegin(), e = toAdd.cend(); i != e; ++i) {
		serviceNotification(i->first.first, i->second, i->first.second, true);
	}
}
예제 #4
0
bool ewsXmlEnumReader(QXmlStreamReader &reader, QVariant &val, QVector<QString> items)
{
    QString elmName = reader.name().toString();
    QString text = reader.readElementText();
    if (reader.error() != QXmlStreamReader::NoError) {
        qCWarningNC(EWSRES_LOG) << QStringLiteral("Failed to read %1 element - invalid content.")
                        .arg(elmName);
        reader.skipCurrentElement();
        return false;
    }
    int i;
    QVector<QString>::const_iterator it;
    for (it = items.cbegin(); it != items.cend(); it++, i++) {
        if (text == *it) {
            val = i;
            break;
        }
    }

    if (it == items.cend()) {
        qCWarningNC(EWSRES_LOG) << QStringLiteral("Failed to read %1 element - unknown value %2.")
                        .arg(elmName).arg(text);
        return false;
    }
    return true;
}
예제 #5
0
QBitArray OsmAnd::RoutingRulesetContext::encode( const std::shared_ptr<const ObfRoutingSectionInfo>& section, const QVector<uint32_t>& roadTypes )
{
    QBitArray bitset(ruleset->owner->_universalRules.size());
    
    auto itTagValueAttribIdCache = owner->_tagValueAttribIdCache.find(section);
    if(itTagValueAttribIdCache == owner->_tagValueAttribIdCache.cend())
        itTagValueAttribIdCache = owner->_tagValueAttribIdCache.insert(section, QMap<uint32_t, uint32_t>());
    
    for(auto itType = roadTypes.cbegin(); itType != roadTypes.cend(); ++itType)
    {
        auto type = *itType;

        auto itId = itTagValueAttribIdCache->find(type);
        if(itId == itTagValueAttribIdCache->end())
        {
            const auto& encodingRule = section->_d->_encodingRules[type];
            assert(encodingRule);

            auto id = ruleset->owner->registerTagValueAttribute(encodingRule->_tag, encodingRule->_value);
            itId = itTagValueAttribIdCache->insert(type, id);
        }
        auto id = *itId;

        if(bitset.size() <= id)
            bitset.resize(id + 1);
        bitset.setBit(id);
    }

    return bitset;
}
예제 #6
0
QVector<TacheUnitaire*> ProjetManager::getTachesProgrammable()
{
    QVector<TacheUnitaire*> res;
    QVector<TacheUnitaire*> taches = this->getUnitaire();
    for (QVector<TacheUnitaire*>::const_iterator it = taches.cbegin(); it != taches.cend(); ++it)
    {
        TacheUnitaire* t = *it;
        if(t->estProgrammable())
            res.push_back(t);
    }

    return res;
}
예제 #7
0
QVector<FileContainer> Documents::newerFileContainers(const QVector<FileContainer> &fileContainers) const
{
    QVector<FileContainer> newerContainers;

    auto documentIsNewer = [this] (const FileContainer &fileContainer) {
        try {
            return document(fileContainer).documentRevision() != fileContainer.documentRevision();
        } catch (const DocumentDoesNotExistException &) {
            return true;
        }
    };

    std::copy_if(fileContainers.cbegin(),
                 fileContainers.cend(),
                 std::back_inserter(newerContainers),
                 documentIsNewer);

    return newerContainers;
}
예제 #8
0
void mtpUpdateDcOptions(const QVector<MTPDcOption> &options) {
	QSet<int32> already, restart;
	{
		mtpDcOptions opts(cDcOptions());
		for (QVector<MTPDcOption>::const_iterator i = options.cbegin(), e = options.cend(); i != e; ++i) {
			const MTPDdcOption &optData(i->c_dcOption());
			if (already.constFind(optData.vid.v) == already.cend()) {
				already.insert(optData.vid.v);
				mtpDcOptions::const_iterator a = opts.constFind(optData.vid.v);
				if (a != opts.cend()) {
					if (a.value().ip != optData.vip_address.c_string().v || a.value().port != optData.vport.v) {
						restart.insert(optData.vid.v);
					}
				}
				opts.insert(optData.vid.v, mtpDcOption(optData.vid.v, optData.vhostname.c_string().v, optData.vip_address.c_string().v, optData.vport.v));
			}
		}
		cSetDcOptions(opts);
	}
	for (QSet<int32>::const_iterator i = restart.cbegin(), e = restart.cend(); i != e; ++i) {
		MTP::restart(*i);
	}
}
예제 #9
0
bool OsmAnd::MapRasterizer_P::containsHelper(const QVector< PointI >& points, const PointI& otherPoint)
{
    uint32_t intersections = 0;

    auto itPrevPoint = points.cbegin();
    auto itPoint = itPrevPoint + 1;
    for (const auto itEnd = points.cend(); itPoint != itEnd; itPrevPoint = itPoint, ++itPoint)
    {
        const auto& point0 = *itPrevPoint;
        const auto& point1 = *itPoint;

        if (Utilities::rayIntersect(point0, point1, otherPoint))
            intersections++;
    }

    // special handling, also count first and last, might not be closed, but
    // we want this!
    const auto& point0 = points.first();
    const auto& point1 = points.last();
    if (Utilities::rayIntersect(point0, point1, otherPoint))
        intersections++;

    return intersections % 2 == 1;
}
예제 #10
0
파일: avform.cpp 프로젝트: Pik-9/qTox
void AVForm::selectBestModes(QVector<VideoMode> &allVideoModes)
{
    // Identify the best resolutions available for the supposed XXXXp resolutions.
    std::map<int, VideoMode> idealModes;
    idealModes[120] = VideoMode(160, 120);
    idealModes[240] = VideoMode(430, 240);
    idealModes[360] = VideoMode(640, 360);
    idealModes[480] = VideoMode(854, 480);
    idealModes[720] = VideoMode(1280, 720);
    idealModes[1080] = VideoMode(1920, 1080);

    std::map<int, int> bestModeInds;
    for (int i = 0; i < allVideoModes.size(); ++i)
    {
        VideoMode mode = allVideoModes[i];

        // PS3-Cam protection, everything above 60fps makes no sense
        if (mode.FPS > 60)
            continue;

        for (auto iter = idealModes.begin(); iter != idealModes.end(); ++iter)
        {
            int res = iter->first;
            VideoMode idealMode = iter->second;
            // don't take approximately correct resolutions unless they really
            // are close
            if (mode.norm(idealMode) > 300)
                continue;

            if (bestModeInds.find(res) == bestModeInds.end())
            {
                bestModeInds[res] = i;
                continue;
            }

            int index = bestModeInds[res];
            VideoMode best = allVideoModes[index];
            if (mode.norm(idealMode) < best.norm(idealMode))
            {
                bestModeInds[res] = i;
                continue;
            }

            if (mode.norm(idealMode) == best.norm(idealMode))
            {
                // prefer higher FPS and "better" pixel formats
                if (mode.FPS > best.FPS)
                {
                    bestModeInds[res] = i;
                    continue;
                }

                bool better = CameraDevice::betterPixelFormat(mode.pixel_format, best.pixel_format);
                if (mode.FPS >= best.FPS && better)
                    bestModeInds[res] = i;
            }
        }
    }

    QVector<VideoMode> newVideoModes;
    for (auto it = bestModeInds.rbegin(); it != bestModeInds.rend(); ++it)
    {
        VideoMode mode = allVideoModes[it->second];

        if (newVideoModes.empty())
        {
            newVideoModes.push_back(mode);
        }
        else
        {
            int size = getModeSize(mode);
            auto result = std::find_if(newVideoModes.cbegin(), newVideoModes.cend(),
                                       [size](VideoMode mode) { return getModeSize(mode) == size; });

            if (result == newVideoModes.end())
                newVideoModes.push_back(mode);
        }
    }
    allVideoModes = newVideoModes;
}
예제 #11
0
void OsmAnd::Utilities::scanlineFillPolygon(const unsigned int verticesCount, const PointF* vertices, std::function<void(const PointI&)> fillPoint)
{
    // Find min-max of Y
    float yMinF, yMaxF;
    yMinF = yMaxF = vertices[0].y;
    for(auto idx = 1u; idx < verticesCount; idx++)
    {
        const auto& y = vertices[idx].y;
        if (y > yMaxF)
            yMaxF = y;
        if (y < yMinF)
            yMinF = y;
    }
    const auto rowMin = qFloor(yMinF);
    const auto rowMax = qFloor(yMaxF);

    // Build set of edges
    struct Edge
    {
        const PointF* v0;
        int startRow;
        const PointF* v1;
        int endRow;
        float xOrigin;
        float slope;
        int nextRow;
    };
    QVector<Edge*> edges;
    edges.reserve(verticesCount);
    auto edgeIdx = 0u;
    for(auto idx = 0u, prevIdx = verticesCount - 1; idx < verticesCount; prevIdx = idx++)
    {
        auto v0 = &vertices[prevIdx];
        auto v1 = &vertices[idx];

        if (v0->y == v1->y)
        {
            // Horizontal edge
            auto edge = new Edge();
            edge->v0 = v0;
            edge->v1 = v1;
            edge->startRow = qFloor(edge->v0->y);
            edge->endRow = qFloor(edge->v1->y);
            edge->xOrigin = edge->v0->x;
            edge->slope = 0;
            edge->nextRow = qFloor(edge->v0->y) + 1;
            edges.push_back(edge);
            //LogPrintf(LogSeverityLevel::Debug, "Edge %p y(%d %d)(%f %f), next row = %d", edge, edge->startRow, edge->endRow, edge->v0->y, edge->v1->y, edge->nextRow);

            continue;
        }

        const PointF* pLower = nullptr;
        const PointF* pUpper = nullptr;
        if (v0->y < v1->y)
        {
            // Up-going edge
            pLower = v0;
            pUpper = v1;
        }
        else if (v0->y > v1->y)
        {
            // Down-going edge
            pLower = v1;
            pUpper = v0;
        }

        // Fill edge 
        auto edge = new Edge();
        edge->v0 = pLower;
        edge->v1 = pUpper;
        edge->startRow = qFloor(edge->v0->y);
        edge->endRow = qFloor(edge->v1->y);
        edge->slope = (edge->v1->x - edge->v0->x) / (edge->v1->y - edge->v0->y);
        edge->xOrigin = edge->v0->x - edge->slope * (edge->v0->y - qFloor(edge->v0->y));
        edge->nextRow = qFloor(edge->v1->y) + 1;
        for(auto vertexIdx = 0u; vertexIdx < verticesCount; vertexIdx++)
        {
            const auto& v = vertices[vertexIdx];

            if (v.y > edge->v0->y && qFloor(v.y) < edge->nextRow)
                edge->nextRow = qFloor(v.y);
        }
        //LogPrintf(LogSeverityLevel::Debug, "Edge %p y(%d %d)(%f %f), next row = %d", edge, edge->startRow, edge->endRow, edge->v0->y, edge->v1->y, edge->nextRow);
        edges.push_back(edge);
    }

    // Sort edges by ascending Y
    qSort(edges.begin(), edges.end(), [](Edge* l, Edge* r) -> bool
    {
        return l->v0->y > r->v0->y;
    });

    // Loop in [yMin .. yMax]
    QVector<Edge*> aet;
    aet.reserve(edges.size());
    for(auto rowIdx = rowMin; rowIdx <= rowMax;)
    {
        //LogPrintf(LogSeverityLevel::Debug, "------------------ %d -----------------", rowIdx);

        // Find active edges
        int nextRow = rowMax;
        for(const auto& edge : constOf(edges))
        {
            const auto isHorizontal = (edge->startRow == edge->endRow);
            if (nextRow > edge->nextRow && edge->nextRow > rowIdx && !isHorizontal)
                nextRow = edge->nextRow;

            if (edge->startRow != rowIdx)
                continue;

            if (isHorizontal)
            {
                // Fill horizontal edge
                const auto xMin = qFloor(qMin(edge->v0->x, edge->v1->x));
                const auto xMax = qFloor(qMax(edge->v0->x, edge->v1->x));
                /*for(auto x = xMin; x <= xMax; x++)
                    fillPoint(PointI(x, rowIdx));*/
                continue;
            }

            //LogPrintf(LogSeverityLevel::Debug, "line %d. Adding edge %p y(%f %f)", rowIdx, edge, edge->v0->y, edge->v1->y);
            aet.push_back(edge);
            continue;
        }

        // If there are no active edges, we've finished filling
        if (aet.isEmpty())
            break;
        assert(aet.size() % 2 == 0);

        // Sort aet by X
        qSort(aet.begin(), aet.end(), [](Edge* l, Edge* r) -> bool
        {
            return l->v0->x > r->v0->x;
        });

        // Find next row
        for(; rowIdx < nextRow; rowIdx++)
        {
            const unsigned int pairsCount = aet.size() / 2;

            auto itEdgeL = aet.cbegin();
            auto itEdgeR = itEdgeL + 1;

            for(auto pairIdx = 0u; pairIdx < pairsCount; pairIdx++, itEdgeL = ++itEdgeR, ++itEdgeR)
            {
                auto lEdge = *itEdgeL;
                auto rEdge = *itEdgeR;

                // Fill from l to r
                auto lXf = lEdge->xOrigin + (rowIdx - lEdge->startRow + 0.5f) * lEdge->slope;
                auto rXf = rEdge->xOrigin + (rowIdx - rEdge->startRow + 0.5f) * rEdge->slope;
                auto xMinF = qMin(lXf, rXf);
                auto xMaxF = qMax(lXf, rXf);
                auto xMin = qFloor(xMinF);
                auto xMax = qFloor(xMaxF);

                LogPrintf(LogSeverityLevel::Debug, "line %d from %d(%f) to %d(%f)", rowIdx, xMin, xMinF, xMax, xMaxF);
                /*for(auto x = xMin; x <= xMax; x++)
                    fillPoint(PointI(x, rowIdx));*/
            }
        }

        // Deactivate those edges that have end at yNext
        for(auto itEdge = aet.begin(); itEdge != aet.end();)
        {
            auto edge = *itEdge;

            if (edge->endRow <= nextRow)
            {
                // When we're done processing the edge, fill it Y-by-X
                auto startCol = qFloor(edge->v0->x);
                auto endCol = qFloor(edge->v1->x);
                auto revSlope = 1.0f / edge->slope;
                auto yOrigin = edge->v0->y - revSlope * (edge->v0->x - qFloor(edge->v0->x));
                auto xMax = qMax(startCol, endCol);
                auto xMin = qMin(startCol, endCol);
                for(auto colIdx = xMin; colIdx <= xMax; colIdx++)
                {
                    auto yf = yOrigin + (colIdx - startCol + 0.5f) * revSlope;
                    auto y = qFloor(yf);

                    LogPrintf(LogSeverityLevel::Debug, "col %d(s%d) added Y = %d (%f)", colIdx, colIdx - startCol, y, yf);
                    fillPoint(PointI(colIdx, y));
                }

                //////////////////////////////////////////////////////////////////////////
                auto yMax = qMax(edge->startRow, edge->endRow);
                auto yMin = qMin(edge->startRow, edge->endRow);
                for(auto rowIdx_ = yMin; rowIdx_ <= yMax; rowIdx_++)
                {
                    auto xf = edge->xOrigin + (rowIdx_ - edge->startRow + 0.5f) * edge->slope;
                    auto x = qFloor(xf);

                    LogPrintf(LogSeverityLevel::Debug, "row %d(s%d) added Y = %d (%f)", rowIdx_, rowIdx_ - edge->startRow, x, xf);
                    fillPoint(PointI(x, rowIdx_));
                }
                //////////////////////////////////////////////////////////////////////////

                //LogPrintf(LogSeverityLevel::Debug, "line %d. Removing edge %p y(%f %f)", rowIdx, edge, edge->v0->y, edge->v1->y);
                itEdge = aet.erase(itEdge);
            }
            else
                ++itEdge;
        }
    }

    // Cleanup
    for(const auto& edge : constOf(edges))
        delete edge;
}