-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTSVFileStream.h
More file actions
79 lines (65 loc) · 1.95 KB
/
TSVFileStream.h
File metadata and controls
79 lines (65 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef TSVFILESTREAM_H
#define TSVFILESTREAM_H
#include "cppCORE_global.h"
#include <QVector>
#include "VersatileFile.h"
/**
@brief TSV file parser as stream.
Assumes that single-quoted header is before the first content line.
*/
class CPPCORESHARED_EXPORT TSVFileStream
{
public:
///Constructor. Reads from stdin if @p filename is empty.
TSVFileStream(QString filename, char separator = '\t', char comment = '#');
///Destructor.
~TSVFileStream();
///Returns if the stream is at the end.
bool atEnd() const
{
return file_->atEnd() && next_line_.isNull();
}
///Returns the current line, split to columns. Note: Empty lines are returned as an empty array.
QByteArrayList readLine();
///Returns the split header line. If no header is present, a list with empty string is returned.
const QByteArrayList& header() const
{
return header_;
}
///Returns the header column index of the column 'name', or -1 when the column is missing.
int colIndex(QByteArray name, bool error_when_missing);
///Returns the comment lines.
const QByteArrayList& comments() const
{
return comments_;
}
///Returns the number of columns in the file.
int columns() const
{
return header_.count();
}
///Returns the 0-based index of the last read line.
int lineIndex() const
{
return line_;
}
//Resets to the state after the coinstructor (internal pointer on first line)
void reset();
///Checks and converts a comma-separated list of columns (names or 1-based indices) to 0-based numeric indices.
QVector<int> checkColumns(const QByteArrayList& col_names, bool numeric);
protected:
QString filename_;
char separator_;
char comment_;
QByteArray double_comment_;
QSharedPointer<VersatileFile> file_;
QByteArray next_line_;
QByteArrayList comments_;
QByteArrayList header_;
int line_;
//declared away methods
TSVFileStream(const TSVFileStream& ) = delete;
TSVFileStream& operator=(const TSVFileStream&) = delete;
TSVFileStream() = delete;
};
#endif