////////////////////////////////////////////////////////////////////// /// (C)opyright 2004 /// /// Institute of Computer Science V /// Prof. Männer /// University of Mannheim, Germany /// /// ******************************************************************* /// /// Designer(s): Steinle / Gläß /// /// ******************************************************************* /// /// Project: Trackfinder for CBM-Project at GSI-Darmstadt, Germany /// /// ******************************************************************* /// /// Description: /// /// class: /// - base class for read and write access to the hdd /// /// ******************************************************************* /// /// $Author: csteinle $ /// $Date: 2007-05-29 15:11:35 $ /// $Revision: 1.3 $ /// ////////////////////////////////////////////////////////////////////// #ifndef _FILEIO_H #define _FILEIO_H #include #include /** * Defines the escape sequences which the file is scanned for */ #define fileCmdSeparator ":=" #define fileCommentSeparator "/*" #define fileDisableCmdSeparator "#" #define fileLineDelimiter (char)(10) // Linefeed #define fileLineRemover (char)(13) // Carriage Return /* ************************************************************** * CLASS fileio * * **************************************************************/ class fileio { private: std::string fileName; /**< Variable stores the name of the file to access */ /** * This method skips whitespaces in a std::string object by * modifying the given iterator. * @param buffer is the string to skip the whitespaces * @param iterator is the beginning of the text to scan for whitespaces * @param itRangeMin is the minimal position of the iterator to scan * @param itRangeMax is the maximal position of the iterator to scan * @param forward enables the scanning in iterator++ direction. Else * the scanning is done in iterator-- direction * @return iterator */ void skipWhitespaces(std::string& buffer, std::string::size_type* iterator, std::string::size_type itRangeMin, std::string::size_type itRangeMax, bool forward); /** * This method returns a legalized comment character. */ char legalizedCommentChar(char value); protected: /** * This method is to read the header of the file. */ void readFileHeader(std::ifstream& fileStream); /** * This methods write the value and the corresponding parameter * which is identified by a specifier to an ofstream. * @param fileStream is a stream to the file * @param specifier is the text which identifies the parameter * @param value is the value of the parameter */ void setHeaderValue(std::ofstream& fileStream, char* specifier, bool value); void setHeaderValue(std::ofstream& fileStream, char* specifier, char* value); void setHeaderValue(std::ofstream& fileStream, char* specifier, const char* value); void setHeaderValue(std::ofstream& fileStream, char* specifier, int value, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, unsigned int value, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, long value, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, unsigned long value, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, float value); void setHeaderValue(std::ofstream& fileStream, char* specifier, double value); void setHeaderValue(std::ofstream& fileStream, char* specifier, std::string& value); void setHeaderValue(std::ofstream& fileStream, char* specifier, bool value, char* comment); void setHeaderValue(std::ofstream& fileStream, char* specifier, char* value, char* comment); void setHeaderValue(std::ofstream& fileStream, char* specifier, const char* value, char* comment); void setHeaderValue(std::ofstream& fileStream, char* specifier, int value, char* comment, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, unsigned int value, char* comment, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, long value, char* comment, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, unsigned long value, char* comment, int radix = 10); void setHeaderValue(std::ofstream& fileStream, char* specifier, float value, char* comment); void setHeaderValue(std::ofstream& fileStream, char* specifier, double value, char* comment); void setHeaderValue(std::ofstream& fileStream, char* specifier, std::string& value, char* comment); /** * This methods writes a comment to an ofstream. */ void writeComment(std::ofstream& fileStream, std::string& comment); void writeComment(std::ofstream& fileStream, char* comment); /** * This method returns the number of accepted commands. */ virtual int getNumberOfCmds() = 0; /** * This method assigns the value to the corresponding parameter * which is identified by a specifier. */ virtual bool getHeaderValue(std::string& specifier, std::string& value) = 0; /** * This method is to write the header of the file. */ virtual void writeFileHeader(std::ofstream& fileStream) = 0; /** * This method is to set the default values for each header * parameter. */ virtual void setHeaderDefValues() = 0; public: /** * Default constructor */ fileio(); /** * Constructor * @param name is the name of the file to access */ fileio(std::string name); fileio(char* name); /** * Destructor */ virtual ~fileio(); /** * This method initializes the object. * @param name is the name of the file to access */ void init(std::string name); void init(char* name); /** * This method returns the name of the file. */ std::string getFileName(); /** * This method sets the name of the file. */ void setFileName(std::string name); void setFileName(char* name); /** * This method returns an information string about the object. * */ virtual std::string getInfo() = 0; /** * This method reads the file. */ virtual void readFile() = 0; /** * This method writes the file. */ virtual void writeFile() = 0; }; #endif