2002-11-21 05:40:49 +00:00
|
|
|
/*******************************************************************************
|
2002-12-29 06:50:19 +00:00
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
Licensed under a BSD-style license.
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
2002-11-21 05:40:49 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\par File Header:
|
|
|
|
File: Types/ZE_ZConfigFile.h <br>
|
|
|
|
Description: Header file for ZEngine INI-Style Config Files.<br>
|
|
|
|
Author(s): James Turk <br>
|
2003-02-10 04:40:16 +00:00
|
|
|
$Id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br>
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
\file ZE_ZConfigFile.h
|
|
|
|
\brief Definition file for ZConfigFile.
|
|
|
|
|
|
|
|
Definition file for ZConfigFile, an INI-style Config format.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __ze_zconfigfile_h__
|
|
|
|
#define __ze_zconfigfile_h__
|
|
|
|
|
2003-02-10 04:02:38 +00:00
|
|
|
#include "ZE_ZEngine.h"
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
namespace ZE
|
|
|
|
{
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief ZConfigFile Class for use in ZEngine.
|
|
|
|
|
|
|
|
ZConfigFile class for INI-style configuration files for games or applications. Inherited from ZObject.
|
|
|
|
**/
|
2003-02-10 04:02:38 +00:00
|
|
|
class ZConfigFile
|
2002-11-21 05:40:49 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2002-12-01 07:56:17 +00:00
|
|
|
//Private Types//
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief ZConfigFile Variable class.
|
|
|
|
|
|
|
|
ZConfigFile class for mapping a variable name to it's value, stored in string form (later converted to
|
|
|
|
bool or int if needed).
|
|
|
|
**/
|
2002-11-21 05:40:49 +00:00
|
|
|
class ZCF_Variable
|
|
|
|
{
|
|
|
|
public:
|
2002-12-01 07:56:17 +00:00
|
|
|
//! Variable name.
|
2002-11-21 05:40:49 +00:00
|
|
|
string var;
|
2002-12-01 07:56:17 +00:00
|
|
|
//! Value associated with variable.
|
2002-11-21 05:40:49 +00:00
|
|
|
string val;
|
|
|
|
};
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief ZConfigFile Section class.
|
|
|
|
|
|
|
|
ZConfigFile class for mapping a section name to a list of variables in that section.
|
|
|
|
**/
|
2002-11-21 05:40:49 +00:00
|
|
|
class ZCF_Section
|
|
|
|
{
|
|
|
|
public:
|
2002-12-01 07:56:17 +00:00
|
|
|
//! Section name.
|
2002-11-21 05:40:49 +00:00
|
|
|
string section;
|
2002-12-01 07:56:17 +00:00
|
|
|
//! STL list of variables.
|
2002-11-21 05:40:49 +00:00
|
|
|
list<ZCF_Variable> varList;
|
|
|
|
};
|
|
|
|
|
2003-02-10 04:02:38 +00:00
|
|
|
protected:
|
2002-11-21 05:40:49 +00:00
|
|
|
//! List of sections of internal type.
|
2003-02-10 04:02:38 +00:00
|
|
|
list<ZCF_Section> rFileLayout;
|
2002-11-21 05:40:49 +00:00
|
|
|
//! Filename of file currently open.
|
2003-02-10 04:02:38 +00:00
|
|
|
string rFilename;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Reformat a string in a form more suitable to parsing.
|
|
|
|
|
|
|
|
Removes whitespace from a string and makes all characters lowercase.
|
|
|
|
\param str The string to get a clean version of.
|
|
|
|
\return Cleaned string.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
string CleanString(string str) const;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2002-12-04 23:08:17 +00:00
|
|
|
/*!
|
2002-12-04 23:06:45 +00:00
|
|
|
\brief Check if a section exists.
|
|
|
|
|
|
|
|
Find out if a section currently exists.
|
|
|
|
\param sec Section to check for.
|
|
|
|
\return bool, true if section exists in file.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool Exists(string sec) const;
|
2002-12-04 23:06:45 +00:00
|
|
|
|
2002-12-04 23:08:17 +00:00
|
|
|
/*!
|
2002-12-04 23:06:45 +00:00
|
|
|
\brief Check if a variable exists.
|
|
|
|
|
|
|
|
Find out if a variable currently exists.
|
|
|
|
\param sec Section to check in.
|
|
|
|
\param var Variable to check for.
|
|
|
|
\return bool, true if section exists in file.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool Exists(string sec, string var) const;
|
2002-12-04 23:06:45 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Internal function to set variables.
|
|
|
|
|
|
|
|
Set variable to value, called internally only.
|
|
|
|
\param sec Section for variable.
|
|
|
|
\param var Variable to set.
|
|
|
|
\param val Value to set variable to.
|
|
|
|
**/
|
2002-11-21 05:40:49 +00:00
|
|
|
void SetVariable(string sec, string var, string val);
|
2002-12-04 23:06:45 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Internal function to get value of a variable.
|
|
|
|
|
|
|
|
Get value of variable, called internally only.
|
|
|
|
\param sec Section for variable.
|
|
|
|
\param var Variable to get.
|
|
|
|
\param defVal Value to return if variable doesnt exist.
|
|
|
|
\return Value of variable.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
string GetVariable(string sec, string var, string defVal) const;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Default constructor.
|
|
|
|
|
|
|
|
A no-op default constructor.
|
|
|
|
**/
|
|
|
|
ZConfigFile();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Constructor which takes filename.
|
|
|
|
|
|
|
|
Constructor takes filename, and calls process on it.
|
|
|
|
\param filename File to load as ZConfigFile.
|
|
|
|
**/
|
|
|
|
ZConfigFile(string filename);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Destructor, flushes file.
|
|
|
|
|
|
|
|
Flushes the file, ensures a flush if the file is left open.
|
|
|
|
**/
|
2003-02-10 04:40:16 +00:00
|
|
|
virtual ~ZConfigFile();
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Parse a file.
|
|
|
|
|
|
|
|
Parses the file, reading the contents into the fileLayout map.
|
|
|
|
\param filename File to parse and attach this ZDataFile to.
|
|
|
|
**/
|
|
|
|
void Process(string filename);
|
|
|
|
|
2003-02-10 03:19:37 +00:00
|
|
|
/*!
|
|
|
|
\brief Get value in floating point format from file.
|
|
|
|
|
|
|
|
Get the current value of a variable in the file, or defVal if not found in file.
|
|
|
|
\since 0.8.3
|
|
|
|
\param section Name of section to seek variable under.
|
|
|
|
\param var Name of variable to seek value for.
|
|
|
|
\param defVal Value to return if var does not exist within section.
|
|
|
|
\return Contents of the variable in floating point format.
|
|
|
|
**/
|
|
|
|
float GetFloat(string section, string var, float defVal) const;
|
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
/*!
|
|
|
|
\brief Get value in integer format from file.
|
|
|
|
|
|
|
|
Get the current value of a variable in the file, or defVal if not found in file.
|
|
|
|
\param section Name of section to seek variable under.
|
|
|
|
\param var Name of variable to seek value for.
|
|
|
|
\param defVal Value to return if var does not exist within section.
|
|
|
|
\return Contents of the variable in integer format.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
int GetInt(string section, string var, int defVal) const;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get value in boolean format from file.
|
|
|
|
|
|
|
|
Get the current value of a variable in the file, or defVal if not found in file.
|
|
|
|
(Valid values are "0","1","true" and "false")
|
|
|
|
\param section Name of section to seek variable under.
|
|
|
|
\param var Name of variable to seek value for.
|
|
|
|
\param defVal Value to return if var does not exist within section.
|
|
|
|
\return Contents of the variable in boolean format.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool GetBool(string section, string var, bool defVal) const;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get value in string format from file.
|
|
|
|
|
|
|
|
Get the current value of a variable in the file, or defVal if not found in file.
|
|
|
|
\param section Name of section to seek variable under.
|
|
|
|
\param var Name of variable to seek value for.
|
|
|
|
\param defVal Value to return if var does not exist within section.
|
|
|
|
\return Contents of the variable in string format.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
string GetString(string section, string var, string defVal) const;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2003-02-10 03:19:37 +00:00
|
|
|
/*!
|
|
|
|
\brief Set value in floating point format in file.
|
|
|
|
|
|
|
|
Set the new value of a variable in the file to val, creating the section and variable
|
|
|
|
if not already found in file.
|
|
|
|
\since 0.8.3
|
|
|
|
\param section Name of section to edit variable under.
|
|
|
|
\param var Name of variable to set value for.
|
|
|
|
\param val Floating point value to set variable to in file.
|
|
|
|
**/
|
|
|
|
void SetFloat(string section, string var, float val);
|
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
/*!
|
|
|
|
\brief Set value in integer format in file.
|
|
|
|
|
|
|
|
Set the new value of a variable in the file to val, creating the section and variable
|
|
|
|
if not already found in file.
|
|
|
|
\param section Name of section to edit variable under.
|
|
|
|
\param var Name of variable to set value for.
|
|
|
|
\param val Integer value to set variable to in file.
|
|
|
|
**/
|
|
|
|
void SetInt(string section, string var, int val);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set value in boolean format in file.
|
|
|
|
|
|
|
|
Set the new value of a variable in the file to val, creating the section and variable
|
|
|
|
if not already found in file.
|
|
|
|
\param section Name of section to edit variable under.
|
|
|
|
\param var Name of variable to set value for.
|
|
|
|
\param val Boolean value to set variable to in file.
|
|
|
|
**/
|
|
|
|
void SetBool(string section, string var, bool val);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set value in string format in file.
|
|
|
|
|
|
|
|
Set the new value of a variable in the file to val, creating the section and variable
|
|
|
|
if not already found in file.
|
|
|
|
\param section Name of section to edit variable under.
|
|
|
|
\param var Name of variable to set value for.
|
|
|
|
\param val String value to set variable to in file.
|
|
|
|
**/
|
|
|
|
void SetString(string section, string var, string val);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Write all values to file
|
|
|
|
|
|
|
|
Writes all values and sections to file.
|
|
|
|
**/
|
|
|
|
void Flush();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Close the file.
|
|
|
|
|
|
|
|
Flush the file and clear the filename.
|
|
|
|
**/
|
|
|
|
void Close();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //__ze_zconfigfile_h__
|