PGE API 0.4
PR00F's Game Engine full documentation
|
PR00F's Game Engine configuration file handler base class. More...
PR00F's Game Engine configuration file handler base class.
This class can load configuration variable data from simple ascii text files and save to file as well. Further logic is added by derived classes.
Definition at line 29 of file PGEcfgFile.h.
#include <PGEcfgFile.h>
Public Member Functions | |
PGEcfgFile (bool bRequireAllAcceptedVarsDefineRequirement, bool bCaseSensitiveVars) | |
virtual | ~PGEcfgFile () |
CConsole & | getConsole () const |
Returns access to console preset with logger module name as this class. | |
std::map< std::string, PGEcfgVariable > & | getVars () |
const std::map< std::string, PGEcfgVariable > & | getVars () const |
bool | load (const char *fname) |
Loads variables from the given config file. | |
bool | save (const char *fname="") const |
Saves variables to the given config file. | |
const std::string & | getFilename () const |
const std::string & | getPathToFile () const |
bool | getAllAcceptedVarsDefineRequirement () const |
bool | getCaseSensitiveVars () const |
const std::set< std::string > & | getAcceptedVars () const |
bool | setAcceptedVars (const std::set< std::string > &newAcceptedVars) |
std::vector< std::string > & | getTemplate () |
Returns the lines of the template generated from the loaded config file. | |
const std::vector< std::string > & | getTemplate () const |
Returns the lines of the template generated from the loaded config file. | |
PGEcfgFile (const PGEcfgFile &other) | |
PGEcfgFile & | operator= (const PGEcfgFile &other) |
Static Public Member Functions | |
static const char * | getLoggerModuleName () |
Returns the logger module name of this class. | |
Protected Member Functions | |
virtual bool | validateOnLoad (std::ifstream &) const |
Validate the file being processed by load(). | |
virtual bool | validateOnSave (std::ofstream &) const |
Validate the file being processed by save(). | |
Static Protected Member Functions | |
static bool | lineIsValueAssignment (const std::string &sTrimmedLine, bool bCaseSensitiveVars, std::string &sVar, std::string &sValue, bool &bParseError) |
Protected Attributes | |
std::set< std::string > | m_acceptedVars |
std::map< std::string, PGEcfgVariable > | m_vars |
Private Member Functions | |
void | lineHandleAssignment (const std::string &sVar, const std::string &sValue, const char *fname, std::set< std::string > &m_missingVars, bool &bParseError) |
Static Private Member Functions | |
static bool | lineIsComment (const std::string &sTrimmedLine) |
static bool | lineShouldBeIgnored (const std::string &sTrimmedLine) |
Private Attributes | |
bool | m_bRequireAllAcceptedVarsDefineRequirement |
bool | m_bCaseSensitiveVars |
std::string | m_sFilename |
std::string | m_sPathToFile |
std::vector< std::string > | m_vTemplateLines |
PGEcfgFile::PGEcfgFile | ( | bool | bRequireAllAcceptedVarsDefineRequirement, |
bool | bCaseSensitiveVars ) |
bRequireAllAcceptedVarsDefineRequirement | If true, all variables that are specified as accepted variables must be defined in the config file. |
bCaseSensitiveVars | If true, all variables will be treated case sensitive, e.g. "Name =" will be different to "name =" or "NAME =". Note: it is your responsibility to define all accepted variables in their lowercafe form if you set case sensitivity to false! |
Definition at line 27 of file PGEcfgFile.cpp.
|
virtual |
Definition at line 35 of file PGEcfgFile.cpp.
|
inline |
Definition at line 65 of file PGEcfgFile.h.
const std::set< std::string > & PGEcfgFile::getAcceptedVars | ( | ) | const |
Definition at line 324 of file PGEcfgFile.cpp.
bool PGEcfgFile::getAllAcceptedVarsDefineRequirement | ( | ) | const |
Definition at line 314 of file PGEcfgFile.cpp.
bool PGEcfgFile::getCaseSensitiveVars | ( | ) | const |
Definition at line 319 of file PGEcfgFile.cpp.
CConsole & PGEcfgFile::getConsole | ( | ) | const |
Returns access to console preset with logger module name as this class.
Definition at line 39 of file PGEcfgFile.cpp.
const std::string & PGEcfgFile::getFilename | ( | ) | const |
Definition at line 304 of file PGEcfgFile.cpp.
|
static |
Returns the logger module name of this class.
Definition at line 44 of file PGEcfgFile.cpp.
const std::string & PGEcfgFile::getPathToFile | ( | ) | const |
Definition at line 309 of file PGEcfgFile.cpp.
std::vector< std::string > & PGEcfgFile::getTemplate | ( | ) |
Returns the lines of the template generated from the loaded config file.
This template is built up automatically in case of a successful load() but you can also modify it if needed. This template is used when writing the configuration back to file: it defines which CVARs in what order should be written to the file, and also the comments unrelated to CVARS.
Definition at line 350 of file PGEcfgFile.cpp.
const std::vector< std::string > & PGEcfgFile::getTemplate | ( | ) | const |
Returns the lines of the template generated from the loaded config file.
This template is built up automatically in case of a successful load() but you can also modify it if needed. This template is used when writing the configuration back to file: it defines which CVARs in what order should be written to the file, and also the comments unrelated to CVARS.
Definition at line 364 of file PGEcfgFile.cpp.
std::map< std::string, PGEcfgVariable > & PGEcfgFile::getVars | ( | ) |
Definition at line 49 of file PGEcfgFile.cpp.
const std::map< std::string, PGEcfgVariable > & PGEcfgFile::getVars | ( | ) | const |
Definition at line 54 of file PGEcfgFile.cpp.
|
private |
Definition at line 486 of file PGEcfgFile.cpp.
|
staticprivate |
Definition at line 476 of file PGEcfgFile.cpp.
|
staticprotected |
Definition at line 373 of file PGEcfgFile.cpp.
|
staticprivate |
Definition at line 481 of file PGEcfgFile.cpp.
bool PGEcfgFile::load | ( | const char * | fname | ) |
Loads variables from the given config file.
Remember: CVAR names are automatically converted to lowercase if you did not request case-sensitive variables in the constructor. It also fills the template vector of strings which can be accessed by getTemplate().
Definition at line 66 of file PGEcfgFile.cpp.
|
inline |
Definition at line 73 of file PGEcfgFile.h.
bool PGEcfgFile::save | ( | const char * | fname = "" | ) | const |
Saves variables to the given config file.
It uses the template vector of strings which can be accessed by getTemplate().
fname | The filename of the file to write to. If left empty, getFilename() is used to determine the file name. |
Definition at line 196 of file PGEcfgFile.cpp.
bool PGEcfgFile::setAcceptedVars | ( | const std::set< std::string > & | newAcceptedVars | ) |
Definition at line 329 of file PGEcfgFile.cpp.
|
protectedvirtual |
Validate the file being processed by load().
Derived class can override this to provide a validating function, e.g. special way to decide if the file being loaded actually has valid format. This is invoked by load() before trying to parse the file. The stream must be already opened prior to calling this function. This function must not open/close the given file stream. Upon success, load() will continue reading the file from the point until this function has read the file.
Reimplemented in PGEcfgProfiles.
Definition at line 450 of file PGEcfgFile.cpp.
|
protectedvirtual |
Validate the file being processed by save().
Derived class can override this to provide a validating function which makes the file compatible with the optionally overridden validateOnLoad() function. For example, if validateOnLoad() checks for a special header, then validateOnSave() is responsible for writing that special header into the file. This is invoked by save() when trying to write the file. The stream must be already opened prior to calling this function. This function must not open/close the given file stream. Upon success, save() will continue writing the file from the point this function has written the file.
Reimplemented in PGEcfgProfiles.
Definition at line 467 of file PGEcfgFile.cpp.
|
protected |
Definition at line 85 of file PGEcfgFile.h.
|
private |
Definition at line 97 of file PGEcfgFile.h.
|
private |
Definition at line 96 of file PGEcfgFile.h.
|
private |
Definition at line 99 of file PGEcfgFile.h.
|
private |
Definition at line 100 of file PGEcfgFile.h.
|
protected |
Definition at line 86 of file PGEcfgFile.h.
|
private |
Definition at line 101 of file PGEcfgFile.h.