The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

FileReader Class Reference

Caches a text file into memory and can be used to retrieve lines from it. More...

#include <modules.h>

Inheritance diagram for FileReader:

Inheritance graph
[legend]
Collaboration diagram for FileReader:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FileReader (InspIRCd *Instance)
 Default constructor.
 FileReader (InspIRCd *Instance, const std::string &filename)
 Secondary constructor.
 ~FileReader ()
 Default destructor.
void LoadFile (const std::string &filename)
 Used to load a file.
std::string Contents ()
 Returns the whole content of the file as std::string.
unsigned long ContentSize ()
 Returns the entire size of the file as std::string.
bool Exists ()
 Returns true if the file exists This function will return false if the file could not be opened.
std::string GetLine (int x)
 Retrieve one line from the file.
int FileSize ()
 Returns the size of the file in lines.

Private Member Functions

void CalcSize ()
 Calculate content size in bytes.

Private Attributes

InspIRCdServerInstance
file_cache fc
 The file contents.
unsigned long contentsize
 Content size in bytes.

Detailed Description

Caches a text file into memory and can be used to retrieve lines from it.

This class contains methods for read-only manipulation of a text file in memory. Either use the constructor type with one parameter to load a file into memory at construction, or use the LoadFile method to load a file.

Definition at line 1534 of file modules.h.


Constructor & Destructor Documentation

FileReader::FileReader InspIRCd Instance  ) 
 

Default constructor.

This method does not load any file into memory, you must use the LoadFile method after constructing the class this way.

Definition at line 931 of file modules.cpp.

FileReader::FileReader InspIRCd Instance,
const std::string filename
 

Secondary constructor.

This method initialises the class with a file loaded into it ready for GetLine and and other methods to be called. If the file could not be loaded, FileReader::FileSize returns 0.

Definition at line 926 of file modules.cpp.

References LoadFile().

FileReader::~FileReader  ) 
 

Default destructor.

This deletes the memory allocated to the file.

Definition at line 971 of file modules.cpp.


Member Function Documentation

void FileReader::CalcSize  )  [private]
 

Calculate content size in bytes.

Definition at line 951 of file modules.cpp.

References contentsize, and fc.

Referenced by LoadFile().

std::string FileReader::Contents  ) 
 

Returns the whole content of the file as std::string.

Definition at line 935 of file modules.cpp.

References fc.

Referenced by HttpServerSocket::ServeData().

unsigned long FileReader::ContentSize  ) 
 

Returns the entire size of the file as std::string.

Definition at line 946 of file modules.cpp.

References contentsize.

Referenced by HttpServerSocket::ServeData().

bool FileReader::Exists  ) 
 

Returns true if the file exists This function will return false if the file could not be opened.

Definition at line 975 of file modules.cpp.

References fc.

Referenced by CommandRandquote::Handle(), ModuleRandQuote::ModuleRandQuote(), and ModuleHttpServer::ReadConfig().

int FileReader::FileSize  ) 
 

Returns the size of the file in lines.

This method returns the number of lines in the read file. If it is 0, no lines have been read into memory, either because the file is empty or it does not exist, or cannot be opened due to permission problems.

Definition at line 987 of file modules.cpp.

References fc.

Referenced by CommandRandquote::Handle(), and ShowOperMOTD().

std::string FileReader::GetLine int  x  ) 
 

Retrieve one line from the file.

This method retrieves one line from the text file. If an empty non-NULL string is returned, the index was out of bounds, or the line had no data on it.

Definition at line 980 of file modules.cpp.

References fc.

Referenced by CommandRandquote::Handle(), and ShowOperMOTD().

void FileReader::LoadFile const std::string filename  ) 
 

Used to load a file.

This method loads a file into the class ready for GetLine and and other methods to be called. If the file could not be loaded, FileReader::FileSize returns 0.

Definition at line 959 of file modules.cpp.

References CalcSize(), InspIRCd::Config, fc, ServerConfig::ReadFile(), and ServerInstance.

Referenced by FileReader().


Member Data Documentation

unsigned long FileReader::contentsize [private]
 

Content size in bytes.

Definition at line 1543 of file modules.h.

Referenced by CalcSize(), and ContentSize().

file_cache FileReader::fc [private]
 

The file contents.

Definition at line 1539 of file modules.h.

Referenced by CalcSize(), Contents(), Exists(), FileSize(), GetLine(), and LoadFile().

InspIRCd* FileReader::ServerInstance [private]
 

Definition at line 1536 of file modules.h.

Referenced by LoadFile().


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