File indexing completed on 2024-12-29 04:11:44
0001 /*************************************************************************** 0002 * * 0003 * Copyright : (C) 2003 The University of Toronto * 0004 * email : netterfield@astro.utoronto.ca * 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_DATA_READER_H 0014 #define ASCII_DATA_READER_H 0015 0016 #include "asciifilebuffer.h" 0017 #include "asciicharactertraits.h" 0018 0019 #include <QVarLengthArray> 0020 #include <QMutex> 0021 0022 class QFile; 0023 class LexicalCast; 0024 class AsciiSourceConfig; 0025 0026 0027 class AsciiDataReader 0028 { 0029 public: 0030 explicit AsciiDataReader(AsciiSourceConfig& config); 0031 ~AsciiDataReader(); 0032 0033 void clear(); 0034 void setRow0Begin(qint64 begin); 0035 inline qint64 beginOfRow(qint64 row) const { return _rowIndex[row]; } 0036 inline qint64 numberOfFrames() const { return _numFrames; } 0037 0038 // where 0039 const AsciiFileBuffer::RowIndex& rowIndex() const { return _rowIndex; } 0040 0041 void detectLineEndingType(QFile& file); 0042 0043 bool findAllDataRows(bool read_completely, QFile* file, qint64 _byteLength, int col_count); 0044 int readField(const AsciiFileData &buf, int col, double *v, const QString& field, int start, int n); 0045 int readFieldFromChunk(const AsciiFileData& chunk, int col, double *v, int start, const QString& field); 0046 0047 template<typename ColumnDelimiter> 0048 static int splitColumns(const QByteArray& line, const ColumnDelimiter& column_del, QStringList* cols = 0); 0049 0050 double progressValue(); 0051 qint64 progressRows(); 0052 0053 private: 0054 QMutex _progressMutex; 0055 double _progressValue; 0056 qint64 _progressRows; 0057 0058 qint64 _numFrames; 0059 qint64 _progressMax; 0060 qint64 _progressDone; 0061 AsciiFileBuffer::RowIndex _rowIndex; 0062 AsciiSourceConfig& _config; 0063 AsciiCharacterTraits::LineEndingType _lineending; 0064 0065 const AsciiCharacterTraits::IsDigit isDigit; 0066 const AsciiCharacterTraits::IsWhiteSpace isWhiteSpace; 0067 0068 template<class T> 0069 bool resizeBuffer(T& buffer, qint64 bytes); 0070 0071 template<class Buffer, typename ColumnDelimiter> 0072 int readColumns(double* v, const Buffer& buffer, qint64 bufstart, qint64 bufread, int col, int s, int n, 0073 const AsciiCharacterTraits::LineEndingType&, const ColumnDelimiter&) const; 0074 0075 template<class Buffer, typename ColumnDelimiter, typename CommentDelimiter> 0076 int readColumns(double* v, const Buffer& buffer, qint64 bufstart, qint64 bufread, int col, int s, int n, 0077 const AsciiCharacterTraits::LineEndingType&, const ColumnDelimiter&, const CommentDelimiter&) const; 0078 0079 template<class Buffer, typename IsLineBreak, typename ColumnDelimiter, typename CommentDelimiter, typename ColumnWidthsAreConst> 0080 int readColumns(double* v, const Buffer& buffer, qint64 bufstart, qint64 bufread, int col, int s, int n, 0081 const IsLineBreak&, const ColumnDelimiter&, const CommentDelimiter&, const ColumnWidthsAreConst&) const; 0082 0083 template<class Buffer, typename IsLineBreak, typename CommentDelimiter> 0084 bool findDataRows(const Buffer& buffer, qint64 bufstart, qint64 bufread, const IsLineBreak&, const CommentDelimiter&, int col_count); 0085 0086 void toDouble(const LexicalCast& lexc, const char* buffer, qint64 bufread, qint64 ch, double* v, int row) const; 0087 0088 mutable QMutex _localeMutex; 0089 }; 0090 0091 0092 template<> 0093 int AsciiDataReader::splitColumns<AsciiCharacterTraits::IsWhiteSpace>(const QByteArray& line, const AsciiCharacterTraits::IsWhiteSpace& column_del, QStringList* cols); 0094 0095 #endif 0096 // vim: ts=2 sw=2 et