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