|
ConfigFile Class Reference#include <configfile.h>
List of all members.
Detailed Description
Class for loading configuration file information.
This class is used to load settings from a configuration text file. Ths file is dividing into sections, with section having a set of key/value fields. Example file format is as follows:
# This is a comment
section_name
(
key1 0
key2 "foo"
key3 ["foo" "bar"]
)
|
Public Member Functions |
| | ConfigFile () |
| | Standard constructor.
|
| | ~ConfigFile () |
| | Standard destructor.
|
| bool | Load (const char *filename) |
| | Load config from file.
|
| bool | WarnUnused () |
| | Check for unused fields and print warnings.
|
| const char * | ReadString (int section, const char *name, const char *value) |
| | Read a string value.
|
| int | ReadInt (int section, const char *name, int value) |
| | Read an integer value.
|
| double | ReadFloat (int section, const char *name, double value) |
| | Read a floating point (double) value.
|
| double | ReadLength (int section, const char *name, double value) |
| | Read a length (includes unit conversion, if any).
|
| double | ReadAngle (int section, const char *name, double value) |
| | Read an angle (includes unit conversion).
|
| uint32_t | ReadColor (int section, const char *name, uint32_t value) |
| | Read a color (includes text to RGB conversion).
|
| const char * | ReadFilename (int section, const char *name, const char *value) |
| | Read a filename.
|
| int | GetTupleCount (int section, const char *name) |
| | Get the number of values in a tuple.
|
| const char * | ReadTupleString (int section, const char *name, int index, const char *value) |
| | Read a string from a tuple field.
|
| int | ReadTupleInt (int section, const char *name, int index, int value) |
| | Read an integer from a tuple field.
|
| double | ReadTupleFloat (int section, const char *name, int index, double value) |
| | Read a float (double) from a tuple field.
|
| double | ReadTupleLength (int section, const char *name, int index, double value) |
| | Read a length from a tuple (includes units conversion).
|
| double | ReadTupleAngle (int section, const char *name, int index, double value) |
| | Read an angle form a tuple (includes units conversion).
|
| uint32_t | ReadTupleColor (int section, const char *name, int index, uint32_t value) |
| | Read a color (includes text to RGB conversion).
|
| int | ReadDeviceId (player_device_id_t *id, int section, const char *name, int code, int index, const char *key) |
| | Read a device id.
|
| int | GetSectionCount () |
| | Get the number of sections.
|
| const char * | GetSectionType (int section) |
| | Get a section type name.
|
| int | LookupSection (const char *type) |
| | Lookup a section number by section type name.
|
| int | GetSectionParent (int section) |
| | Get a section's parent section.
|
| void | DumpTokens () |
| | Dump the token list (for debugging).
|
| void | DumpSections () |
| | Dump the section list for debugging.
|
| void | DumpFields () |
| | Dump the field list for debugging.
|
Public Attributes |
| char * | filename |
| | Name of the file we loaded.
|
Constructor & Destructor Documentation
| ConfigFile::ConfigFile |
( |
|
) |
|
|
Member Function Documentation
| bool ConfigFile::Load |
( |
const char * |
filename |
) |
|
|
|
|
Load config from file.
- Parameters:
-
| filename | Name of file; can be relative or fully qualified path. |
- Returns:
- Returns true on success.
|
| bool ConfigFile::WarnUnused |
( |
|
) |
|
|
|
|
Check for unused fields and print warnings.
- Returns:
- Returns true if there are unused fields.
|
| const char* ConfigFile::ReadString |
( |
int |
section, |
|
|
const char * |
name, |
|
|
const char * |
value |
|
) |
|
|
|
|
Read a string value.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the field value.
|
| int ConfigFile::ReadInt |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
value |
|
) |
|
|
|
|
Read an integer value.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the field value.
|
| double ConfigFile::ReadFloat |
( |
int |
section, |
|
|
const char * |
name, |
|
|
double |
value |
|
) |
|
|
|
|
Read a floating point (double) value.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the field value.
|
| double ConfigFile::ReadLength |
( |
int |
section, |
|
|
const char * |
name, |
|
|
double |
value |
|
) |
|
|
|
|
Read a length (includes unit conversion, if any).
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the field value.
|
| double ConfigFile::ReadAngle |
( |
int |
section, |
|
|
const char * |
name, |
|
|
double |
value |
|
) |
|
|
|
|
Read an angle (includes unit conversion).
In the configuration file, angles are specified in degrees; this method will convert them to radians.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file (radians). |
- Returns:
- Returns the field value.
|
| uint32_t ConfigFile::ReadColor |
( |
int |
section, |
|
|
const char * |
name, |
|
|
uint32_t |
value |
|
) |
|
|
|
|
Read a color (includes text to RGB conversion).
In the configuration file colors may be specified with sybolic names; e.g., "blue" and "red". This function will convert them to an RGB value using the X11 rgb.txt file.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file (RGB). |
- Returns:
- Returns the field value.
|
| const char* ConfigFile::ReadFilename |
( |
int |
section, |
|
|
const char * |
name, |
|
|
const char * |
value |
|
) |
|
|
|
|
Read a filename.
Always returns an absolute path. If the filename is entered as a relative path, we prepend the config file's path to it.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the field value.
|
| int ConfigFile::GetTupleCount |
( |
int |
section, |
|
|
const char * |
name |
|
) |
|
|
|
|
Get the number of values in a tuple.
- Parameters:
-
| section | Section to read. |
| name | Field name. |
|
| const char* ConfigFile::ReadTupleString |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
const char * |
value |
|
) |
|
|
|
|
Read a string from a tuple field.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the tuple element value.
|
| int ConfigFile::ReadTupleInt |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
int |
value |
|
) |
|
|
|
|
Read an integer from a tuple field.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the tuple element value.
|
| double ConfigFile::ReadTupleFloat |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
double |
value |
|
) |
|
|
|
|
Read a float (double) from a tuple field.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the tuple element value.
|
| double ConfigFile::ReadTupleLength |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
double |
value |
|
) |
|
|
|
|
Read a length from a tuple (includes units conversion).
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the tuple element value.
|
| double ConfigFile::ReadTupleAngle |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
double |
value |
|
) |
|
|
|
|
Read an angle form a tuple (includes units conversion).
In the configuration file, angles are specified in degrees; this method will convert them to radians.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file. |
- Returns:
- Returns the tuple element value.
|
| uint32_t ConfigFile::ReadTupleColor |
( |
int |
section, |
|
|
const char * |
name, |
|
|
int |
index, |
|
|
uint32_t |
value |
|
) |
|
|
|
|
Read a color (includes text to RGB conversion).
In the configuration file colors may be specified with sybolic names; e.g., "blue" and "red". This function will convert them to an RGB value using the X11 rgb.txt file.
- Parameters:
-
| section | Section to read. |
| name | Field name |
| index | Tuple index (zero-based) |
| value | Default value if the field is not present in the file (RGB). |
- Returns:
- Returns the field value.
|
| int ConfigFile::ReadDeviceId |
( |
player_device_id_t * |
id, |
|
|
int |
section, |
|
|
const char * |
name, |
|
|
int |
code, |
|
|
int |
index, |
|
|
const char * |
key |
|
) |
|
|
|
|
Read a device id.
- Parameters:
-
| id | ID field to be filled in. |
| section | File section. |
| name | Field name. |
| code | Interface type code (use 0 to match all interface types). |
| index | Tuple index (use -1 to match all indices). |
| key | Device key value (use NULL to match all key vales). |
- Returns:
- Non-zero on error.
|
| int ConfigFile::GetSectionCount |
( |
|
) |
|
|
|
|
Get the number of sections.
|
| const char* ConfigFile::GetSectionType |
( |
int |
section |
) |
|
|
| int ConfigFile::LookupSection |
( |
const char * |
type |
) |
|
|
|
|
Lookup a section number by section type name.
- Returns:
- Returns -1 if there is no section with this type.
|
| int ConfigFile::GetSectionParent |
( |
int |
section |
) |
|
|
|
|
Get a section's parent section.
- Returns:
- Returns -1 if there is no parent.
|
| void ConfigFile::DumpTokens |
( |
|
) |
|
|
|
|
Dump the token list (for debugging).
|
| void ConfigFile::DumpSections |
( |
|
) |
|
|
|
|
Dump the section list for debugging.
|
| void ConfigFile::DumpFields |
( |
|
) |
|
|
|
|
Dump the field list for debugging.
|
Member Data Documentation
|
|
Name of the file we loaded.
|
The documentation for this class was generated from the following file:
Generated on Tue May 3 14:15:49 2005 for Player by 1.3.6
|