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


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

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


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

示例1: toFile_MeOnly

bool ccHObject::toFile_MeOnly(QFile& out) const
{
	assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));

	/*** ccHObject takes in charge the ccDrawableObject properties (which is not a ccSerializableObject) ***/

	//'visible' state (dataVersion>=20)
	if (out.write((const char*)&m_visible,sizeof(bool)) < 0)
		return WriteError();
	//'lockedVisibility' state (dataVersion>=20)
	if (out.write((const char*)&m_lockedVisibility,sizeof(bool)) < 0)
		return WriteError();
	//'colorsDisplayed' state (dataVersion>=20)
	if (out.write((const char*)&m_colorsDisplayed,sizeof(bool)) < 0)
		return WriteError();
	//'normalsDisplayed' state (dataVersion>=20)
	if (out.write((const char*)&m_normalsDisplayed,sizeof(bool)) < 0)
		return WriteError();
	//'sfDisplayed' state (dataVersion>=20)
	if (out.write((const char*)&m_sfDisplayed,sizeof(bool)) < 0)
		return WriteError();
	//'colorIsOverriden' state (dataVersion>=20)
	if (out.write((const char*)&m_colorIsOverriden,sizeof(bool)) < 0)
		return WriteError();
	if (m_colorIsOverriden)
	{
		//'tempColor' (dataVersion>=20)
		if (out.write((const char*)m_tempColor,sizeof(colorType)*3) < 0)
			return WriteError();
	}
	//'glTransEnabled' state (dataVersion>=20)
	if (out.write((const char*)&m_glTransEnabled,sizeof(bool)) < 0)
		return WriteError();
	if (m_glTransEnabled)
		if (!m_glTrans.toFile(out))
			return false;

	//'showNameIn3D' state (dataVersion>=24)
	if (out.write((const char*)&m_showNameIn3D,sizeof(bool)) < 0)
		return WriteError();

	return true;
}
开发者ID:fredericoal,项目名称:trunk,代码行数:43,代码来源:ccHObject.cpp

示例2: fromFile

bool ccObject::fromFile(QFile& in, short dataVersion)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	if (dataVersion<20)
		return CorruptError();

	//DGM: if we are here, we assume the class ID has already been read!
	//Call ccObject::readClassIDFromFile if necessary
	////class ID (dataVersion>=20)
	//uint32_t classID = 0;
	//if (in.read((char*)&classID,4)<0)
	//	return ReadError();

	//unique ID (dataVersion>=20)
	//DGM: this ID will be usefull to recreate dynamic links between entities!
	uint32_t uniqueID = 0;
	if (in.read((char*)&uniqueID,4)<0)
		return ReadError();
	m_uniqueID = (unsigned)uniqueID;

	//name
	if (dataVersion < 22) //old style
	{
		char name[256];
		if (in.read(name,256)<0)
			return ReadError();
		setName(name);
	}
	else //(dataVersion>=22)
	{
		QDataStream inStream(&in);
		inStream >> m_name;
	}

	//flags (dataVersion>=20)
	uint32_t flags = 0;
	if (in.read((char*)&flags,4)<0)
		return ReadError();
	m_flags = (unsigned)flags;

	return true;
}
开发者ID:dshean,项目名称:trunk,代码行数:43,代码来源:ccObject.cpp

示例3: fromFile_MeOnly

bool ccHObject::fromFile_MeOnly(QFile& in, short dataVersion)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	/*** ccHObject takes in charge the ccDrawableObject properties (which is not a ccSerializableObject) ***/

	//'visible' state (dataVersion>=20)
	if (in.read((char*)&visible,sizeof(bool))<0)
		return ReadError();
	//'lockedVisibility' state (dataVersion>=20)
	if (in.read((char*)&lockedVisibility,sizeof(bool))<0)
		return ReadError();
	//'colorsDisplayed' state (dataVersion>=20)
	if (in.read((char*)&colorsDisplayed,sizeof(bool))<0)
		return ReadError();
	//'normalsDisplayed' state (dataVersion>=20)
	if (in.read((char*)&normalsDisplayed,sizeof(bool))<0)
		return ReadError();
	//'sfDisplayed' state (dataVersion>=20)
	if (in.read((char*)&sfDisplayed,sizeof(bool))<0)
		return ReadError();
	//'colorIsOverriden' state (dataVersion>=20)
	if (in.read((char*)&colorIsOverriden,sizeof(bool))<0)
		return ReadError();
	if (colorIsOverriden)
	{
		//'tempColor' (dataVersion>=20)
		if (in.read((char*)tempColor,sizeof(colorType)*3)<0)
			return ReadError();
	}
	//'glTransEnabled' state (dataVersion>=20)
	if (in.read((char*)&glTransEnabled,sizeof(bool))<0)
		return ReadError();
	if (glTransEnabled)
		if (!glTrans.fromFile(in,dataVersion))
			return false;

	return true;
}
开发者ID:zhenglai,项目名称:trunk,代码行数:39,代码来源:ccHObject.cpp

示例4: ReadClassIDFromFile

CC_CLASS_ENUM ccObject::ReadClassIDFromFile(QFile& in, short dataVersion)
{
    assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

    //class ID (on 32 bits between version 2.0 and 3.3, then 64 bits from version 3.4)
    CC_CLASS_ENUM classID = CC_TYPES::OBJECT;
    if (dataVersion < 34)
    {
        uint32_t _classID = 0;
        if (in.read((char*)&_classID,4) < 0)
            return ReadError();
        classID = static_cast<CC_CLASS_ENUM>(_classID);
    }
    else
    {
        uint64_t _classID = 0;
        if (in.read((char*)&_classID,8) < 0)
            return ReadError();
        classID = static_cast<CC_CLASS_ENUM>(_classID);
    }

    return classID;
}
开发者ID:Windlkx,项目名称:trunk,代码行数:23,代码来源:ccObject.cpp

示例5: fromFile

bool ccScalarField::fromFile(QFile& in, short dataVersion, int flags)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	if (dataVersion < 20)
		return CorruptError();

	//name (dataVersion>=20)
	if (in.read(m_name,256) < 0)
		return ReadError();

	//'strictly positive' state (20 <= dataVersion < 26)
	bool onlyPositiveValues = false;
	if (dataVersion < 26)
	{
		if (in.read((char*)&onlyPositiveValues,sizeof(bool)) < 0)
			return ReadError();
	}

	//data (dataVersion>=20)
	bool result = false;
	{
		bool fileScalarIsFloat = (flags & ccSerializableObject::DF_SCALAR_VAL_32_BITS);
		if (fileScalarIsFloat && sizeof(ScalarType) == 8) //file is 'float' and current type is 'double'
		{
			result = ccSerializationHelper::GenericArrayFromTypedFile<1,ScalarType,float>(*this,in,dataVersion);
		}
		else if (!fileScalarIsFloat && sizeof(ScalarType) == 4) //file is 'double' and current type is 'float'
		{
			result = ccSerializationHelper::GenericArrayFromTypedFile<1,ScalarType,double>(*this,in,dataVersion);
		}
		else
		{
			result = ccSerializationHelper::GenericArrayFromFile(*this,in,dataVersion);
		}
	}
	if (!result)
		return false;

	//convert former 'hidden/NaN' values for non strictly positive SFs (dataVersion < 26)
	if (dataVersion < 26)
	{
		const ScalarType FORMER_BIG_VALUE = static_cast<ScalarType>(sqrt(3.4e38f)-1.0f);

		for (unsigned i=0; i<m_maxCount; ++i)
		{
			ScalarType val = getValue(i);
			//convert former 'HIDDEN_VALUE' and 'BIG_VALUE' to 'NAN_VALUE'
			if ((onlyPositiveValues && val < 0) || (!onlyPositiveValues && val >= FORMER_BIG_VALUE))
				val = NAN_VALUE;
		}
	}

	//displayed values & saturation boundaries (dataVersion>=20)
	double minDisplayed = 0;
	if (in.read((char*)&minDisplayed,sizeof(double)) < 0)
		return ReadError();
	double maxDisplayed = 0;
	if (in.read((char*)&maxDisplayed,sizeof(double)) < 0)
		return ReadError();
	double minSaturation = 0;
	if (in.read((char*)&minSaturation,sizeof(double)) < 0)
		return ReadError();
	double maxSaturation = 0;
	if (in.read((char*)&maxSaturation,sizeof(double)) < 0)
		return ReadError();
	double minLogSaturation = 0;
	if (in.read((char*)&minLogSaturation,sizeof(double)) < 0)
		return ReadError();
	double maxLogSaturation = 0;
	if (in.read((char*)&maxLogSaturation,sizeof(double)) < 0)
		return ReadError();

	if (dataVersion < 27)
	{
		//'absolute saturation' state (27>dataVersion>=20)
		bool absSaturation = false;
		if (in.read((char*)&absSaturation,sizeof(bool)) < 0)
			return ReadError();
		//quite equivalent to 'symmetrical mode' now...
		m_symmetricalScale = absSaturation;
	}

	//'logarithmic scale' state (dataVersion>=20)
	if (in.read((char*)&m_logScale,sizeof(bool)) < 0)
		return ReadError();

	if (dataVersion < 27)
	{
		bool autoBoundaries = false;
		//'automatic boundaries update' state (dataVersion>=20)
		if (in.read((char*)&autoBoundaries,sizeof(bool)) < 0)
			return ReadError();
		//warn the user that this option is deprecated
		if (!autoBoundaries)
		{
			ccLog::Warning("[ccScalarField] Former 'released' boundaries are deprecated!");
			ccLog::Warning("[ccScalarField] You'll have to create the corresponding 'absolute' color scale (see the Color Scale Manager) and replace the file.");
		}
	}
//.........这里部分代码省略.........
开发者ID:fredericoal,项目名称:trunk,代码行数:101,代码来源:ccScalarField.cpp

示例6: toFile

bool ccScalarField::toFile(QFile& out) const
{
	assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));

	//name (dataVersion>=20)
	if (out.write(m_name,256) < 0)
		return WriteError();

	//data (dataVersion>=20)
	if (!ccSerializationHelper::GenericArrayToFile(*this,out))
		return WriteError();

	//displayed values & saturation boundaries (dataVersion>=20)
	double dValue = (double)m_displayRange.start();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();
	dValue = (double)m_displayRange.stop();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();
	dValue = (double)m_saturationRange.start();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();
	dValue = (double)m_saturationRange.stop();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();
	dValue = (double)m_logSaturationRange.start();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();
	dValue = (double)m_logSaturationRange.stop();
	if (out.write((const char*)&dValue,sizeof(double)) < 0)
		return WriteError();

	//'logarithmic scale' state (dataVersion>=20)
	if (out.write((const char*)&m_logScale,sizeof(bool)) < 0)
		return WriteError();

	//'symmetrical scale' state (dataVersion>=27)
	if (out.write((const char*)&m_symmetricalScale,sizeof(bool)) < 0)
		return WriteError();

	//'NaN values in grey' state (dataVersion>=27)
	if (out.write((const char*)&m_showNaNValuesInGrey,sizeof(bool)) < 0)
		return WriteError();

	//'always show 0' state (dataVersion>=27)
	if (out.write((const char*)&m_alwaysShowZero,sizeof(bool)) < 0)
		return WriteError();

	//color scale (dataVersion>=27)
	{
		bool hasColorScale = (m_colorScale != 0);
		if (out.write((const char*)&hasColorScale,sizeof(bool)) < 0)
			return WriteError();

		if (m_colorScale)
			if (!m_colorScale->toFile(out))
				return WriteError();
	}

	//color ramp steps (dataVersion>=20)
	uint32_t colorRampSteps = (uint32_t)m_colorRampSteps;
	if (out.write((const char*)&colorRampSteps,4) < 0)
		return WriteError();

	return true;
}
开发者ID:fredericoal,项目名称:trunk,代码行数:66,代码来源:ccScalarField.cpp

示例7: fromFile

bool ccHObject::fromFile(QFile& in, short dataVersion, int flags, bool omitChildren)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	//read 'ccObject' header
	if (!ccObject::fromFile(in, dataVersion, flags))
		return false;

	//read own data
	if (!fromFile_MeOnly(in, dataVersion, flags))
		return false;

	if (omitChildren)
		return true;

	//(serializable) child count (dataVersion>=20)
	uint32_t serializableCount = 0;
	if (in.read((char*)&serializableCount,4) < 0)
		return ReadError();

	//read serializable children (if any)
	for (uint32_t i=0; i<serializableCount; ++i)
	{
		//read children class ID
		CC_CLASS_ENUM classID = ReadClassIDFromFile(in, dataVersion);
		if (classID == CC_TYPES::OBJECT)
			return false;

		//create corresponding child object
		ccHObject* child = New(classID);

		//specifc case of custom objects (defined by plugins)
		if (classID == CC_TYPES::CUSTOM_H_OBJECT)
		{
			//store current position
			size_t originalFilePos = in.pos();
			//we need to load the custom object as plain ccCustomHobject
			child->fromFile(in, dataVersion, flags, true);
			//go back to original position
			in.seek(originalFilePos);
			//get custom object name and plugin name
			QString childName = child->getName();
			QString classId = child->getMetaData(ccCustomHObject::DefautMetaDataClassName()).toString();
			QString pluginId = child->getMetaData(ccCustomHObject::DefautMetaDataPluginName()).toString();
			//dont' need this instance anymore
			delete child;
			child = 0;

			// try to get a new object from external factories
			ccHObject* newChild = ccHObject::New(pluginId, classId);
			if (newChild) // found a plugin that can deserialize it
			{
				child = newChild;
			}
			else
			{
				ccLog::Warning(QString("[ccHObject::fromFile] Couldn't found any plugin able to deserialize custom object '%1' (class_ID = %2 / plugin_ID = %3").arg(childName).arg(classID).arg(pluginId));
				return false; // FIXME: for now simply return false. We may want to skip it but I'm not sure if there is a simple way of doing that
			}
		}

		assert(child && child->isSerializable());
		if (child)
		{
			if (child->fromFile(in, dataVersion, flags))
			{
				//FIXME
				//addChild(child,child->getFlagState(CC_FATHER_DEPENDENT));
				addChild(child);
			}
			else
			{
				delete child;
				return false;
			}
		}
		else
		{
			return CorruptError();
		}
	}

	//write current selection behavior (dataVersion>=23)
	if (dataVersion >= 23)
	{
		if (in.read((char*)&m_selectionBehavior,sizeof(SelectionBehavior)) < 0)
			return ReadError();
	}
	else
	{
		m_selectionBehavior = SELECTION_AA_BBOX;
	}

	return true;
}
开发者ID:fredericoal,项目名称:trunk,代码行数:95,代码来源:ccHObject.cpp


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