当前位置: 首页>>代码示例>>C++>>正文


C++ QFile::map方法代码示例

本文整理汇总了C++中QFile::map方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::map方法的具体用法?C++ QFile::map怎么用?C++ QFile::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QFile的用法示例。


在下文中一共展示了QFile::map方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: hashFile

QByteArray Scanner::hashFile(QFile &f)
{
    uchar *map;

    QCryptographicHash hasher(QCryptographicHash::Sha1);
    hasher.reset();

    /* Try map first */
    map = f.map( 0, f.size() );
    if (NULL==map) {
        /* no mmap, read in chunks */
        uchar buffer[512];
        qint64 r;
        do {
            r = f.read((char*)buffer,sizeof(buffer));
            if (r<0){
                throw 1;
            }
            if (r<=0)
                break;
            hasher.addData( (const char*)buffer, r);
        } while (r>0);

    } else {
        hasher.addData((const char*)map,f.size());
        f.unmap(map);
    }

    return hasher.result();
}
开发者ID:kdgoup,项目名称:arduinoupdater,代码行数:30,代码来源:scanner.cpp

示例2: qWarning

FixFile::FixFile(QIODevice* file, const QString& filename)
{
    _file = file;

    if (!file) {
        _len = 0;
        _currentLeft = 0;
        _openError = true;
        return;
    }

    _filename = filename;
    if (!file->isOpen() && !file->open( QIODevice::ReadOnly ) ) {
        qWarning( "%s: %s", (const char*)QFile::encodeName(_filename),
                  strerror( errno ) );
        _len = 0;
        _currentLeft = 0;
        _openError = true;
        return;
    }

    _openError = false;
    _used_mmap = false;

    uchar* addr = 0;

#if QT_VERSION >= 0x040400
    // QFile::map was introduced with Qt 4.4
    if (file->size() >0) {
        QFile* mappableDevice = dynamic_cast<QFile*>(file);
        if (mappableDevice) {
            addr = mappableDevice->map( 0, file->size() );
        }
    }
#endif

    if (addr) {
        // map succeeded
        _base = (char*) addr;
        _len = file->size();
        _used_mmap = true;

        if (0) qDebug("Mapped '%s'", qPrintable( _filename ));
    }
    else {
        // try reading the data into memory instead
        file->seek(0);
        _data = file->readAll();
        _base = _data.data();
        _len  = _data.size();
    }

    _current     = _base;
    _currentLeft = _len;
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:55,代码来源:utils.cpp

示例3: findEnd

uint JsonEngine::findEnd(QFile &file)
{
	int len = file.size();
	QByteArray data;
	uchar *fmap = file.map(0, file.size());
	if(!fmap)
	{
		data = file.readAll();
		fmap = (uchar *)data.constData();
	}
	uint end = file.size();
	const uchar *s = K8JSON::skipBlanks(fmap, &len);
	uchar qch = *s;
	if(!s || (qch != '[' && qch != '{'))
	{
		if(data.isEmpty())
			file.unmap(fmap);
		return end;
	}
	qch = (qch == '{' ? '}' : ']');
	s++;
	len--;
	bool first = true;
	while(s)
	{
		s = K8JSON::skipBlanks(s, &len);
		if(len < 2 || (s && *s == qch))
		{
			if(*(s-1) == '\n')
				s--;
			end = (uint)(s - fmap);
			break;
		}
		if(!s)
			break;
		if((!first && *s != ',') || (first && *s == ','))
			break;
		first = false;
		if(*s == ',')
		{
			s++;
			len--;
		}
		if(!(s = K8JSON::skipRec(s, &len)))
			break;
	}
	if(data.isEmpty())
		file.unmap(fmap);
	return end;
}
开发者ID:veksha,项目名称:vekshas-qutim,代码行数:50,代码来源:jsonengine.cpp

示例4: map

static QFile* map(QString path, raw_buffer &fData)
{
	const char *message;

	QFile *f = new QFile(path);

	if (!f->open(QIODevice::ReadOnly)) {
		message = "is not readable";
		goto map_failed;
	}

	if (f->size() > std::numeric_limits<typeof(fData.m_len)>::max()) {
		message = "is too big";
		goto map_failed;
	}

	if (f->size() != 0) {
		fData.m_len = f->size();
		fData.m_str = (const char *)f->map(0, f->size());
		if (fData.m_str == NULL) {
			message = "failed to memory map";
			goto map_failed;
		}
	} else {
		qDebug() << "File" << path << "is empty";
		fData.m_len = 0;
		fData.m_str = "";
	}

	return f;

map_failed:

	f->close();
	delete f;
	f = NULL;

	const char *fileNameStr = qPrintable(path);

	fprintf(stderr, "%s %s\n", fileNameStr, message);
	return f;
}
开发者ID:eslng,项目名称:libpbnjson,代码行数:42,代码来源:TestSchema.cpp

示例5: QByteArray

QByteArray QCOMM::md5(QFile &file)
{
    unsigned char *buf;
    bool isopen;
    if(!file.exists())
        return QByteArray();
    if(file.size()==0)
        return QByteArray();
    if(file.isOpen())
        isopen = TRUE;
    if(isopen&&(!file.open(QIODevice::ReadOnly)))
        return QByteArray();
    buf = file.map(0,file.size());
    if(isopen)
        file.close();
    if(0==buf)
        return QByteArray();
    QByteArray data = QByteArray::fromRawData((char*)buf,file.size());
    QByteArray md5 =  QCryptographicHash::hash (data, QCryptographicHash::Md5);
    file.unmap(buf);
    return md5;
}
开发者ID:httpftpli,项目名称:wm,代码行数:22,代码来源:qcomm.cpp


注:本文中的QFile::map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。