diff options
Diffstat (limited to 'include/modules.h')
-rw-r--r-- | include/modules.h | 70 |
1 files changed, 18 insertions, 52 deletions
diff --git a/include/modules.h b/include/modules.h index 176bdda34..89961a6f5 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1281,76 +1281,42 @@ class CoreExport Module : public classbase, public usecountbase virtual void OnSetUserIP(LocalUser* user); }; -/** 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. - */ +/** Provides an easy method of reading a text file into memory. */ class CoreExport FileReader : public classbase { - /** The file contents + /** The lines of text in the file. */ - std::vector<std::string> fc; + std::vector<std::string> lines; /** Content size in bytes */ - unsigned long contentsize; - - /** Calculate content size in bytes - */ - void CalcSize(); + unsigned long totalSize; public: - /** Default constructor. - * This method does not load any file into memory, you must use the LoadFile method - * after constructing the class this way. - */ - FileReader(); - - /** 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. + /** Initializes a new file reader. */ - FileReader(const std::string &filename); + FileReader() : totalSize(0) { } - /** Default destructor. - * This deletes the memory allocated to the file. - */ - ~FileReader(); - - /** 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. + /** Initializes a new file reader and reads the specified file. + * @param file The file to read into memory. */ - void LoadFile(const std::string &filename); + FileReader(const std::string& filename); - /** Returns the whole content of the file as std::string + /** Loads a text file from disk. + * @param filename The file to read into memory. + * @throw CoreException The file can not be loaded. */ - std::string Contents(); + void Load(const std::string& filename); - /** Returns the entire size of the file as std::string + /** Retrieves the entire contents of the file cache as a single string. */ - unsigned long ContentSize(); + std::string GetString(); - /** Returns true if the file exists - * This function will return false if the file could not be opened. + /** Retrieves the entire contents of the file cache as a vector of strings. */ - bool Exists(); + const std::vector<std::string>& GetVector() { return lines; } - /** 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. - */ - std::string GetLine(int x); - - /** 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. - */ - int FileSize(); + unsigned long TotalSize() { return totalSize; } }; /** A list of modules |