|
|
|
|
Documentation |
|
Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages Search
NLMISC::CConfigFile Class ReferenceCConfigFile class.
More...
#include <config_file.h>
List of all members.
Detailed Description
CConfigFile class.
Useful when you want to have a configuration file with variables. It manages integers, real (double), and string basic types. A variable can be an array of basic type. In this case, all elements of the array must have the same type.
If you setup the global callback before loading, it'll be call after the load() function.
Example: try
{
CConfigFile cf;
cf.load ("test.txt");
cf.setCallback ("var1", var1cb);
CConfigFile::CVar &foo = cf.getVar ("foo");
printf ("foo = %s\n", foo.asString ().c_str ());
CConfigFile::CVar &bar = cf.getVar ("bar");
printf ("bar have %d elements : \n", bar.size ());
for (int i = 0; i < bar.size (); i++)
printf ("%d ", bar.asInt (i));
printf("\n");
}
catch (EConfigFile &e)
{
printf ("%s\n", e.what ());
}
*
Example of config file:
/ * big comment
on more than one line * /
var1 = 123;
var2 = "456.25";
var3 = 123.123;
var4 = 123.123 + 2;
var5 = 123 + 2.1;
var6 = (-112+1) * 3 - 14;
var7 = var1 + 1;
var8 = var2 + 10;
var9 = 10.15 + var2;
var10 = { 10.0, 51.1 };
var11 = { "str1", "str2", "str3" };
var12 = { 10+var1, var1-var7 };
*
Operators are '+', '-', '*', '/'. You can't use operators on a array variable, for example, you can't do \cvar13=var12+1. If you have 2 variables with the same name, the first value will be remplaced by the second one.
-
Bug:
-
if you terminate the config file with a comment without carriage returns it'll generate an exception, add a carriage returns
-
Author:
-
Vianney Lecroart , Nevrax France
-
Date:
-
2000
Definition at line 119 of file config_file.h.
Constructor & Destructor Documentation
NLMISC::CConfigFile::CConfigFile |
( |
|
) |
[inline] |
|
NLMISC::CConfigFile::~CConfigFile |
( |
|
) |
[virtual] |
|
Member Function Documentation
void NLMISC::CConfigFile::CConfigFile::setTimeout |
( |
uint32 |
timeout |
) |
[static] |
|
|
set the time between 2 file checking (default value is 1 second) -
Parameters:
-
timeout |
time in millisecond, if timeout=0, the check will be made each "frame". |
|
void NLMISC::CConfigFile::checkConfigFiles |
( |
|
) |
[static] |
|
bool NLMISC::CConfigFile::exists |
( |
const std::string & |
varName |
) |
|
|
|
Return true if the variable exists, false otherwise.
Definition at line 410 of file config_file.cpp.
References _Vars. |
std::string NLMISC::CConfigFile::getFilename |
( |
|
) |
const [inline] |
|
uint32 NLMISC::CConfigFile::getLastModified |
( |
|
) |
[private] |
|
void NLMISC::CConfigFile::load |
( |
const std::string & |
fileName |
) |
|
|
bool NLMISC::CConfigFile::loaded |
( |
|
) |
|
|
void NLMISC::CConfigFile::print |
( |
CLog * |
log |
) |
const |
|
void NLMISC::CConfigFile::print |
( |
|
) |
const |
|
void NLMISC::CConfigFile::reparse |
( |
const char * |
filename = NULL, |
|
|
bool |
callingCallback = true |
|
) |
|
|
|
reload and reparse the file.
Definition at line 270 of file config_file.cpp.
References _Callback, _FileName, _LastModified, _Vars, cf_CurrentLine, cf_ifile, cf_OverwriteExistingVariable, cfparse, cfrestart, getLastModified, nlassert, and nlwarning.
Referenced by load. |
void NLMISC::CConfigFile::save |
( |
|
) |
const |
|
void NLMISC::CConfigFile::setCallback |
( |
const std::string & |
VarName, |
|
|
void(* |
cb)(CConfigFile::CVar &var) |
|
) |
|
|
|
set a callback function to a variable, it will be called when this variable is modified.
Definition at line 575 of file config_file.cpp.
References _Vars. |
void NLMISC::CConfigFile::setCallback |
( |
void(* |
cb)() |
) |
|
|
void NLMISC::CConfigFile::setLastModifiedNow |
( |
|
) |
|
|
Member Data Documentation
void(* NLMISC::CConfigFile::_Callback)() [private]
|
|
vector< CConfigFile * > * NLMISC::CConfigFile::_ConfigFiles = NULL [static, private]
|
|
std::string NLMISC::CConfigFile::_FileName [private]
|
|
uint32 NLMISC::CConfigFile::_LastModified [private]
|
|
uint32 NLMISC::CConfigFile::_Timeout = 1000 [static, private]
|
|
std::vector<CVar> NLMISC::CConfigFile::_Vars [private]
|
|
std::vector<std::string> NLMISC::CConfigFile::UnknownVariables
|
|
The documentation for this class was generated from the following files:
|
|