.TH "FileReader" 3 "15 Dec 2005" "Version 1.0Betareleases" "InspIRCd" \" -*- nroff -*- .ad l .nh .SH NAME FileReader \- Caches a text file into memory and can be used to retrieve lines from it. .PP .SH SYNOPSIS .br .PP \fC#include \fP .PP Inherits \fBclassbase\fP. .PP .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBFileReader\fP ()" .br .RI "\fIDefault constructor. \fP" .ti -1c .RI "\fBFileReader\fP (\fBstd::string\fP filename)" .br .RI "\fISecondary constructor. \fP" .ti -1c .RI "\fB~FileReader\fP ()" .br .RI "\fIDefault destructor. \fP" .ti -1c .RI "void \fBLoadFile\fP (\fBstd::string\fP filename)" .br .RI "\fIUsed to load a file. \fP" .ti -1c .RI "bool \fBExists\fP ()" .br .RI "\fIReturns true if the file exists This function will return false if the file could not be opened. \fP" .ti -1c .RI "\fBstd::string\fP \fBGetLine\fP (int x)" .br .RI "\fIRetrieve one line from the file. \fP" .ti -1c .RI "int \fBFileSize\fP ()" .br .RI "\fIReturns the size of the file in lines. \fP" .in -1c .SS "Private Attributes" .in +1c .ti -1c .RI "\fBfile_cache\fP \fBfc\fP" .br .in -1c .SH "Detailed Description" .PP 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. .PP Definition at line 1621 of file modules.h. .SH "Constructor & Destructor Documentation" .PP .SS "FileReader::FileReader ()" .PP Default constructor. .PP This method does not load any file into memory, you must use the LoadFile method after constructing the class this way. .PP Definition at line 891 of file modules.cpp. .PP .nf 892 { 893 } .fi .PP .SS "FileReader::FileReader (\fBstd::string\fP filename)" .PP Secondary constructor. .PP 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, \fBFileReader::FileSize\fP returns 0. .PP Definition at line 884 of file modules.cpp. .PP References fc, and readfile(). .PP .nf 885 { 886 file_cache c; 887 readfile(c,filename.c_str()); 888 this->fc = c; 889 } .fi .PP .SS "FileReader::~FileReader ()" .PP Default destructor. .PP This deletes the memory allocated to the file. .PP Definition at line 903 of file modules.cpp. .PP .nf 904 { 905 } .fi .PP .SH "Member Function Documentation" .PP .SS "bool FileReader::Exists ()" .PP Returns true if the file exists This function will return false if the file could not be opened. .PP Definition at line 907 of file modules.cpp. .PP References fc. .PP .nf 908 { 909 if (fc.size() == 0) 910 { 911 return(false); 912 } 913 else 914 { 915 return(true); 916 } 917 } .fi .PP .SS "int FileReader::FileSize ()" .PP Returns the size of the file in lines. .PP 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. .PP Definition at line 926 of file modules.cpp. .PP References fc. .PP .nf 927 { 928 return fc.size(); 929 } .fi .PP .SS "\fBstd::string\fP FileReader::GetLine (int x)" .PP Retrieve one line from the file. .PP 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. .PP Definition at line 919 of file modules.cpp. .PP References fc. .PP .nf 920 { 921 if ((x<0) || ((unsigned)x>fc.size())) 922 return ''; 923 return fc[x]; 924 } .fi .PP .SS "void FileReader::LoadFile (\fBstd::string\fP filename)" .PP Used to load a file. .PP 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, \fBFileReader::FileSize\fP returns 0. .PP Definition at line 895 of file modules.cpp. .PP References fc, and readfile(). .PP .nf 896 { 897 file_cache c; 898 readfile(c,filename.c_str()); 899 this->fc = c; 900 } .fi .PP .SH "Member Data Documentation" .PP .SS "\fBfile_cache\fP \fBFileReader::fc\fP\fC [private]\fP" .PP Definition at line 1623 of file modules.h. .PP Referenced by Exists(), FileReader(), FileSize(), GetLine(), and LoadFile(). .SH "Author" .PP Generated automatically by Doxygen for InspIRCd from the source code.