File indexing completed on 2024-12-29 04:11:44
0001 /*************************************************************************** 0002 * * 0003 * Copyright : (C) 2012 Peter Kümmel * 0004 * email : syntheticpp@gmx.net * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #ifndef ASCII_FILE_BUFFER_H 0014 #define ASCII_FILE_BUFFER_H 0015 0016 #include "asciifiledata.h" 0017 0018 #include <QVector> 0019 #include <stdlib.h> 0020 0021 class AsciiFileBuffer 0022 { 0023 public: 0024 AsciiFileBuffer(); 0025 ~AsciiFileBuffer(); 0026 0027 typedef QVarLengthArray<qint64, AsciiFileData::Prealloc> RowIndex; 0028 0029 inline qint64 begin() const { return _begin; } 0030 inline qint64 bytesRead() const { return _bytesRead; } 0031 0032 void clear(); 0033 0034 void setFile(QFile* file); 0035 bool readWindow(QVector<AsciiFileData>& window) const; 0036 0037 void useOneWindowWithChunks(const RowIndex& rowIndex, qint64 start, qint64 bytesToRead, int numChunks); 0038 void useSlidingWindow(const RowIndex& rowIndex, qint64 start, qint64 bytesToRead, qint64 windowSize); 0039 void useSlidingWindowWithChunks(const RowIndex& rowIndex, qint64 start, qint64 bytesToRead, qint64 windowSize, int numWindowChunks); 0040 0041 QVector<QVector<AsciiFileData> >& fileData() { return _fileData; } 0042 0043 static bool openFile(QFile &file); 0044 0045 private: 0046 QFile* _file; 0047 QVector<QVector<AsciiFileData> > _fileData; 0048 0049 qint64 _begin; 0050 qint64 _bytesRead; 0051 0052 const QVector<AsciiFileData> splitFile(qint64 chunkSize, const RowIndex& rowIndex, qint64 start, qint64 bytesToRead) const; 0053 qint64 findRowOfPosition(const AsciiFileBuffer::RowIndex& rowIndex, qint64 searchStart, qint64 pos) const; 0054 void useSlidingWindowWithChunks(const RowIndex& rowIndex, qint64 start, qint64 bytesToRead, qint64 windowSize, int numWindowChunks, bool reread); 0055 0056 friend class AsciiSourceTest; 0057 }; 0058 0059 #endif 0060 // vim: ts=2 sw=2 et