VHISTlib
1.84.0.3018
|
00001 00002 /* $HEADERS 00003 $Id: fileiterator.h 2791 2013-05-06 11:24:28Z michael $ 00004 */ 00005 00006 #ifndef FILEITERATOR_INCLUDED 00007 #define FILEITERATOR_INCLUDED 00008 00009 #include "../shared/misc_defines.h" 00010 00011 #include <QString> 00012 #include <QByteArray> 00013 #include <QList> 00014 #include <QSharedPointer> 00015 #include <QFileInfo> 00016 00017 00018 //#include "../shared/maybe.tpl" 00019 00020 class QFile; 00021 00022 namespace vhist 00023 { 00024 00025 typedef QList<QByteArray> QByteArrays; 00026 typedef QSharedPointer<QString> MaybeString; 00027 typedef QSharedPointer<QByteArray> MaybeArray; 00028 00036 class VHIST_EXTERN FileIterator 00037 { 00038 public: // construction, destruction and assignment 00039 FileIterator(); 00040 ~FileIterator(); 00041 00042 public: 00043 bool open(const QString& filename); 00044 bool nextLine(); 00045 bool prevLine(); 00046 bool firstLine(); 00047 bool lastLine(); 00048 00049 bool reachedStart(); 00050 bool reachedEnd(); 00051 bool onLine(); 00052 bool empty(); 00053 bool gotoPos(int pos); 00054 00055 MaybeArray curLine(); 00056 MaybeString curLineAsString(); 00057 int curPos(); 00058 QByteArray getBytes(int startPos, int numBytes); 00059 00060 public: 00061 bool curLineStartsWithBytes(const char* str); 00062 00063 private: 00064 bool containsNulls(const QByteArray& line); 00065 void closeFile(); 00066 int getFileSize(); 00067 00068 bool getFirstBuffer(); 00069 bool getLastBuffer(); 00070 bool getNextBuffer(); 00071 bool getPrevBuffer(); 00072 bool getBuffer(int pos); 00073 00074 bool searchForwards(); 00075 bool searchBackwards(); 00076 00077 private: 00078 QFile* m_file; 00079 QFileInfo m_finfo; 00080 QByteArray m_buffer; 00081 QByteArray m_curLine; 00082 int m_startOfLine; 00083 int m_bufferStart; 00084 int m_posInBuffer; 00085 }; 00086 00087 00088 } // namespace 00089 00090 00091 #endif // FILEITERATOR_INCLUDED 00092