|
|||
|
|||
|
#include <modules.h>
Inheritance diagram for FileReader:


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 | |
| InspIRCd * | ServerInstance |
| file_cache | fc |
| The file contents. | |
| unsigned long | contentsize |
| Content size in bytes. | |
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 1574 of file modules.h.
|
|
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 673 of file modules.cpp. 00673 : ServerInstance(Instance) 00674 { 00675 }
|
|
||||||||||||
|
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 668 of file modules.cpp. References LoadFile(). 00668 : ServerInstance(Instance) 00669 { 00670 LoadFile(filename); 00671 }
|
|
|
Default destructor. This deletes the memory allocated to the file. Definition at line 713 of file modules.cpp.
|
|
|
Calculate content size in bytes.
Definition at line 693 of file modules.cpp. References contentsize, and fc. Referenced by LoadFile(). 00694 { 00695 unsigned long n = 0; 00696 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++) 00697 n += (a->length() + 2); 00698 this->contentsize = n; 00699 }
|
|
|
Returns the whole content of the file as std::string.
Definition at line 677 of file modules.cpp. References fc. Referenced by HttpServerSocket::ServeData(). 00678 { 00679 std::string x; 00680 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++) 00681 { 00682 x.append(*a); 00683 x.append("\r\n"); 00684 } 00685 return x; 00686 }
|
|
|
Returns the entire size of the file as std::string.
Definition at line 688 of file modules.cpp. References contentsize. Referenced by HttpServerSocket::ServeData(). 00689 { 00690 return this->contentsize; 00691 }
|
|
|
Returns true if the file exists This function will return false if the file could not be opened.
Definition at line 717 of file modules.cpp. References fc. Referenced by cmd_randquote::Handle(), ModuleRandQuote::ModuleRandQuote(), and ModuleHttpServer::ReadConfig(). 00718 { 00719 return (!(fc.size() == 0)); 00720 }
|
|
|
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 729 of file modules.cpp. References fc. Referenced by cmd_randquote::Handle(), and ShowOperMOTD(). 00730 { 00731 return fc.size(); 00732 }
|
|
|
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 722 of file modules.cpp. References fc. Referenced by cmd_randquote::Handle(), and ShowOperMOTD().
|
|
|
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 701 of file modules.cpp. References CalcSize(), InspIRCd::Config, fc, ServerConfig::ReadFile(), and ServerInstance. Referenced by FileReader(). 00702 { 00703 file_cache c; 00704 c.clear(); 00705 if (ServerInstance->Config->ReadFile(c,filename.c_str())) 00706 { 00707 this->fc = c; 00708 this->CalcSize(); 00709 } 00710 }
|
|
|
Content size in bytes.
Definition at line 1583 of file modules.h. Referenced by CalcSize(), and ContentSize(). |
|
|
The file contents.
Definition at line 1579 of file modules.h. Referenced by CalcSize(), Contents(), Exists(), FileSize(), GetLine(), and LoadFile(). |
|
|
Definition at line 1576 of file modules.h. Referenced by LoadFile(). |