Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound 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>

Inherits classbase.

List of all members.

Public Member Functions

 FileReader ()
 Default constructor.

 FileReader (std::string filename)
 Secondary constructor.

 ~FileReader ()
 Default destructor.

void LoadFile (std::string filename)
 Used to load a file.

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 Attributes

file_cache fc


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 879 of file modules.h.


Constructor & Destructor Documentation

FileReader::FileReader  ) 
 

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 828 of file modules.cpp.

00829 {
00830 }

FileReader::FileReader 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 821 of file modules.cpp.

References fc, and file_cache.

00822 {
00823         file_cache c;
00824         readfile(c,filename.c_str());
00825         this->fc = c;
00826 }

FileReader::~FileReader  ) 
 

Default destructor.

This deletes the memory allocated to the file.

Definition at line 840 of file modules.cpp.

00841 {
00842 }


Member Function Documentation

bool FileReader::Exists  ) 
 

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

Definition at line 844 of file modules.cpp.

References fc.

00845 {
00846         if (fc.size() == 0)
00847         {
00848                 return(false);
00849         }
00850         else
00851         {
00852                 return(true);
00853         }
00854 }

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 863 of file modules.cpp.

References fc.

00864 {
00865         return fc.size();
00866 }

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 856 of file modules.cpp.

References fc.

00857 {
00858         if ((x<0) || (x>fc.size()))
00859                 return "";
00860         return fc[x];
00861 }

void FileReader::LoadFile 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 832 of file modules.cpp.

References fc, and file_cache.

00833 {
00834         file_cache c;
00835         readfile(c,filename.c_str());
00836         this->fc = c;
00837 }


Member Data Documentation

file_cache FileReader::fc [private]
 

Definition at line 881 of file modules.h.

Referenced by Exists(), FileReader(), FileSize(), GetLine(), and LoadFile().


The documentation for this class was generated from the following files:
Generated on Wed Apr 13 13:07:04 2005 for InspIRCd by doxygen 1.3.3