Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ConfigReader Class Reference

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. More...

#include <modules.h>

Inheritance diagram for ConfigReader:

Inheritance graph
[legend]
Collaboration diagram for ConfigReader:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ConfigReader ()
 Default constructor.

 ConfigReader (std::string filename)
 Overloaded constructor.

 ~ConfigReader ()
 Default destructor.

std::string ReadValue (std::string tag, std::string name, int index)
 Retrieves a value from the config file.

int Enumerate (std::string tag)
 Counts the number of times a given tag appears in the config file.

bool Verify ()
 Returns true if a config file is valid.

int EnumerateValues (std::string tag, int index)
 Returns the number of items within a tag.


Protected Attributes

std::stringstream * cache
 The contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).

bool error
 Used to store errors.


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.

Definition at line 497 of file modules.h.


Constructor & Destructor Documentation

ConfigReader::ConfigReader  
 

Default constructor.

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

Definition at line 336 of file modules.cpp.

References cache, and error.

00337 {
00338         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
00339         this->error = LoadConf(CONFIG_FILE,this->cache);
00340 }

ConfigReader::ConfigReader std::string    filename
 

Overloaded constructor.

This constructor initialises the ConfigReader class to read a user-specified config file

Definition at line 350 of file modules.cpp.

References cache, and error.

00351 {
00352         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
00353         this->error = LoadConf(filename.c_str(),this->cache);
00354 };

ConfigReader::~ConfigReader  
 

Default destructor.

This method destroys the ConfigReader class.

Definition at line 343 of file modules.cpp.

References cache.

00344 {
00345         if (this->cache)
00346                 delete this->cache;
00347 }


Member Function Documentation

int ConfigReader::Enumerate 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.

Definition at line 364 of file modules.cpp.

00365 {
00366         return EnumConf(cache,tag.c_str());
00367 }

int ConfigReader::EnumerateValues std::string    tag,
int    index
 

Returns the number of items within a tag.

For example if the tag was <test tag="blah" data="foo"> then this function would return 2. Spaces and newlines both qualify as valid seperators between values.

Definition at line 369 of file modules.cpp.

00370 {
00371         return EnumValues(cache, tag.c_str(), index);
00372 }

std::string ConfigReader::ReadValue std::string    tag,
std::string    name,
int    index
 

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.

Definition at line 356 of file modules.cpp.

00357 {
00358         char val[MAXBUF];
00359         ReadConf(cache,tag.c_str(),name.c_str(),index,val);
00360         return val;
00361 }

bool ConfigReader::Verify  
 

Returns true if a config file is valid.

This method is partially implemented and will only return false if the config file does not exist or could not be opened.

Definition at line 374 of file modules.cpp.

References error.

00375 {
00376         return this->error;
00377 }


Member Data Documentation

std::stringstream* ConfigReader::cache [protected]
 

The contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).

It will contain a pointer to the configuration file data with unneeded data (such as comments) stripped from it.

Definition at line 505 of file modules.h.

Referenced by ConfigReader(), and ~ConfigReader().

bool ConfigReader::error [protected]
 

Used to store errors.

Definition at line 508 of file modules.h.

Referenced by ConfigReader(), and Verify().


The documentation for this class was generated from the following files:
Generated on Mon Apr 19 02:34:42 2004 for InspIRCd by doxygen1.3-rc3