InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
Public Member Functions | Protected Attributes | List of all members
ConfigReader Class Reference

#include <modules.h>

Inheritance diagram for ConfigReader:
interfacebase

Public Member Functions

 ConfigReader ()
 
 ~ConfigReader ()
 
std::string ReadValue (const std::string &tag, const std::string &name, int index, bool allow_linefeeds=false)
 
std::string ReadValue (const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds=false)
 
bool ReadFlag (const std::string &tag, const std::string &name, int index)
 
bool ReadFlag (const std::string &tag, const std::string &name, const std::string &default_value, int index)
 
int ReadInteger (const std::string &tag, const std::string &name, int index, bool need_positive)
 
int ReadInteger (const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
 
long GetError ()
 
int Enumerate (const std::string &tag)
 

Protected Attributes

long error
 

Additional Inherited Members

- Static Public Member Functions inherited from interfacebase
static void * operator new (size_t, void *m)
 

Detailed Description

Allows reading of values from configuration files This class allows a module to read from either the main configuration file (inspircd.conf) or from a module-specified configuration file. It may either be instantiated with one parameter or none. Constructing the class using one parameter allows you to specify a path to your own configuration file, otherwise, inspircd.conf is read.

Constructor & Destructor Documentation

ConfigReader::ConfigReader ( )

Default constructor. This constructor initialises the ConfigReader class to read the inspircd.conf file as specified when running ./configure.

ConfigReader::~ConfigReader ( )

Default destructor. This method destroys the ConfigReader class.

Member Function Documentation

int ConfigReader::Enumerate ( const std::string &  tag)

Counts the number of times a given tag appears in the config file. This method counts the number of times a tag appears in a config file, for use where there are several tags of the same kind, e.g. with opers and connect types. It can be used with the index value of ConfigReader::ReadValue to loop through all copies of a multiple instance tag.

long ConfigReader::GetError ( )

Returns the last error to occur. Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. A call to GetError() resets the error flag back to 0.

bool ConfigReader::ReadFlag ( const std::string &  tag,
const std::string &  name,
int  index 
)

Retrieves a boolean value from the config file. This method retrieves a boolean value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" and "true" in the config file count as true to ReadFlag, and any other value counts as false.

bool ConfigReader::ReadFlag ( const std::string &  tag,
const std::string &  name,
const std::string &  default_value,
int  index 
)

Retrieves a boolean value from the config file. This method retrieves a boolean value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" and "true" in the config file count as true to ReadFlag, and any other value counts as false. If the tag is not found, the default value is used instead.

int ConfigReader::ReadInteger ( const std::string &  tag,
const std::string &  name,
int  index,
bool  need_positive 
)

Retrieves an integer value from the config file. This method retrieves an integer value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. Any invalid integer values in the tag will cause the objects error value to be set, and any call to GetError() will return CONF_INVALID_NUMBER to be returned. need_positive is set if the number must be non-negative. If a negative number is placed into a tag which is specified positive, 0 will be returned and GetError() will return CONF_INT_NEGATIVE. Note that need_positive is not suitable to get an unsigned int - you should cast the result to achieve that effect.

int ConfigReader::ReadInteger ( const std::string &  tag,
const std::string &  name,
const std::string &  default_value,
int  index,
bool  need_positive 
)

Retrieves an integer value from the config file. This method retrieves an integer value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. Any invalid integer values in the tag will cause the objects error value to be set, and any call to GetError() will return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned. If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead.

std::string ConfigReader::ReadValue ( const std::string &  tag,
const std::string &  name,
int  index,
bool  allow_linefeeds = false 
)

Retrieves a value from the config file. This method retrieves a value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve.

std::string ConfigReader::ReadValue ( const std::string &  tag,
const std::string &  name,
const std::string &  default_value,
int  index,
bool  allow_linefeeds = false 
)

Retrieves a value from the config file. This method retrieves a value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. If the tag is not found the default value is returned instead.

Member Data Documentation

long ConfigReader::error
protected

Error code


The documentation for this class was generated from the following files: