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


C++ AttributeMap::keys方法代码示例

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


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

示例1: writePreserving

	void writePreserving(QFile& inFile, QTextStream& out, const AttributeMap& data)
	{
		FNTRACE("ini", "", "writePreserving", QString("in, out, %1 rows of data").arg(data.size()));

		int i, j;
		QChar c;
		QString name;
		size_t lineNumber = 0;
		QString line;
		typedef QSet<AttributeMap::key_type> KeySet;
		KeySet unwrittenKeys = KeySet::fromList(data.keys());

		if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text))
			ETHROW(Exception(QString("Unable to open %1 for reading.").arg(inFile.fileName())));
		QTextStream in(&inFile);

		while (!(line = in.readLine()).isNull())
		{
			++lineNumber;
			//std::cout << lineNumber << ": " << line.toStdString() << ":\n";

			for (i = 0; line[i].isSpace(); ++i) { out << line[i]; }

			if (line[i].isNull()) { out << '\n'; continue; }
			else if (line[i] == COMMENT_BEGIN) { out << line.mid(i) << '\n'; continue; }

			for (j = i; !(c = line[i]).isNull() && c!=COMMENT_BEGIN && c!=ASSIGNER; ++i) ;
			//std::cout << "non-empty, ";
			if (c != ASSIGNER) // non-empty line that isn't assignment -> invalid
				ETHROW(ParseError(inFile.fileName(), lineNumber, "Unknown non-empty line."));
			for (--i; line[i].isSpace(); --i) ; // last character of name
			name = line.mid(j, i - j + 1);
			//std::cout << "name: " << name.toStdString() << ' ';

			for ( ; line[j]!=ASSIGNER; ++j) out << line[j];
			out << ASSIGNER;
			i = j + 1;

			for ( ; line[i].isSpace(); ++i) out << line[i];

			if (data.contains(name))
			{
				//std::cout << "known ";
				out << data.value(name);
				unwrittenKeys.remove(name);
				for (j = i; !line[i].isNull() && line[i]!=COMMENT_BEGIN; ++i) ; // EOL || comment
				for (--i; line[i].isSpace(); --i) ; // last character of value
				++i; // first character after value
			}

			out << line.mid(i) << '\n';
			//std::cout << '\n';
		}

		if (unwrittenKeys.size())
		{
			out << '\n' << COMMENT_BEGIN << "Following lines were generated by Ds1edit Loader:\n";
			for (KeySet::iterator key = unwrittenKeys.begin();
				key != unwrittenKeys.end(); ++key)
				out << (*key) << ' ' << ASSIGNER << ' ' << data.value(*key) << '\n';
		}

		//in.resize(in.pos()+1);
		inFile.close();
	}
开发者ID:devnev,项目名称:ds1edit-loader,代码行数:65,代码来源:iniparser.cpp


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