/** * Copyright Mikael Högdahl - triyana@users.sourceforge.net * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef MHCSVFile_h #define MHCSVFile_h #include "MH.h" #include "MHFileTransaction.h" /** * A csv file reader/writer object. */ class MHCSVFile : public MH { public: enum { MAX_COL = 100, MAX_ROW_LEN = 5000, }; static const char* OPEN_ERROR; static const char* RANGE_ERROR; static const char* READ_ERROR; static const char* WRITE_ERROR; MHCSVFile (); MHCSVFile (const char* fileName, char sep, int limit = 0); ~MHCSVFile (); const char* Class () {return "MHCSVFile";} int Cols () {return aCols;} static void Compress () {aaLzo = true;} char GetChar (int pos); double GetDouble (int pos); int GetInt (int pos); const char* GetRow () {if (aBufferPos < aBufferLen) return (const char*) aBuffer + aBufferPos; else return 0;} int GetRowPos () {return aRow;} const char* GetString (int pos); bool ReadRow (bool split = true); int Rows() {return aRows;} static void Uncompress () {aaLzo = false;} void WriteFile (const char* fileName); void WriteString (const char* string); private: enum FMODE { CLOSED = 0, READFILE, WRITEFILE, COMPRESS, }; FMODE aFMode; FILE* aFile; int aLimitSize; char aSep; char* aBuffer; int aRows; int aBufferLen; int aBufferPos; int aCols; int aColPos[MAX_COL]; int aRow; static bool aaLzo; void splitRows (); }; #endif