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


C++ CConfigFile::display方法代码示例

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


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

示例1: main

int main (int /* argc */, char ** /* argv */)
{

	// look at the debug example
	createDebug();

	// Add the data directory to the search path.
	CPath::addSearchPath(NL_SAMPLE_CFG);

	// load and parse the configfile
	cf.load (CPath::lookup("simpletest.txt"));

	// CConfigFile checks if the config file has been modified by an external program.
	// in this case, the configfile automatically reloads and reparses the file.
	// you can connect a callback function that will be called in this case if
	// you want, for example, reset variables
	
	// link a callback with this configfile.
	cf.setCallback (mainCallback);

	// link a callback with the var12. If and only if the var12 changed, this
	// callback will be called
	cf.setCallback ("var12", var12Callback);

	// display all variables
	cf.display(InfoLog);

	// get the value of var1 as int
	int var1 = cf.getVar ("var1").asInt();
	nlinfo("var1 (int) = %d", var1);

	// get the value of var1 as double, in this case, a conversion from int
	// to double will be done
	double var2 = cf.getVar ("var1").asDouble();
	nlinfo("var1 (double) = %lf", var2);

	// get the value of var2 as int, in this case, a conversion from string
	// to int will be done
	int var3 = cf.getVar ("var2").asInt();
	nlinfo("var2 = %d", var3);

	// if the variable is an array of values, you can access them putting the
	// index of the variable you want. Example, get and print all value of var12:
	for (uint i = 0; i < cf.getVar ("var12").size(); i++)
	{
		int val = cf.getVar ("var12").asInt(i);
		nlinfo("%d -> %d", i, val);
	}

	// if you try to access an unknown variable or if something goes wrong, an
	// exception will be called, you can catch them individually or all together in a try/catch block

	try
	{
		// try to access an unknown variable
		int val = cf.getVar ("unknown_variable").asInt();
		nlinfo("unknown_variable = %d", val);
	}
	catch (EConfigFile &e)
	{
		nlinfo("something goes wrong with configfile: %s", e.what());
	}

	cf.getVar ("var13").asInt (0);
	cf.getVar ("var13").asInt (1);
	cf.getVar ("var13").asInt (2);
	
	nlinfo("Try to modify the var12 in the configfile or any other variable.\n\nPress CTRL-C to exit\n");

	while(true)
	{
		CConfigFile::checkConfigFiles();
	}
	return EXIT_SUCCESS;
}
开发者ID:Darkhunter,项目名称:Tranquillien-HCRP-Project-using-NeL,代码行数:75,代码来源:main.cpp


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