Joris Aerts / ConfigFile

Fork of ConfigFile by peter brier

Embed: (wiki syntax)

« Back to documentation index

ConfigFile Class Reference

ConfigFile Class Reference

Simple config file object Only supports reading config files. More...

#include <ConfigFile.h>

Public Member Functions

 ConfigFile (char *name)
 Make new ConfigFile object.
bool Value (char *key, char *value, size_t maxlen, char *def)
 Read value.
bool Value (char *key, int *value, int def)
 Read Integer value.
bool Value (char *key, float *value, float def)
 Read Float value.

Detailed Description

Simple config file object Only supports reading config files.

Tries to limit memory usage. Note: the file handle is kept open during the lifetime of this object. To close the file: destroy this ConfigFile object! A simple way is to enclose the creation of this object inside a code block Example:

 char ip[16];
 int port;
 {
   ConfigFile cfg("/local/config.txt");
   cfg.Value("ip", ip, sizeof(ip), "192.168.1.10");
   cfg.Value("port", &port, 80);
 }

Definition at line 63 of file ConfigFile.h.


Constructor & Destructor Documentation

ConfigFile ( char *  name )

Make new ConfigFile object.

Open config file. Note: the file handle is kept open during the lifetime of this object. To close the file: destroy this ConfigFile object!

Parameters:
fileFilename of the configuration file.

Definition at line 26 of file ConfigFile.cpp.


Member Function Documentation

bool Value ( char *  key,
char *  value,
size_t  maxlen,
char *  def 
)

Read value.

If file is not open, or key does not exist: copy default value (return false)

Parameters:
keyname of the key in the file
valuepointer to buffer that receives the value
maxlenthe maximum length of the value. If the actual value is longer, it is truncated
defDefault value. If the key is not found in the file, this value is copied.
Returns:
"true" if the key is found "false" is key is not found (default value is returned)

Definition at line 41 of file ConfigFile.cpp.

bool Value ( char *  key,
float *  value,
float  def 
)

Read Float value.

If file is not open, or key does not exist: copy default value (return false)

Parameters:
keyname of the key in the file
valuepointer to integer that receives the value
defDefault value. If the key is not found in the file, this value is copied.
Returns:
"true" if the key is found "false" is key is not found (default value is returned)

Definition at line 133 of file ConfigFile.cpp.

bool Value ( char *  key,
int *  value,
int  def 
)

Read Integer value.

If file is not open, or key does not exist: copy default value (return false)

Parameters:
keyname of the key in the file
valuepointer to integer that receives the value
defDefault value. If the key is not found in the file, this value is copied.
Returns:
"true" if the key is found "false" is key is not found (default value is returned)

Definition at line 119 of file ConfigFile.cpp.